Пример #1
0
 protected override object BuildSettings(DeviceEntry entry)
 {
     MdsSettings settings = new MdsSettings();
     settings.Factor = (StringValue)entry["factor1"];
     settings.Frequence = (StringValue)entry[DeviceEntry.RecordInterval];
     return settings;
 }
Пример #2
0
		// Initialize the device
		private void Initialize(DeviceEntry entry)
		{
			this.Name = entry[DeviceEntry.Name].ToString();
			this.DeviceConfigPath = entry[DeviceEntry.Path].ToString();
			this.Version = entry[DeviceEntry.Version].ToString();
            this.Id = entry[DeviceEntry.Identity].ToString();

			string deviceSn = entry[DeviceEntry.DeviceSn].ToString();
			if (string.IsNullOrEmpty(deviceSn))
			{
				throw new Exception("Config Error: No Device SN");
			}
			this.deviceSn = deviceSn.Trim();

			this.addr = (StringValue)entry[DeviceEntry.IPAddress];

			this.minuteAdjust = (StringValue)entry["MinuteAdjust"];


            string tableName = (StringValue)entry[DeviceEntry.TableName];
            string tableFields = (StringValue)entry[DeviceEntry.TableFields];
            this.InitializeNaITable(tableName, tableFields, out this.insertIntoCommand);

            string tableName2 = (StringValue)entry["TableName2"];
            string tableFields2 = (StringValue)entry["TableFields2"];
            this.InitializeNaITable(tableName2, tableFields2, out this.insertIntoCommand2);


            // Virtual On
            string isVirtual = (StringValue)entry[DeviceEntry.Virtual];
            if (isVirtual != null && isVirtual.ToLower() == "true")
            {
                this.isVirtual = true;
            }
		}
Пример #3
0
        private static DeviceEntry LoadFromConfig(string deviceName, string configFile)
        {
            if (!File.Exists(configFile))
            {
                return(null);
            }

            using (ScadaReader sr = new ScadaReader(configFile))
            {
                SectionType    secType = SectionType.None;
                string         line    = null;
                string         key     = null;
                IValue         value   = null;
                ReadLineResult result  = sr.ReadLine(out secType, out line, out key, out value);
                // Dictionary<string, string> config = new Dictionary<string, string>();
                DeviceEntry entry = new DeviceEntry();
                while (result == ReadLineResult.OK)
                {
                    result = sr.ReadLine(out secType, out line, out key, out value);

                    if (secType == SectionType.KeyWithStringValue)
                    {
                        entry[key] = value;
                    }
                }
                DirectoryInfo di         = Directory.GetParent(configFile);
                string        devicePath = di.FullName;
                // Path
                entry[DeviceEntry.Path]     = new StringValue(devicePath);
                entry[DeviceEntry.Identity] = new StringValue(deviceName);


                return(entry);
            }
        }
Пример #4
0
 protected override object BuildSettings(DeviceEntry entry)
 {
     ShelterSettings settings = new ShelterSettings();
     settings.SerialPort = (StringValue)entry[DeviceEntry.SerialPort];
     settings.Frequence = (StringValue)entry[DeviceEntry.RecordInterval];
     return settings;
 }
Пример #5
0
        private void Initialize(DeviceEntry entry)
        {
            this.Name = entry[DeviceEntry.Name].ToString();
            this.Id = entry[DeviceEntry.Identity].ToString();
            this.DeviceConfigPath = entry[DeviceEntry.Path].ToString();
            this.Version = entry[DeviceEntry.Version].ToString();

            this.ipAddr = entry["IPADDR"].ToString();

            this.Flow = entry["Flow"].ToString();
            this.Hours = entry["Hours"].ToString();

            this.tableName = (StringValue)entry[DeviceEntry.TableName];
            if (!string.IsNullOrEmpty(tableName))
            {
                string tableFields = (StringValue)entry[DeviceEntry.TableFields];
                this.insertSQL = this.MakeInsertSQL(this.tableName, tableFields);
            }
            
            IValue v = entry["TSAP"];
            if (v != null)
            {
                this.tsap = v.ToString();
            }

        }
