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); }
private void cmbGateway_SelectedIndexChanged(object sender, EventArgs e) { if (cmbGateway.Text.Trim() == "") { MessageBox.Show("Please select gateway id", "Error"); return; } cls_Gateway_Info gi = this.gateway_mgr.gateway_list.Where(p => p.gateway_id == cmbGateway.Text.Trim()).FirstOrDefault(); if (gi != null) { cmbDevice.Items.Clear(); foreach (cls_Device_Info di in gi.device_info) { cmbDevice.Items.Add(di.device_name); } gateway_index = this.gateway_mgr.gateway_list.FindIndex(p => p.gateway_id == cmbGateway.Text.Trim()); } else { MessageBox.Show("Find gateway failed", "Error"); return; } }
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); } } } } }
//Delegate function to add Gateway Information void SetGatewayInfo(cls_Gateway_Info g_info, bool edit_flag) { if (edit_flag) { int i = 0; if (gm.gateway_list.Count > 0) { foreach (cls_Gateway_Info gi in gm.gateway_list) { if (gi.gateway_id == g_info.gateway_id) { break; } i++; } gm.gateway_list[i] = g_info; } } else { gm.gateway_list.Add(g_info); } }
private void lvGatewayList_DoubleClick(object sender, EventArgs e) { string strGatewayID; cls_Gateway_Info gwTemp = new cls_Gateway_Info(); if (lvGatewayList.SelectedItems.Count == 0) { MessageBox.Show("Please select the gateway first!", "Error"); return; } strGatewayID = lvGatewayList.SelectedItems[0].Text.Trim(); int i = 0; foreach (cls_Gateway_Info gi in this.gm.gateway_list) { if (gi.gateway_id == strGatewayID) { gwTemp = this.gm.gateway_list[i]; break; } i++; } var frm = new frmEditGateway(SetGatewayInfo, gwTemp); frm.Owner = this; frm.ShowDialog(); gwTemp = null; RefreshGatewayList(); lvGatewayList.Focus(); }
// Constructor called by frmListGateway after clicked "+" button public frmEditGateway(SetGatewayInfo set_gw, ChechDuplicateGatewayID check, bool edit_flag) { InitializeComponent(); this.isEdit = edit_flag; this.gateway_Info = new cls_Gateway_Info(); this.delgSetGateway = set_gw; this.delgCheckDuplicate = check; }
//Constructor currently no use public frmEditGateway(cls_Gateway_Info gw) { InitializeComponent(); this.isEdit = true; this.gateway_Info = gw; this.device_list = gw.device_info; //iGatewayIndex = index; }
public bool CheckDuplicateGatewayID(string gateway_id) { cls_Gateway_Info gwi = ObjectManager.GatewayManager.gateway_list.Where(p => p.gateway_id == gateway_id).FirstOrDefault(); if (gwi != null) { return(true); } return(false); }
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); } }
//Constructor called by frmListGateway after double clicked the gateway list //Constructor called by Gateway.cs after clicked the gateway node public frmEditGateway(SetGatewayInfo set_gw, cls_Gateway_Info gw) { InitializeComponent(); this.isEdit = true; if (gw.gateway_id == "") { this.isCopy = true; } this.gateway_Info = gw; this.device_list = gw.device_info; //iGatewayIndex = index; this.delgSetGateway = set_gw; }
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); } } } } }
//Constructor called by Gateway.cs after clicked device node public frmEditDevice(cls_Gateway_Info gw, cls_Device_Info device, int index) { InitializeComponent(); this.isEdit = true; this.isEmbedded = true; this.gw_data = gw; 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); } } } } }
public Proc_IR_Temperature_DataXOL_Data(cls_Gateway_Info Gateway, Put_ProcRecv_CollectData_Event _delegate_Method) { _Gateway = Gateway; this.Put_ProcRecv_CollectData = _delegate_Method; }
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(); } } }
private void btnGWSave_Click(object sender, EventArgs e) { //Gateway lgateway = (Gateway)this.Owner; cls_Gateway_Info giTemp = new cls_Gateway_Info(); if (txtGatewayID.Text.Trim() == "") { MessageBox.Show("Please enter the gateway id!", "Error"); return; } else { if (!this.isEdit || this.isCopy) { /* * if(!this.delgCheckDuplicate(txtGatewayID.Text.Trim())) * { * return; * } */ bool gw_duplicate_flag = (bool)IEW.Platform.Kernel.Platform.Instance.Invoke("GatewayService", "CheckDuplicateGatewayID", new object[] { txtGatewayID.Text.Trim() }); if (gw_duplicate_flag) { MessageBox.Show("Gateway ID [" + txtGatewayID.Text.Trim() + "] is duplicate, it should be unique!!", "Error"); return; } } } if (!chkVirtual.Checked) { if (txtGatewayIP.Text.Trim() == "") { MessageBox.Show("Please enter the gateway ip!", "Error"); return; } else { IPAddress ip; bool validate = IPAddress.TryParse(txtGatewayIP.Text.Trim(), out ip); if (!validate) { MessageBox.Show("Please enter the valid ip address!", "Error"); return; } } } if (lvGWDevice.Items.Count == 0) { MessageBox.Show("Please add at lease one device", "Error"); return; } giTemp.gateway_id = txtGatewayID.Text.Trim(); giTemp.gateway_ip = txtGatewayIP.Text.Trim(); giTemp.location = txtLocation.Text.Trim(); if (chkVirtual.Checked) { if (txtTopic.Text.Trim() == "") { MessageBox.Show("Please input the Publish Topic for virtual gateway", "Error"); return; } giTemp.virtual_flag = true; } else { giTemp.virtual_flag = false; } giTemp.virtual_publish_topic = txtTopic.Text.Trim(); //giTemp.device_info = this.device_list; giTemp.device_info = this.gateway_Info.device_info; if (this.isCopy) { foreach (cls_Device_Info dvi in giTemp.device_info) { bool duplicate_flag = (bool)IEW.Platform.Kernel.Platform.Instance.Invoke("GatewayService", "CheckDuplicateDeviceID", new object[] { dvi.device_name }); if (duplicate_flag) { MessageBox.Show("Device ID [" + dvi.device_name + "] is duplicate, it should be unique!!", "Error"); return; } } delgSetGateway(giTemp, false); } else { delgSetGateway(giTemp, this.isEdit); } giTemp = null; this.Close(); }
private void btnUpdate_Click(object sender, EventArgs e) { cls_Cmd_OTA cmd_ota = new cls_Cmd_OTA(); int ver_index; ListView lvList = null; string gw_id; string dv_id; if (VerifyFTPData()) { this.ota_manager.ftp_info.server_ip = txtServerIP.Text.Trim(); this.ota_manager.ftp_info.server_port = txtServerPort.Text.Trim(); this.ota_manager.ftp_info.user_id = txtUserID.Text.Trim(); this.ota_manager.ftp_info.password = txtPassword.Text.Trim(); SaveFTPConfig(); } else { return; } if (VerifyInputData(AP_TYPE[tabOTA.SelectedIndex])) { SaveOTAConfig(); } else { return; } ver_index = 0; if (tabOTA.SelectedIndex == 0) //IOT Tab Page { lvList = lvIOTList; ver_index = 2; } else if (tabOTA.SelectedIndex == 1) //Worker Tab Page { lvList = lvWorkerList; ver_index = 2; } else if (tabOTA.SelectedIndex == 2) //Firmware Tab Page { lvList = lvFirmwareList; ver_index = 3; } if (lvList != null) { foreach (ListViewItem lvItem in lvList.CheckedItems) { //MessageBox.Show(lvItem.SubItems[2].Text, "Information"); cmd_ota.Trace_ID = DateTime.Now.ToString("yyyyMMddHHmmssfff"); cmd_ota.FTP_Server = txtServerIP.Text.Trim(); cmd_ota.FTP_Port = txtServerPort.Text.Trim(); cmd_ota.User_name = txtUserID.Text.Trim(); cmd_ota.Password = txtPassword.Text.Trim(); cmd_ota.App_Name = AP_TYPE[tabOTA.SelectedIndex]; cmd_ota.Current_Version = lvItem.SubItems[ver_index].Text; cmd_ota.New_Version = this.ver_info.ap_version; //cmd_ota.Process_ID = cmd_ota.Image_Name = this.ver_info.ap_store_path_name; cmd_ota.MD5_String = this.ver_info.md5_string; string json_string = JsonConvert.SerializeObject(cmd_ota, Newtonsoft.Json.Formatting.Indented); gw_id = lvItem.Text.Trim(); if (tabOTA.SelectedIndex == 0 || tabOTA.SelectedIndex == 1) { cls_Gateway_Info gw = this.gw_manager.gateway_list.Where(p => p.gateway_id == gw_id).FirstOrDefault(); dv_id = gw.device_info[0].device_name; cls_OTA_Gateway_Info ogi = null; if (tabOTA.SelectedIndex == 0) { ogi = this.ota_manager.ota_iot_list.Where(o => o.gateway_id == gw_id).FirstOrDefault(); } else { ogi = this.ota_manager.ota_worker_list.Where(o => o.gateway_id == gw_id).FirstOrDefault(); } if (ogi != null) { ogi.ap_new_version = this.ver_info.ap_version; ogi.ap_new_store_path_name = this.ver_info.ap_store_path_name; ogi.md5_new_string = this.ver_info.md5_string; ogi.ap_description = this.ver_info.ap_description; } } else { dv_id = lvItem.SubItems[1].Text.Trim(); cls_OTA_Device_Info odi = this.ota_manager.ota_firmware_list.Where(o => (o.gateway_id == gw_id) && (o.device_id == dv_id)).FirstOrDefault(); if (odi != null) { odi.ap_new_version = this.ver_info.ap_version; odi.ap_new_store_path_name = this.ver_info.ap_store_path_name; odi.md5_new_string = this.ver_info.md5_string; odi.ap_description = this.ver_info.ap_description; } } SaveOTAConfig(); IEW.Platform.Kernel.Platform.Instance.Invoke("GatewayService", "SendOTA", new object[] { gw_id, dv_id, json_string }); Thread.Sleep(500); } } }
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()); } } } }
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); } }
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; } } } } }