Esempio n. 1
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;
        }
Esempio n. 2
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);
     }
 }
Esempio n. 3
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);


            // 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.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];
                if (!string.IsNullOrEmpty(hexes))
                {
                    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;

            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];

            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);
        }