Пример #6
0
		public WeatherDevice(DeviceEntry entry)
		{
            this.entry = entry;
			if (!this.Initialize(entry))
			{
				string initFailedEvent = string.Format("Device '{0}' initialized failed. Error is {1}.", entry[DeviceEntry.Identity], error);
				RecordManager.DoSystemEventRecord(this, initFailedEvent);
			}
		}
Пример #7
0
 protected override object BuildSettings(DeviceEntry entry)
 {
     NaISettings settings = new NaISettings();
     settings.DeviceSn = (StringValue)entry[DeviceEntry.DeviceSn];
     settings.Frequence = (StringValue)entry[DeviceEntry.RecordInterval];
     settings.MinuteAdjust = (StringValue)entry["MinuteAdjust"];
     settings.IPAddress = (StringValue)entry[DeviceEntry.IPAddress];
     return settings;
 }
Пример #8
0
 protected override object BuildSettings(DeviceEntry entry)
 {
     HpicSettings settings = new HpicSettings();
     settings.SerialPort = (StringValue)entry[DeviceEntry.SerialPort];
     settings.Frequence = (StringValue)entry[DeviceEntry.RecordInterval];
     settings.Factor = (StringValue)entry["factor1"];
     settings.AlarmValue = (StringValue)entry[DeviceEntry.Alarm1];
     return settings;
 }
Пример #9
0
        private void btnConnAIS_Click(object sender, EventArgs e)
        {
            DeviceEntry entry = new DeviceEntry();
            entry[DeviceEntry.Name] = new StringValue("AIS");
            entry[DeviceEntry.Identity] = new StringValue("Scada.AIS");
            entry[DeviceEntry.Path] = new StringValue("");
            entry[DeviceEntry.Version] = new StringValue("0.9");

            entry["IPADDR"] = new StringValue("192.168.0.6");
            this.aisDevice = new AISDevice(entry);
            this.aisDevice.Start("S7200.OPCServer");

            this.aisDevice.Send(Encoding.ASCII.GetBytes("connect"), default(DateTime));
        }
Пример #10
0
        // Initialize the device
        private void Initialize(DeviceEntry entry)
        {
            this.Name = entry[DeviceEntry.Name].ToString();
            this.DeviceConfigPath = entry[DeviceEntry.Path].ToString();
            this.Version = entry[DeviceEntry.Version].ToString();
            this.Id = entry[DeviceEntry.Identity].ToString();

            this.strFileMonitoringPath = (StringValue)entry["FileMonitoringPath"];
            this.strFileCopy2Path = (StringValue)entry["FileCopy2Path"];
            this.strSidPath = (StringValue)entry["SIDPath"];
            this.strActionInterval = (StringValue)entry[DeviceEntry.ActionInterval];

            string tableName = (StringValue)entry[DeviceEntry.TableName];
            string tableFields = (StringValue)entry[DeviceEntry.TableFields];
            this.InitializeHPGeTable(tableName, tableFields, out this.insertIntoCommand);
        }
Пример #11
0
 protected virtual object BuildSettings(DeviceEntry entry)
 {
     return null;
 }
Пример #12
0
 public HPGEFileDevice(DeviceEntry entry)
 {
     this.entry = entry;
     this.Initialize(entry);
 }
Пример #13
0
        private Device Load(DeviceEntry entry)
        {
            if (entry == null)
                return null;

            StringValue className = (StringValue)entry[DeviceEntry.ClassName];
            if (typeof(StandardDevice).ToString() == className)
            {
                return new StandardDevice(entry);
            }
            else if (typeof(WebFileDevice).ToString() == className)
            {
                return new WebFileDevice(entry);
            }
            else if (typeof(FormProxyDevice).ToString() == className)
            {
                return new FormProxyDevice(entry);
            }

            // Other Device defined in some Assemblies.
            if (entry[DeviceEntry.Assembly] != null)
            {
                Assembly assembly = Assembly.Load((StringValue)entry[DeviceEntry.Assembly]);
                Type deviceClass = assembly.GetType((StringValue)entry[DeviceEntry.ClassName]);
                if (deviceClass != null)
                {
                    object device = Activator.CreateInstance(deviceClass, new object[] { });
                    return device as Device;
                }
            }

            return (Device)null;
        }
