Beispiel #1
0
        private void DisplayTagList(cls_Device_Info device)
        {
            lvTagList.BeginUpdate();
            lvTagList.Items.Clear();
            foreach (KeyValuePair <string, cls_Tag> tag in device.tag_info)
            {
                ListViewItem item = new ListViewItem(tag.Value.TagName);
                item.SubItems.Add(tag.Value.Expression);
                item.SubItems.Add(tag.Value.UUID_Address);
                item.SubItems.Add(tag.Value.scale.ToString());
                item.SubItems.Add(tag.Value.offset.ToString());
                item.SubItems.Add(tag.Value.LastUpdateTime);
                if (tag.Value.report_flag == "Y")
                {
                    item.Checked = true;
                }
                else
                {
                    item.Checked = false;
                }

                lvTagList.Items.Add(item);
            }
            lvTagList.EndUpdate();
        }
 public ProcCollectData(cls_Device_Info Device, string GatewayID, string DeviceID, Put_ProcRecv_CollectData_Event _delegate_Method)
 {
     _GatewayID = GatewayID;
     _DeviceID  = DeviceID;
     _Device    = Device;
     this.Put_ProcRecv_CollectData = _delegate_Method;
 }
Beispiel #3
0
        private void cmbDevice_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmbDevice.Text.Trim() == "")
            {
                MessageBox.Show("Please select device id", "Error");
                return;
            }

            cls_Gateway_Info gi = this.gateway_mgr.gateway_list.Where(p => p.gateway_id == cmbGateway.Text.Trim()).FirstOrDefault();

            if (gi != null)
            {
                cls_Device_Info di = gi.device_info.Where(p => p.device_name == cmbDevice.Text.Trim()).FirstOrDefault();
                if (di != null)
                {
                    DisplayTagList(di);
                    DisplayCalcTagList(di);
                    device_index = gi.device_info.FindIndex(p => p.device_name == cmbDevice.Text.Trim());
                }
                else
                {
                    MessageBox.Show("Find device information failed", "Error");
                    return;
                }
            }
            else
            {
                MessageBox.Show("Find gateway information failed", "Error");
                return;
            }
        }
        public void ReceiveReplyData(xmlMessage InputData)
        {
            // Parse Mqtt Topic
            string[] Topic     = InputData.MQTTTopic.Split('/'); // /IEW/GateWay/Device/ReplyData
            string   GateWayID = Topic[2].ToString();
            string   DeviceID  = Topic[3].ToString();

            if (ObjectManager.GatewayManager != null)
            {
                cls_Gateway_Info Gateway = ObjectManager.GatewayManager.gateway_list.Where(p => p.gateway_id == GateWayID).FirstOrDefault();
                if (Gateway != null)
                {
                    cls_Device_Info Device = Gateway.device_info.Where(p => p.device_name == DeviceID).FirstOrDefault();
                    if (Device != null)
                    {
                        try
                        {
                            SetOnlineMonitorEDCReportStatus(GateWayID, DeviceID, InputData.MQTTPayload.ToString());

                            //Raise event to notify Online Monitor form to refresh status
                            this.ObjectManager.OnEDCReportEventCall(null);
                        }
                        catch (Exception ex)
                        {
                            NLogManager.Logger.LogError(LogName, GetType().Name, MethodInfo.GetCurrentMethod().Name + "()", ex);
                        }
                    }
                }
            }
        }
        public void SendCmdConfig(string GateWayID, string DeviceID)
        {
            cls_Gateway_Info tmp_gw_info = new cls_Gateway_Info();
            cls_Gateway_Info gw_info     = ObjectManager.GatewayManager.gateway_list.Where(p => p.gateway_id == GateWayID).FirstOrDefault();

            if (gw_info == null)
            {
                MessageBox.Show("Can't find [" + GateWayID + "][" + DeviceID + "] Config to send to IoTClient", "Error");
                return;
            }

            tmp_gw_info.gateway_id            = gw_info.gateway_id;
            tmp_gw_info.gateway_ip            = gw_info.gateway_ip;
            tmp_gw_info.location              = gw_info.location;
            tmp_gw_info.virtual_flag          = gw_info.virtual_flag;
            tmp_gw_info.virtual_publish_topic = gw_info.virtual_publish_topic;
            tmp_gw_info.function_list         = gw_info.function_list;
            cls_Device_Info dv_info = gw_info.device_info.Where(o => o.device_name == DeviceID).FirstOrDefault();

            tmp_gw_info.device_info.Add(dv_info);

            string json_msg = JsonConvert.SerializeObject(tmp_gw_info, Newtonsoft.Json.Formatting.Indented);

            xmlMessage SendOutMsg = new xmlMessage();

            SendOutMsg.LineID      = GateWayID;
            SendOutMsg.DeviceID    = DeviceID;
            SendOutMsg.MQTTTopic   = "Cmd_Config";
            SendOutMsg.MQTTPayload = json_msg;
            SendMQTTData(SendOutMsg);
        }
        public void Organize_DBPartaker(string GateWayID, string Device_ID)
        {
            //--- Check DB List information
            if (_objectmanager.DBManager == null)
            {
                return;
            }

            List <ObjectManager.cls_DB_Info> lst_DBInfo = _objectmanager.DBManager.dbconfig_list.Where(p => p.gateway_id == GateWayID && p.device_id == Device_ID && p.enable == true).ToList();

            foreach (cls_DB_Info _DB in lst_DBInfo)
            {
                DBPartaker       DBReporter = new DBPartaker(_DB);
                cls_Gateway_Info gateway    = _objectmanager.GatewayManager.gateway_list.Where(p => p.gateway_id == GateWayID).FirstOrDefault();
                if (gateway != null)
                {
                    cls_Device_Info device = gateway.device_info.Where(p => p.device_name == Device_ID).FirstOrDefault();
                    if (device != null)
                    {
                        // Assembly Normal Tag info
                        foreach (Tuple <string, string> _Items in _DB.tag_info)
                        {
                            string ReportItemName  = _Items.Item1;
                            string ReportItemValue = string.Empty;
                            if (device.tag_info.ContainsKey(_Items.Item2))
                            {
                                ReportItemValue = device.tag_info[_Items.Item2].Value;
                                DBReporter.Report_Item.Add(Tuple.Create(ReportItemName, ReportItemValue, device.tag_info[_Items.Item2].Expression));
                            }
                        }

                        // Assembly Calc Tag info
                        foreach (Tuple <string, string> _Items in _DB.calc_tag_info)
                        {
                            string ReportItemName  = _Items.Item1;
                            string ReportItemValue = string.Empty;
                            if (device.tag_info.ContainsKey(_Items.Item2))
                            {
                                ReportItemValue = device.tag_info[_Items.Item2].Value;
                                DBReporter.Report_Item.Add(Tuple.Create(ReportItemName, ReportItemValue, device.tag_info[_Items.Item2].Expression));
                            }
                        }
                    }
                }

                //----- Send MQTT-----
                xmlMessage SendOutMsg = new xmlMessage();
                SendOutMsg.GatewayID   = GateWayID; // GateID
                SendOutMsg.DeviceID    = Device_ID; // DeviceID
                SendOutMsg.MQTTTopic   = "DBService";
                SendOutMsg.MQTTPayload = JsonConvert.SerializeObject(DBReporter, Newtonsoft.Json.Formatting.Indented);
                _QueueManager.PutMessage(SendOutMsg);
            }
        }