Пример #14
0
 private string GetCOMPort(DeviceEntry entry)
 {
     if (entry.Contains(DeviceEntry.SerialPort))
     {
         return (StringValue)entry[DeviceEntry.SerialPort];
     }
     return string.Empty;
 }
Пример #15
0
		private bool Initialize(DeviceEntry entry)
		{
            this.Name = entry[DeviceEntry.Name].ToString();
            this.Id = entry[DeviceEntry.Identity].ToString();
            this.DeviceConfigPath = entry[DeviceEntry.Path].ToString();
            this.Version = entry[DeviceEntry.Version].ToString();

            this.processName = (StringValue)entry[ProcessName];

            for (int i = 1; i < 50; i++)
            {
                string elemId = string.Format("ElemId{0}", i);
                if (!entry.Contains(elemId))
                {
                    break;
                }
                string controlIdStr = (StringValue)entry[elemId];
                int controlId = 0;
                if (controlIdStr.StartsWith("0x"))
                {
                    controlIdStr = controlIdStr.Substring(2);
                    controlId = int.Parse(controlIdStr, NumberStyles.AllowHexSpecifier);
                    this.elemIdList.Add(controlId);
                }
                else
                {
                    if (int.TryParse(controlIdStr, out controlId))
                    {
                        this.elemIdList.Add(controlId);
                    }
                }
            }

            string tableName = (StringValue)entry[DeviceEntry.TableName];
            string tableFields = (StringValue)entry[DeviceEntry.TableFields];


            if (!Device.GetFactor(entry, 1, out this.factor1))
            {
                // Debug.Assert(false);
            }

            string[] fields = tableFields.Split(',');
            string atList = string.Empty;
            for (int i = 0; i < fields.Length; ++i)
            {
                string at = string.Format("@{0}, ", i + 1);
                atList += at;
            }
            atList = atList.TrimEnd(',', ' ');

            this.tableName = tableName;
            string cmd = string.Format("insert into {0}({1}) values({2})", tableName, tableFields, atList);
            this.insertIntoCommand = cmd;


            string fieldsConfigStr = (StringValue)entry[DeviceEntry.FieldsConfig];
            List<FieldConfig> fieldConfigList = ParseDataFieldConfig(fieldsConfigStr);
            this.fieldsConfig = fieldConfigList.ToArray<FieldConfig>();

            this.GenCurrentSid();
			return true;
		}
Пример #16
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="entry"></param>
 public ShelterDevice(DeviceEntry entry)
     :base(entry)
 {
 }
Пример #17
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="entry"></param>
 public CinderlDataDevice(DeviceEntry entry)
     :base(entry)
 {
 }
Пример #18
0
 protected void SetDataParserFactors(DataParser dataParser, DeviceEntry entry)
 {
     int i = 0;
     double v = 0.0;
     while (Device.GetFactor(entry, ++i, out v))
     {
         dataParser.Factors.Add(v);
     }
 }
Пример #19
0
 protected string GetValue(DeviceEntry entry, string entryName, string defaultValue)
 {
     IValue v = entry[entryName];
     if (v != null)
     {
         return (StringValue)v;
     }
     return defaultValue;
 }
Пример #20
0
 public static bool GetFactor(DeviceEntry entry, int i, out double v)
 {
     v = 0.0;
     string factor = string.Format("factor{0}", i);
     string s = (StringValue)entry[factor];
     if (s != null && s.Length > 0)
     {
         if (double.TryParse(s, out v))
         {
             return true;
         }
     }
     return false;
 }
Пример #21
0
        private bool Initialize(DeviceEntry entry)
        {
            this.Name = entry[DeviceEntry.Name].ToString();
            this.Id = entry[DeviceEntry.Identity].ToString();
            this.Path = entry[DeviceEntry.Path].ToString();
            this.Version = entry[DeviceEntry.Version].ToString();

            this.baudRate = this.GetValue(entry, DeviceEntry.BaudRate, 9600);
            this.readTimeout = this.GetValue(entry, DeviceEntry.ReadTimeout, 12000);
            this.dataBits = this.GetValue(entry, DeviceEntry.DataBits, ComDataBits);
            this.stopBits = (StopBits)this.GetValue(entry, DeviceEntry.StopBits, (int)StopBits.One);

            StringValue parity = (StringValue)entry[DeviceEntry.Parity];
            this.parity = SerialPorts.ParseParity(parity);

            // Virtual On
            string isVirtual = (StringValue)entry[DeviceEntry.Virtual];
            if (isVirtual != null && isVirtual.ToLower() == "true")
            {
                this.isVirtual = true;
            }

            this.actionCondition = (StringValue)entry[DeviceEntry.ActionCondition];
            string actionSendInHex = (StringValue)entry[DeviceEntry.ActionSendInHex];
            if (actionSendInHex != "true")
            {
                string actionSend = (StringValue)entry[DeviceEntry.ActionSend];
                if (actionSend != null)
                {
                    actionSend = actionSend.Replace("\\r", "\r");
                    this.actionSend = Encoding.ASCII.GetBytes(actionSend);
                }
            }
            else
            {
                this.actionSendInHex = true;
                string hexes = (StringValue)entry[DeviceEntry.ActionSend];
                hexes = hexes.Trim();
                this.actionSend = DeviceEntry.ParseHex(hexes);
            }

            this.actionDelay = (StringValue)entry[DeviceEntry.ActionDelay];

            const int DefaultRecordInterval = 30;
            this.actionInterval = this.GetValue(entry, DeviceEntry.ActionInterval, DefaultRecordInterval);
            this.RecordInterval = this.GetValue(entry, DeviceEntry.RecordInterval, DefaultRecordInterval);
            this.recordTimePolicy.Interval = this.RecordInterval;

            var sensitive = this.GetValue(entry, DeviceEntry.Sensitive, "false");
            this.sensitive = (sensitive.ToLower() == "true");

            this.calcDataWithLastData = this.GetValue(entry, "CalcLast", 0) == 1;

            // Set DataParser & factors
            string dataParserClz = (StringValue)entry[DeviceEntry.DataParser];
            this.dataParser = this.GetDataParser(dataParserClz);
            this.SetDataParserFactors(this.dataParser, entry);

            string tableName = (StringValue)entry[DeviceEntry.TableName];
            string tableFields = (StringValue)entry[DeviceEntry.TableFields];

            string[] fields = tableFields.Split(',');
            string atList = string.Empty;
            for (int i = 0; i < fields.Length; ++i)
            {
                string at = string.Format("@{0}, ", i + 1);
                atList += at;
            }
            atList = atList.TrimEnd(',', ' ');

            string cmd = string.Format("insert into {0}({1}) values({2})", tableName, tableFields, atList);
            this.insertIntoCommand = cmd;

            string fieldsConfigStr = (StringValue)entry[DeviceEntry.FieldsConfig];
            List<FieldConfig> fieldConfigList = ParseDataFieldConfig(fieldsConfigStr);
            this.fieldsConfig = fieldConfigList.ToArray<FieldConfig>();

            if (!this.IsRealDevice)
            {
                string el = (StringValue)entry[DeviceEntry.ExampleLine];
                el = el.Replace("\\r", "\r");
                el = el.Replace("\\n", "\n");

                this.exampleLine = el;
            }
            return true;
        }
Пример #22
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="entry"></param>
        public CinderlStatusDevice(DeviceEntry entry)
            :base(entry)
        {

        }
Пример #23
0
 public MDSDevice(DeviceEntry entry)
     :base(entry)
 {
     this.deviceKey = "scada.mds";
 }