Beispiel #7
0
        private void lvGWDevice_DoubleClick(object sender, EventArgs e)
        {
            string strDeviceID;

            if (lvGWDevice.SelectedItems.Count == 0)
            {
                MessageBox.Show("Please select the device first!", "Error");
                return;
            }

            strDeviceID = lvGWDevice.SelectedItems[0].Text.Trim();

            int i = 0;

            cls_Device_Info deviceTemp = this.gateway_Info.device_info.Where(o => o.device_name == strDeviceID).FirstOrDefault();

            if (deviceTemp == null)
            {
                return;
            }

            i = this.gateway_Info.device_info.FindIndex(p => p.device_name == deviceTemp.device_name);

            /*
             * foreach (cls_Device_Info di in this.gateway_Info.device_info)
             * {
             *  if (di.device_name == strDeviceID)
             *  {
             *      deviceTemp = this.gateway_Info.device_info[i];
             *      break;
             *  }
             *  i++;
             * }
             */

            if (this.isCopy)
            {
                deviceTemp.device_name = "";
            }

            var frm = new frmEditDevice(deviceTemp, i);

            frm.Owner = this;
            frm.ShowDialog();

            DisplayDeviceList();
            lvGWDevice.Focus();
        }
Beispiel #8
0
        public void ThreadPool_Proc(string msg)
        {
            try
            {
                JObject jsonObj = JObject.Parse(msg.ToString());
                Dictionary <string, object> dictObj = jsonObj.ToObject <Dictionary <string, object> >();

                if (dictObj.ContainsKey("MCUName") == false)
                {
                    return;
                }
                else
                {
                    cls_ProcRecv_CollectData ProcRecv_CollectData = new cls_ProcRecv_CollectData();
                    ProcRecv_CollectData.GateWayID = _Gateway.gateway_id;

                    cls_Device_Info Device = _Gateway.device_info.Where(p => p.device_name == dictObj["MCUName"].ToString()).FirstOrDefault();
                    if (Device == null)
                    {
                        return;
                    }
                    else
                    {
                        ProcRecv_CollectData.Device_ID = Device.device_name;

                        foreach (KeyValuePair <string, cls_Tag> kvp in Device.tag_info)
                        {
                            if (dictObj.ContainsKey(kvp.Value.TagName) == false)
                            {
                                continue;
                            }
                            else
                            {
                                kvp.Value.Value = dictObj[kvp.Value.TagName].ToString();
                                ProcRecv_CollectData.Prod_EDC_Data.Enqueue(Tuple.Create(kvp.Key, kvp.Value.Value));
                            }
                        }

                        this.Put_ProcRecv_CollectData(ProcRecv_CollectData);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Handle IR Sensor Data Error Message Error [{0}].", ex.Message));
            }
        }
        public void ReceiveMQTTData(xmlMessage InputData)
        {
            // Chris Modify 20191023 直接在外面判斷是否為virtual type
            // Parse Mqtt Topic

            string[] Topic     = InputData.MQTTTopic.Split('/'); // /IEW/GateWay/Device/ReplyData
            string   GateWayID = Topic[2].ToString();
            string   DeviceID  = Topic[3].ToString();

            NLogManager.Logger.LogInfo(LogName, GetType().Name, MethodInfo.GetCurrentMethod().Name + "()", string.Format("GateWay Service Handle Receive Data GateWayID = {0}, DeviceID = {1}, Topic = {2}.", GateWayID, DeviceID, InputData.MQTTTopic));
            NLogManager.Logger.LogDebug(LogName, GetType().Name, MethodInfo.GetCurrentMethod().Name + "()", string.Format("GateWay Service Handle Receive Data  Topic = {0}, Payload = {1}.", InputData.MQTTTopic, InputData.MQTTPayload));

            if (ObjectManager.GatewayManager != null)
            {
                cls_Gateway_Info Gateway = ObjectManager.GatewayManager.gateway_list.Where(p => p.gateway_id == GateWayID).FirstOrDefault();
                if (Gateway != null)
                {
                    cls_Device_Info Device = Gateway.device_info.Where(p => p.device_name == DeviceID).FirstOrDefault();
                    if (Device != null)
                    {
                        try
                        {
                            ProcCollectData Function = new ProcCollectData(Device, GateWayID, DeviceID, _Update_ProcRecv_CollectData_Enqueue);

                            if (Gateway.virtual_flag == false)
                            {
                                ThreadPool.QueueUserWorkItem(o => Function.ThreadPool_Proc_Physical(InputData.MQTTPayload.ToString()));
                            }
                            else
                            {
                                ThreadPool.QueueUserWorkItem(o => Function.ThreadPool_Proc_Virtual(InputData.MQTTPayload.ToString()));
                            }


                            SetOnlineMonitorEDCReportStatus(GateWayID, DeviceID, InputData.MQTTPayload.ToString());
                            //Raise event to notify Online Monitor form to refresh status
                            this.ObjectManager.OnEDCReportEventCall(null);
                        }
                        catch (Exception ex)
                        {
                            NLogManager.Logger.LogError(LogName, GetType().Name, MethodInfo.GetCurrentMethod().Name + "()", "Gateway Services Handle Receive MQTT Message Error :" + ex.Message);
                        }
                    }
                }
            }
        }
Beispiel #10
0
 // Constructor called by frmEditGateway after double clicked device list
 public frmEditDevice(cls_Device_Info device, int index)
 {
     InitializeComponent();
     this.isEdit            = true;
     this.isEmbedded        = false;
     this.device_data       = device;
     this.iDeviceIndex      = index;
     this.taglist_data      = device.tag_info;
     this.calc_taglist_data = device.calc_tag_info;
     if (this.device_data.device_name == "")
     {
         this.isCopy = true;
     }
     else
     {
         this.isCopy = false;
     }
 }
        // Chris Modify 20191023 直接在外面判斷是否為virtual type
        public void ReceiveMQTTData(xmlMessage InputData)
        {
            if (GateWayStatus != "Run" && GateWayStatus != "Ready")
            {
                return;
            }
            // Parse Mqtt Topic
            string[] Topic     = InputData.MQTTTopic.Split('/'); // /IEW/GateWay/Device/ReplyData
            string   GateWayID = Topic[2].ToString();
            string   DeviceID  = Topic[3].ToString();

            _logger.LogInformation(string.Format("GateWay Service Handle Receive Data GateWayID = {0}, DeviceID = {1}, Topic = {2}.", GateWayID, DeviceID, InputData.MQTTTopic));
            _logger.LogDebug(string.Format("GateWay Service Handle Receive Data  Topic = {0}, Payload = {1}.", InputData.MQTTTopic, InputData.MQTTPayload));

            if (_objectmanager.GatewayManager != null)
            {
                cls_Gateway_Info Gateway = _objectmanager.GatewayManager.gateway_list.Where(p => p.gateway_id == GateWayID).FirstOrDefault();
                if (Gateway != null)
                {
                    cls_Device_Info Device = Gateway.device_info.Where(p => p.device_name == DeviceID).FirstOrDefault();
                    if (Device != null)
                    {
                        try
                        {
                            ProcCollectData Function = new ProcCollectData(Device, GateWayID, DeviceID, _Update_ProcRecv_CollectData_Enqueue);

                            if (Gateway.virtual_flag == false)
                            {
                                ThreadPool.QueueUserWorkItem(o => Function.ThreadPool_Proc_Physical(InputData.MQTTPayload.ToString()));
                            }
                            else
                            {
                                ThreadPool.QueueUserWorkItem(o => Function.ThreadPool_Proc_Virtual(InputData.MQTTPayload.ToString()));
                            }
                        }
                        catch (Exception ex)
                        {
                            _logger.LogError("Gateway Services Handle Receive MQTT Message Error :" + ex.Message);
                        }
                    }
                }
            }
        }
Beispiel #12
0
 private void DisplayCalcTagList(cls_Device_Info device)
 {
     lvCalcTagList.BeginUpdate();
     lvCalcTagList.Items.Clear();
     foreach (KeyValuePair <string, cls_CalcTag> calc_tag in device.calc_tag_info)
     {
         ListViewItem item = new ListViewItem(calc_tag.Value.TagName);
         item.SubItems.Add(calc_tag.Value.ParamA);
         item.SubItems.Add(calc_tag.Value.ParamB);
         item.SubItems.Add(calc_tag.Value.ParamC);
         item.SubItems.Add(calc_tag.Value.ParamD);
         item.SubItems.Add(calc_tag.Value.ParamE);
         item.SubItems.Add(calc_tag.Value.ParamF);
         item.SubItems.Add(calc_tag.Value.ParamG);
         item.SubItems.Add(calc_tag.Value.ParamH);
         item.SubItems.Add(calc_tag.Value.Expression);
         lvCalcTagList.Items.Add(item);
     }
     lvCalcTagList.EndUpdate();
 }
        public void ProcCalcTag(string GateWayID, string Device_ID)
        {
            cls_Gateway_Info gateway = _objectmanager.GatewayManager.gateway_list.Where(p => p.gateway_id == GateWayID).FirstOrDefault();

            if (gateway != null)
            {
                cls_Device_Info device = gateway.device_info.Where(p => p.device_name == Device_ID).FirstOrDefault();
                if (device != null)
                {
                    foreach (KeyValuePair <string, cls_CalcTag> kvp in device.calc_tag_info)
                    {
                        cls_Tag tagA = null;
                        cls_Tag tagB = null;
                        cls_Tag tagC = null;
                        cls_Tag tagD = null;
                        cls_Tag tagE = null;
                        cls_Tag tagF = null;
                        cls_Tag tagG = null;
                        cls_Tag tagH = null;

                        Double douA      = -1;
                        Double douB      = -1;
                        Double douC      = -1;
                        Double douD      = -1;
                        Double douE      = -1;
                        Double douF      = -1;
                        Double douG      = -1;
                        Double douH      = -1;
                        Double douResult = -999999.999;

                        if (kvp.Value.ParamA.Trim() != "")
                        {
                            // for vic verify dictionary key exist or not.
                            if (device.tag_info.ContainsKey(kvp.Value.ParamA))
                            {
                                tagA = device.tag_info[kvp.Value.ParamA];
                            }
                        }

                        if (kvp.Value.ParamB.Trim() != "")
                        {
                            tagB = device.tag_info[kvp.Value.ParamB];
                        }

                        if (kvp.Value.ParamC.Trim() != "")
                        {
                            tagC = device.tag_info[kvp.Value.ParamC];
                        }

                        if (kvp.Value.ParamD.Trim() != "")
                        {
                            tagD = device.tag_info[kvp.Value.ParamD];
                        }

                        if (kvp.Value.ParamE.Trim() != "")
                        {
                            tagE = device.tag_info[kvp.Value.ParamE];
                        }

                        if (kvp.Value.ParamF.Trim() != "")
                        {
                            tagF = device.tag_info[kvp.Value.ParamF];
                        }

                        if (kvp.Value.ParamG.Trim() != "")
                        {
                            tagG = device.tag_info[kvp.Value.ParamG];
                        }

                        if (kvp.Value.ParamH.Trim() != "")
                        {
                            tagH = device.tag_info[kvp.Value.ParamH];
                        }

                        try
                        {
                            douA = Convert.ToDouble(tagA.Value);
                            douB = Convert.ToDouble(tagB.Value);
                            douC = Convert.ToDouble(tagC.Value);
                            douD = Convert.ToDouble(tagD.Value);
                            douE = Convert.ToDouble(tagE.Value);
                            douF = Convert.ToDouble(tagF.Value);
                            douG = Convert.ToDouble(tagG.Value);
                            douH = Convert.ToDouble(tagH.Value);

                            ExpressionCalculator exp_calc = new ExpressionCalculator(kvp.Value.Expression, douA, douB, douC, douD, douE, douF, douG, douH);
                            douResult       = exp_calc.Evaluate();
                            kvp.Value.Value = douResult.ToString();
                        }
                        catch (Exception ex)
                        {
                            douResult = -999999.999;
                        }
                    }
                }
            }
        }
        private void frmEditDBConfig_Load(object sender, EventArgs e)
        {
            cmbGateway.Items.Clear();
            if (this.gateway_mgr.gateway_list.Count > 0)
            {
                foreach (cls_Gateway_Info gi in this.gateway_mgr.gateway_list)
                {
                    cmbGateway.Items.Add(gi.gateway_id);
                }
            }

            lvTagList.Columns.Clear();
            lvTagList.Columns.Add("Tag Name", 100);
            lvTagList.Columns.Add("Data Type", 80);
            lvTagList.Columns.Add("Address", 100);
            lvTagList.Columns.Add("Scale", 60);
            lvTagList.Columns.Add("Offset", 60);
            lvTagList.Columns.Add("Update Time", 140);

            lvCalcTagList.Columns.Clear();
            lvCalcTagList.Columns.Add("Tag Name", 80);
            lvCalcTagList.Columns.Add("A", 50);
            lvCalcTagList.Columns.Add("B", 50);
            lvCalcTagList.Columns.Add("C", 50);
            lvCalcTagList.Columns.Add("D", 50);
            lvCalcTagList.Columns.Add("E", 50);
            lvCalcTagList.Columns.Add("F", 50);
            lvCalcTagList.Columns.Add("G", 50);
            lvCalcTagList.Columns.Add("H", 50);
            lvCalcTagList.Columns.Add("Expression", 180);

            cmbDBType.Items.Clear();
            cmbDBType.Items.Add("My SQL");
            cmbDBType.Items.Add("MS SQL");

            txtSerial.Enabled = false;
            this.serial_index = this.serial_index + 1;
            txtSerial.Text    = this.serial_index.ToString("D8");

            if (isEdit)
            {
                /*
                 * cmbGateway.Enabled = false;
                 * cmbDevice.Enabled = false;
                 * cmbDBType.Enabled = false;
                 * txtDataSource.Enabled = false;
                 * txtPortID.Enabled = false;
                 * txtConnectDB.Enabled = false;
                 * txtUserName.Enabled = false;
                 * txtPassword.Enabled = false;
                 */
                if (this.isCopy)
                {
                    gpbDBInfo.Enabled = true;
                    txtSerial.Enabled = false;
                }
                else
                {
                    gpbDBInfo.Enabled = false;
                }

                txtSerial.Text     = this.db_data.serial_id;
                cmbGateway.Text    = this.db_data.gateway_id;
                cmbDevice.Text     = this.db_data.device_id;
                cmbDBType.Text     = this.db_data.db_type;
                txtDataSource.Text = this.db_data.data_source;
                txtPortID.Text     = this.db_data.port_id;
                txtConnectDB.Text  = this.db_data.db_name;
                txtUserName.Text   = this.db_data.user_name;
                //txtPassword.Text = EncryptionHelper.Decrypt(this.db_data.password);
                txtPassword.Text = this.db_data.password;
                if (this.db_data.enable)
                {
                    chkEnable.Checked = true;
                }
                else
                {
                    chkEnable.Checked = false;
                }

                cls_Gateway_Info gi = this.gateway_mgr.gateway_list.Where(p => p.gateway_id == this.gateway_id).FirstOrDefault();
                if (gi != null)
                {
                    gateway_index = this.gateway_mgr.gateway_list.FindIndex(c => c.gateway_id == this.gateway_id);
                    cls_Device_Info di = gi.device_info.Where(a => a.device_name == this.device_id).FirstOrDefault();
                    if (di != null)
                    {
                        DisplayTagList(di);
                        DisplayCalcTagList(di);
                        device_index = gi.device_info.FindIndex(b => b.device_name == cmbDevice.Text.Trim());
                    }
                }
            }
        }
Beispiel #15
0
        private void frmEditEDCXml_Load(object sender, EventArgs e)
        {
            cmbGateway.Items.Clear();
            if (this.gateway_mgr.gateway_list.Count > 0)
            {
                foreach (cls_Gateway_Info gi in this.gateway_mgr.gateway_list)
                {
                    cmbGateway.Items.Add(gi.gateway_id);
                }
            }


            lvTagList.Columns.Clear();
            lvTagList.Columns.Add("Tag Name", 80);
            lvTagList.Columns.Add("Data Type", 60);
            lvTagList.Columns.Add("Address", 80);
            lvTagList.Columns.Add("Scale", 40);
            lvTagList.Columns.Add("Offset", 40);
            lvTagList.Columns.Add("Update Time", 120);

            lvCalcTagList.Columns.Clear();
            lvCalcTagList.Columns.Add("Tag Name", 80);
            lvCalcTagList.Columns.Add("A", 50);
            lvCalcTagList.Columns.Add("B", 50);
            lvCalcTagList.Columns.Add("C", 50);
            lvCalcTagList.Columns.Add("D", 50);
            lvCalcTagList.Columns.Add("E", 50);
            lvCalcTagList.Columns.Add("F", 50);
            lvCalcTagList.Columns.Add("G", 50);
            lvCalcTagList.Columns.Add("H", 50);
            lvCalcTagList.Columns.Add("Expression", 180);

            lvHeaderItemList.Columns.Clear();
            lvHeaderItemList.Columns.Add("Item Name", 60);
            lvHeaderItemList.Columns.Add("Value", 60);
            lvHeaderItemList.Columns.Add("Length", 60);

            cmbEDCHeaderSet.Items.Clear();
            if (LoadHeaderSetConfig())
            {
                if (this.edc_header_list.head_set_list.Count > 0)
                {
                    cmbEDCHeaderSet.Items.Clear();
                    foreach (cls_EDC_Header header in this.edc_header_list.head_set_list)
                    {
                        cmbEDCHeaderSet.Items.Add(header.set_name);
                    }
                }
            }

            cmbReportType.Items.Clear();
            cmbReportType.Items.Add("trigger");
            cmbReportType.Items.Add("interval");

            txtSerial.Enabled = false;
            this.serial_index = this.serial_index + 1;
            txtSerial.Text    = this.serial_index.ToString("D8");

            if (isEdit)
            {
                if (isCopy)
                {
                    cmbGateway.Enabled = true;
                    cmbDevice.Enabled  = true;
                }
                else
                {
                    cmbGateway.Enabled = false;
                    cmbDevice.Enabled  = false;
                }

                txtSerial.Text     = this.edc_data.serial_id;
                cmbGateway.Text    = this.edc_data.gateway_id;
                cmbDevice.Text     = this.edc_data.device_id;
                cmbReportType.Text = this.edc_data.report_tpye;
                if (this.edc_data.report_tpye == "trigger")
                {
                    txtReportInterval.Text    = "";
                    txtReportInterval.Enabled = false;
                }
                else if (this.edc_data.report_tpye == "interval")
                {
                    txtReportInterval.Text    = this.edc_data.report_interval.ToString();
                    txtReportInterval.Enabled = true;
                    if (this.edc_data.interval_function.Contains("AVG"))
                    {
                        chkAVG.Checked = true;
                    }

                    if (this.edc_data.interval_function.Contains("MAX"))
                    {
                        chkMAX.Checked = true;
                    }

                    if (this.edc_data.interval_function.Contains("MIN"))
                    {
                        chkMIN.Checked = true;
                    }
                }

                txtReportPath.Text = this.edc_data.ReportEDCPath;
                if (this.edc_data.enable)
                {
                    chkEnable.Checked = true;
                }
                else
                {
                    chkEnable.Checked = false;
                }

                cls_Gateway_Info gi = this.gateway_mgr.gateway_list.Where(p => p.gateway_id == this.gateway_id).FirstOrDefault();
                if (gi != null)
                {
                    gateway_index = this.gateway_mgr.gateway_list.FindIndex(c => c.gateway_id == this.gateway_id);
                    cls_Device_Info di = gi.device_info.Where(a => a.device_name == this.device_id).FirstOrDefault();
                    if (di != null)
                    {
                        DisplayTagList(di);
                        DisplayCalcTagList(di);
                        device_index = gi.device_info.FindIndex(b => b.device_name == cmbDevice.Text.Trim());
                    }
                }
                if (edc_data.edchead_info.Count > 0)
                {
                    lvHeaderItemList.BeginUpdate();
                    lvHeaderItemList.Items.Clear();
                    foreach (cls_EDC_Head_Item hi in edc_data.edchead_info)
                    {
                        ListViewItem item = new ListViewItem(hi.head_name);
                        item.SubItems.Add(hi.value);
                        item.SubItems.Add(hi.length.ToString());
                        lvHeaderItemList.Items.Add(item);
                    }
                    lvHeaderItemList.EndUpdate();
                }
            }
        }
        public void Organize_EDCPartaker(string GateWayID, string Device_ID)
        {
            //--- 等待EDC List information

            if (_objectmanager.EDCManager == null)
            {
                return;
            }

            List <ObjectManager.cls_EDC_Info> lst_EDCInfo = _objectmanager.EDCManager.gateway_edc.Where(p => p.gateway_id == GateWayID && p.device_id == Device_ID && p.enable == true).ToList();

            foreach (cls_EDC_Info _EDC in lst_EDCInfo)
            {
                EDCPartaker EDCReporter = new EDCPartaker(_EDC);
                EDCReporter.timestapm = DateTime.Now;

                cls_Gateway_Info gateway = _objectmanager.GatewayManager.gateway_list.Where(p => p.gateway_id == GateWayID).FirstOrDefault();
                if (gateway != null)
                {
                    cls_Device_Info device = gateway.device_info.Where(p => p.device_name == Device_ID).FirstOrDefault();
                    if (device != null)
                    {
                        // Assembly Normal Tag info
                        foreach (Tuple <string, string> _Items in _EDC.tag_info)
                        {
                            cls_EDC_Body_Item edcitem = new cls_EDC_Body_Item();
                            edcitem.item_name = _Items.Item1;
                            edcitem.item_type = "X";

                            if (device.tag_info.ContainsKey(_Items.Item2))
                            {
                                edcitem.item_value     = device.tag_info[_Items.Item2].Value;
                                edcitem.orig_item_type = device.tag_info[_Items.Item2].Expression;
                            }
                            else
                            {
                                edcitem.item_value = string.Empty;
                            }

                            EDCReporter.edcitem_info.Add(edcitem);
                        }

                        // Assembly Calc Tag info
                        foreach (Tuple <string, string> _Items in _EDC.calc_tag_info)
                        {
                            cls_EDC_Body_Item edcitem = new cls_EDC_Body_Item();
                            edcitem.item_name = _Items.Item1;
                            edcitem.item_type = "X";

                            if (device.calc_tag_info.ContainsKey(_Items.Item2))
                            {
                                edcitem.item_value     = device.calc_tag_info[_Items.Item2].Value;
                                edcitem.orig_item_type = "DOUBLE";
                            }
                            else
                            {
                                edcitem.item_value = string.Empty;
                            }

                            EDCReporter.edcitem_info.Add(edcitem);
                        }
                    }
                }

                //----- Send MQTT-----
                xmlMessage SendOutMsg = new xmlMessage();
                SendOutMsg.GatewayID   = GateWayID; // GateID
                SendOutMsg.DeviceID    = Device_ID; // DeviceID
                SendOutMsg.MQTTTopic   = "EDCService";
                SendOutMsg.MQTTPayload = JsonConvert.SerializeObject(EDCReporter, Newtonsoft.Json.Formatting.Indented);
                _QueueManager.PutMessage(SendOutMsg);
            }
        }
Beispiel #17
0
        private void btnDeviceSave_Click(object sender, EventArgs e)
        {
            cls_Device_Info diTemp         = new cls_Device_Info();
            bool            duplicate_flag = false;

            if (txtDeviceID.Text.Trim() == "")
            {
                MessageBox.Show("Please enter Device ID!", "Error");
                return;
            }

            if (!this.isEdit)
            {
                duplicate_flag = (bool)IEW.Platform.Kernel.Platform.Instance.Invoke("GatewayService", "CheckDuplicateDeviceID", new object[] { txtDeviceID.Text.Trim() });
                if (duplicate_flag)
                {
                    MessageBox.Show("Device ID should be unique!!", "Error");
                    return;
                }
            }

            if (cmbType.Text.Trim() == "")
            {
                MessageBox.Show("Please select the device type!", "Error");
                return;
            }

            if (cmbType.Text == "PLC")
            {
                if (txtPLC_IP.Text.Trim() == "")
                {
                    MessageBox.Show("Please enter the PLC ip!", "Error");
                    return;
                }
                else
                {
                    IPAddress ip;
                    bool      validate = IPAddress.TryParse(txtPLC_IP.Text.Trim(), out ip);
                    if (!validate)
                    {
                        MessageBox.Show("Please enter the  valid ip address!", "Error");
                        return;
                    }
                }

                if (txtPLC_Port.Text.Trim() == "")
                {
                    MessageBox.Show("Please enter the port id!", "Error");
                    return;
                }
            }
            else if (cmbType.Text == "BLE")
            {
                if (txtBLE_Mac.Text.Trim() == "")
                {
                    MessageBox.Show("Please enter the MAC address!", "Error");
                    return;
                }
                else
                {
                    Regex r = new Regex("^([0-9a-fA-F]{2}(?:(?:-[0-9a-fA-F]{2}){5}|(?::[0-9a-fA-F]{2}){5}|[0-9a-fA-F]{10}))$");
                    if (!r.IsMatch(txtBLE_Mac.Text.Trim()))
                    {
                        MessageBox.Show("Invalid MAC address!", "Error");
                        return;
                    }
                }

                if (txtBLE_Service_UUID.Text.Trim() == "")
                {
                    MessageBox.Show("Please enter the BLE Service UUID!", "Error");
                    return;
                }
            }

            diTemp.device_name     = txtDeviceID.Text.Trim();
            diTemp.device_type     = cmbType.Text.Trim();
            diTemp.device_location = txtLocation.Text.Trim();
            diTemp.plc_ip_address  = txtPLC_IP.Text.Trim();
            diTemp.plc_port_id     = txtPLC_Port.Text.Trim();
            diTemp.ble_mac         = txtBLE_Mac.Text.Trim();
            if (txtBLE_Service_UUID.Text.Trim() == "")
            {
                diTemp.ble_service_uuid = null;
            }
            else
            {
                diTemp.ble_service_uuid.Add(txtBLE_Service_UUID.Text.Trim());
            }

            diTemp.tag_info      = taglist_data;
            diTemp.calc_tag_info = calc_taglist_data;

            this.device_data = diTemp;

            if (!isEmbedded)
            {
                frmEditGateway pgw = (frmEditGateway)this.Owner;

                if (!isEdit)
                {
                    //pgw.device_list.Add(diTemp);
                    pgw.gateway_Info.device_info.Add(diTemp);
                }
                else
                {
                    //pgw.device_list[iDeviceIndex] = diTemp;
                    pgw.gateway_Info.device_info[iDeviceIndex] = diTemp;
                }
            }
            else
            {
                Gateway p = (Gateway)this.Owner;
                p.SetDeviceInfo(gw_data, device_data, iDeviceIndex, this.isCopy);
                p.RefreshGatewayConfig(0);
            }

            this.Close();
        }