Пример #24
0
        private static DeviceEntry LoadFromConfig(string deviceName, string configFile)
        {
            if (!File.Exists(configFile))
                return null;

            using (ScadaReader sr = new ScadaReader(configFile))
            {
                SectionType secType = SectionType.None;
                string line = null;
                string key = null;
                IValue value = null;
                ReadLineResult result = sr.ReadLine(out secType, out line, out key, out value);
                // Dictionary<string, string> config = new Dictionary<string, string>();
                DeviceEntry entry = new DeviceEntry();
                while (result == ReadLineResult.OK)
                {
                    result = sr.ReadLine(out secType, out line, out key, out value);

                    if (secType == SectionType.KeyWithStringValue)
                    {
                        entry[key] = value;
                    }
                }
                DirectoryInfo di = Directory.GetParent(configFile);
                string devicePath = di.FullName;
                // Path
                entry[DeviceEntry.Path] = new StringValue(devicePath);
                entry[DeviceEntry.Identity] = new StringValue(deviceName);

                return entry;
            }
        }
Пример #25
0
 public OpcDevice(DeviceEntry entry)
 {
     this.Initialize(entry);
 }
Пример #26
0
		private bool Initialize(DeviceEntry entry)
		{
			this.Name = entry[DeviceEntry.Name].ToString();
            this.Id = entry[DeviceEntry.Identity].ToString();
            this.DeviceConfigPath = entry[DeviceEntry.Path].ToString();
			this.Version = entry[DeviceEntry.Version].ToString();

            this.baudRate = this.GetValue(entry, DeviceEntry.BaudRate, 9600);
            this.readTimeout = this.GetValue(entry, DeviceEntry.ReadTimeout, 12000);        
            this.dataBits = this.GetValue(entry, DeviceEntry.DataBits, ComDataBits);
            this.stopBits = (StopBits)this.GetValue(entry, DeviceEntry.StopBits, (int)StopBits.One);

			StringValue parity = (StringValue)entry[DeviceEntry.Parity];
			this.parity = SerialPorts.ParseParity(parity);

            // 
            this.actionSend1 = Encoding.ASCII.GetBytes((StringValue)entry["ActionSend1"]);
            this.actionSend2 = Encoding.ASCII.GetBytes((StringValue)entry["ActionSend2"]);
			
			// Virtual On
			string isVirtual = (StringValue)entry[DeviceEntry.Virtual];
			if (isVirtual != null && isVirtual.ToLower() == "true")
			{
				this.isVirtual = true;
			}

            string bufferSleepString = (StringValue)entry["BufferSleep"];
            if (bufferSleepString != null)
            {
                this.bufferSleep = int.Parse(bufferSleepString);
            }

			// this.actionDelay = (StringValue)entry[DeviceEntry.ActionDelay];

            const int DefaultRecordInterval = 30;
            this.actionInterval = this.GetValue(entry, DeviceEntry.ActionInterval, DefaultRecordInterval);
            this.RecordInterval = this.GetValue(entry, DeviceEntry.RecordInterval, DefaultRecordInterval);
            this.recordTimePolicy.Interval = this.RecordInterval;

            string tableName = (StringValue)entry[DeviceEntry.TableName];
            if (!string.IsNullOrEmpty(tableName))
            {
                string tableFields = (StringValue)entry[DeviceEntry.TableFields];

                string[] fields = tableFields.Split(',');
                string atList = string.Empty;
                for (int i = 0; i < fields.Length; ++i)
                {
                    string at = string.Format("@{0}, ", i + 1);
                    atList += at;
                }
                atList = atList.TrimEnd(',', ' ');

                // Insert into
                string cmd = string.Format("insert into {0}({1}) values({2})", tableName, tableFields, atList);
                this.insertIntoCommand = cmd;
            }

			string fieldsConfigStr = (StringValue)entry[DeviceEntry.FieldsConfig];
            List<FieldConfig> fieldConfigList = ParseDataFieldConfig(fieldsConfigStr);
			this.fieldsConfig = fieldConfigList.ToArray<FieldConfig>();

			if (!this.IsRealDevice)
			{
				string el = (StringValue)entry[DeviceEntry.ExampleLine];
				el = el.Replace("\\r", "\r");
				el = el.Replace("\\n", "\n");

				this.exampleLine = el;
			}
			return true;
		}
Пример #27
0
		public FormProxyDevice(DeviceEntry entry)
		{

			this.Initialize(entry);
		}
Пример #28
0
 public AISDevice(DeviceEntry entry)
     : base(entry)
 {
     this.deviceKey = "scada.ais";
 }
Пример #29
0
        private void CheckVirtualDevice(DeviceEntry entry, string configFile)
        {
            DirectoryInfo di = Directory.GetParent(configFile);
            string virtualDeviceFlagFile = string.Format("{0}\\virtual-device", di.FullName);
            if (!File.Exists(virtualDeviceFlagFile))
            {
                return;
            }

            string deviceDisplayName = (StringValue)entry[DeviceEntry.Name];
            string caption = "连接虚拟设备提示";
            string message = string.Format("是否要连接 '{0}' 的虚拟设备,连接虚拟设备点击‘是’,\n连接真实设备点击‘否’", deviceDisplayName);
            DialogResult dr = MessageBox.Show(message, caption, MessageBoxButtons.YesNo);
            if (dr == DialogResult.Yes)
            {
                entry[DeviceEntry.Virtual] = new StringValue("true");
            }
            else
            {
                entry[DeviceEntry.Virtual] = new StringValue("false");

                string deleteVirtualFileMsg = string.Format("是否要删除 '{0}' 的虚拟设备标志文件?", deviceDisplayName);
                DialogResult del = MessageBox.Show(deleteVirtualFileMsg, caption, MessageBoxButtons.YesNo);
                if (del == DialogResult.Yes)
                {
                    File.Delete(virtualDeviceFlagFile);
                }
            }
        }
Пример #30
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="deviceName"></param>
 /// <param name="configFile"></param>
 /// <returns></returns>
 public static DeviceEntry GetDeviceEntry(string deviceName, string configFile)
 {
     return(DeviceEntry.LoadFromConfig(deviceName, configFile));
 }
Пример #31
0
        private Device Load(DeviceEntry entry)
        {
			if (entry == null)
				return null;


            //实例化设备
            StringValue className = (StringValue)entry[DeviceEntry.ClassName];
            if (typeof(StandardDevice).ToString() == className)
            {
                return new StandardDevice(entry);
            }
			else if (typeof(WebFileDevice).ToString() == className)
			{
				return new WebFileDevice(entry);
			}
            else if (typeof(FormProxyDevice).ToString() == className)
            {
                return new FormProxyDevice(entry);
            }
            else if (typeof(CinderlDataDevice).ToString() == className)
            {
                return new CinderlDataDevice(entry);
            }
            else if (typeof(CinderlStatusDevice).ToString() == className)
            {
                return new CinderlStatusDevice(entry);
            }
            else if (typeof(ShelterDevice).ToString() == className)
            {
                return new ShelterDevice(entry);
            }
            else if (typeof(HPGEFileDevice).ToString() == className)
            {
                return new HPGEFileDevice(entry);
            }
            else if (typeof(WeatherDevice).ToString() == className)
            {
                return new WeatherDevice(entry);
            }

			// Other Device defined in some Assemblies.
            if (entry[DeviceEntry.Assembly] != null)
            {
                string assemblyName = (StringValue)entry[DeviceEntry.Assembly];
                string assemblyFile = LogPath.GetExeFilePath(assemblyName);
                Assembly assembly = Assembly.LoadFile(assemblyFile);
                Type deviceClass = assembly.GetType((StringValue)entry[DeviceEntry.ClassName]);
                if (deviceClass != null)
                {
                    object device = Activator.CreateInstance(deviceClass, new object[] { entry });
                    return device as Device;
                }
            }
            MessageBox.Show("Create Device Failed");
            return (Device)null;
        }