private void ButtonStartStopClick(object sender, EventArgs e) { if (!bIsRunning) { bIsRunning = true; try { MqttServerHelper.Start(); MqttClientHelper.Start(); TcpClientHelper.Start(); TcpServerHelper.Start(); UDPServerHelper.Start(); UDPClientHelper.Start(); } catch (Exception error) { Log("star error " + error.ToString()); return; } buttonStartStop.Text = @"Stop"; DgiotHelper.GetIps(); SaveAppConfig(); } else { ToStop(); } }
public static void Config() { server = ConfigHelper.GetConfig("DgiotSever"); port = int.Parse(ConfigHelper.GetConfig("DgiotPort")); bIsCheck = DgiotHelper.StrTobool(ConfigHelper.GetConfig("UDPClientIsCheck")); bAutoReconnect = DgiotHelper.StrTobool(ConfigHelper.GetConfig("ReconnectChecked")); }
public static void Config(KeyValueConfigurationCollection config) { if (config["PLCIsCheck"] != null) { bIsCheck = DgiotHelper.StrTobool(config["PLCIsCheck"].Value); } }
public static void Config(KeyValueConfigurationCollection config, MainForm mainform) { if (config["ControlIsCheck"] != null) { ControlHelper.bIsCheck = DgiotHelper.StrTobool(config["ControlIsCheck"].Value); } ControlHelper.mainform = mainform; }
public static void Start() { Config(); LogHelper.Log("TcpClient_Checked " + ConfigHelper.GetConfig("TcpClient_Checked")); if (DgiotHelper.StrTobool(ConfigHelper.GetConfig("TcpClient_Checked"))) { CreateConnect(); } }
public static string Logdata(byte[] data, int offset, int len) { var line = bDisplayHex ? DgiotHelper.ToHexString(data, offset, len) : System.Text.Encoding.ASCII.GetString(data, offset, len); if (line.EndsWith("\r\n")) { line = line.Substring(0, line.Length - 2); } return(line); }
public static void Config() { port = int.Parse(ConfigHelper.GetConfig("DgiotPort")); if (DgiotHelper.StrTobool(ConfigHelper.GetConfig("UDPClient_Checked")) && DgiotHelper.StrTobool(ConfigHelper.GetConfig("Bridge_Checked"))) { bIsCheck = true; } else { bIsCheck = false; } }
public static byte[] Payload(char[] data) { byte[] payload = System.Text.Encoding.UTF8.GetBytes(data); if (bDisplayHex) { byte[] hexPayload = DgiotHelper.ToHexBinary(payload); return(hexPayload); } else { return(payload); } }
public static void StartMonitor() { if (DgiotHelper.StrTobool(ConfigHelper.GetConfig("OPCDACheck"))) { interval = int.Parse(ConfigHelper.GetConfig("OPCDAInterval")) * 1000; int count = int.Parse(ConfigHelper.GetConfig("OPCDACount")); OpcDa.StartGroup(OPCDAViewHelper.GetRootNode(), interval, count); } else { OpcDa.StopGroup(); } }
public static void Config() { bAutoReconnect = DgiotHelper.StrTobool(ConfigHelper.GetConfig("ReconnectChecked")); server = ConfigHelper.GetConfig("DgiotSever"); LogHelper.Log("DgiotPort " + ConfigHelper.GetConfig("DgiotPort")); port = int.Parse(ConfigHelper.GetConfig("DgiotPort")); clientid = ConfigHelper.GetConfig("MqttClientId"); username = ConfigHelper.GetConfig("MqttUserName"); password = ConfigHelper.GetConfig("MqttPassword"); pubtopic = ConfigHelper.GetConfig("MqttPubTopic"); subtopic = ConfigHelper.GetConfig("MqttSubTopic"); dtuAddr = ConfigHelper.GetConfig("DtuAddr"); bIsCheck = DgiotHelper.StrTobool(ConfigHelper.GetConfig("MqttClient_Checked")); }
public static void Config() { clientid = ConfigHelper.GetConfig("MqttClientId"); pubtopic = ConfigHelper.GetConfig("MqttPubTopic"); port = int.Parse(ConfigHelper.GetConfig("DgiotPort")); if (DgiotHelper.StrTobool(ConfigHelper.GetConfig("MqttClient_Checked")) && DgiotHelper.StrTobool(ConfigHelper.GetConfig("Bridge_Checked"))) { bIsCheck = true; } else { bIsCheck = false; } }
private void RestoreUDP() { if (ConfigHelper.Check("UDPClientLogin")) { textBoxUDPClientLogin.Text = ConfigHelper.GetConfig("UDPClientLogin"); } else { ConfigHelper.SetConfig("UDPClientLogin", textBoxUDPClientLogin.Text); } if (ConfigHelper.Check("UDPClient_Checked")) { radioButtonUDPClient.Checked = DgiotHelper.StrTobool(ConfigHelper.GetConfig("UDPClient_Checked")); } else { ConfigHelper.SetConfig("UDPClient_Checked", DgiotHelper.BoolTostr(radioButtonUDPClient.Checked)); } }
public void ValueChangedCallBack(OpcDaGroup group, OpcDaItemValue[] values) { JsonObject result = new JsonObject(); result.Add("timestamp", DgiotHelper.Now()); string groupKey = ""; JsonObject properties = new JsonObject(); List <Item> collection = new List <Item>(); values.ToList().ForEach(v => { if (v.Item != null && v.Value != null) { properties.Add(v.Item.ItemId, v.Value); groupKey = v.Item.UserData as string; OpcDa.setItems(groupKey, v.Item.ItemId, properties); } }); int i = OpcDa.getItemsCount(groupKey); if (i <= 0) { properties = OpcDa.getItems(group, groupKey); string topic = "$dg/thing/" + productId + "/" + devAddr + "/properties/report"; int flag1 = OpcDa.GetGroupFlag(groupKey); if (flag1 > 0) { properties.Add("dgiotcollectflag", 0); LogHelper.Log(" topic: " + topic + " payload: " + properties); } else { properties.Add("dgiotcollectflag", 1); } result.Add("properties", properties); MqttClientHelper.Publish(topic, Encoding.UTF8.GetBytes(properties.ToString())); // LogHelper.Log("properties: " + properties.ToString()); } }
public static string Key(string path) { return(DgiotHelper.Md5(path).Substring(0, 10)); }
private void RadioButtonUDPClient_CheckedChanged(object sender, EventArgs e) { ConfigHelper.SetConfig("UDPClient_Checked", DgiotHelper.BoolTostr(radioButtonTcpClient.Checked)); ConfigHelper.SetConfig("TcpClient_Checked", DgiotHelper.BoolTostr(false)); ConfigHelper.SetConfig("MqttClient_Checked", DgiotHelper.BoolTostr(false)); }
private void RestoreCommonConfig() { if (ConfigHelper.Check("DtuAddr")) { var tmp = ConfigHelper.GetConfig("DtuAddr"); comboBoxDtuAddr.SelectedIndex = comboBoxDtuAddr.Items.IndexOf(tmp); } else { ConfigHelper.SetConfig("DtuAddr", comboBoxDtuAddr.Text); } if (ConfigHelper.Check("DgiotSever")) { textBoxDgiotSever.Text = ConfigHelper.GetConfig("DgiotSever"); } else { ConfigHelper.SetConfig("DgiotSever", textBoxDgiotSever.Text); } if (ConfigHelper.Check("DgiotPort")) { textBoxDgiotPort.Text = ConfigHelper.GetConfig("DgiotPort"); } else { ConfigHelper.SetConfig("DgiotPort", textBoxDgiotPort.Text); } if (ConfigHelper.Check("BridgePort")) { textBoxBridgePort.Text = ConfigHelper.GetConfig("BridgePort"); } else { ConfigHelper.SetConfig("BridgePort", textBoxBridgePort.Text); } if (ConfigHelper.Check("ReconnectChecked")) { checkBoxReconnect.Checked = DgiotHelper.StrTobool(ConfigHelper.GetConfig("ReconnectChecked")); } else { ConfigHelper.SetConfig("ReconnectChecked", DgiotHelper.BoolTostr(checkBoxReconnect.Checked)); } if (ConfigHelper.Check("LogLevel")) { var tmp = ConfigHelper.GetConfig("LogLevel"); comboBoxLogLevel.SelectedIndex = comboBoxLogLevel.Items.IndexOf(tmp); } else { ConfigHelper.SetConfig("LogLevel", comboBoxLogLevel.Text); } if (ConfigHelper.Check("ToPayload")) { textToPayload.Text = ConfigHelper.GetConfig("ToPayload"); } else { ConfigHelper.SetConfig("ToPayload", textToPayload.Text); } if (ConfigHelper.Check("DisplayHex")) { checkBoxDisplayHex.Checked = DgiotHelper.StrTobool(ConfigHelper.GetConfig("DisplayHex")); } else { ConfigHelper.SetConfig("DisplayHex", DgiotHelper.BoolTostr(checkBoxDisplayHex.Checked)); } if (ConfigHelper.Check("Bridge_Checked")) { checkBoxBridge.Checked = DgiotHelper.StrTobool(ConfigHelper.GetConfig("Bridge_Checked")); } else { ConfigHelper.SetConfig("Bridge_Checked", DgiotHelper.BoolTostr(checkBoxBridge.Checked)); } }
private void SetComboBox() { var arrPorts = SerialPortHelper.GetPorts(); comboBoxSerialPort.Items.Clear(); foreach (var port in arrPorts) { comboBoxSerialPort.Items.Add(port); } if (arrPorts.Length > 0) { comboBoxSerialPort.SelectedIndex = 0; } comboBoxBaudRate.SelectedIndex = 7; comboBoxDataBits.SelectedIndex = 0; comboBoxStopBits.SelectedIndex = 0; comboBoxParity.SelectedIndex = 0; comboBoxCmdProdxy.SelectedIndex = 0; comboBoxBridge.Items.Clear(); foreach (var bridge in bridges) { comboBoxBridge.Items.Add(bridge); } if (bridges.Length > 0) { comboBoxBridge.SelectedIndex = 0; } comboBoxDtuAddr.Items.Clear(); List <string> macAddrs = DgiotHelper.GetMacByWmi(); foreach (var mac in macAddrs) { devaddr = Regex.Replace(mac, @":", ""); comboBoxDtuAddr.Items.Add(devaddr); textBoxTcpClientLogin.Text = devaddr; textBoxUDPClientLogin.Text = devaddr; } comboBoxDtuAddr.SelectedIndex = 0; List <string> loglevels = LogHelper.Levels(); foreach (var level in loglevels) { comboBoxLogLevel.Items.Add(level); } if (loglevels.Count > 0) { comboBoxLogLevel.SelectedIndex = (int)LogHelper.Level.DEBUG; } comboBoxLan.Items.Add("简体中文"); comboBoxLan.Items.Add("English"); comboBoxLan.SelectedIndex = 0; }
public static void Config() { bDisplayHex = DgiotHelper.StrTobool(ConfigHelper.GetConfig("DisplayHex")); }
private void RestoreMqtt() { if (ConfigHelper.Check("MqttUserName")) { textBoxMqttUserName.Text = ConfigHelper.GetConfig("MqttUserName"); } else { ConfigHelper.SetConfig("MqttUserName", textBoxMqttUserName.Text); } if (ConfigHelper.Check("MqttPassword")) { textBoxMqttPassword.Text = ConfigHelper.GetConfig("MqttPassword"); } else { ConfigHelper.SetConfig("MqttPassword", textBoxMqttPassword.Text); } if (ConfigHelper.Check("MqttClientId")) { textBoxMqttClientId.Text = ConfigHelper.GetConfig("MqttClientId"); } else { ConfigHelper.SetConfig("MqttClientId", comboBoxDtuAddr.Text); } if (ConfigHelper.Check("MqttPubTopic")) { textBoxMqttPubTopic.Text = ConfigHelper.GetConfig("MqttPubTopic"); } else { ConfigHelper.SetConfig("MqttPubTopic", textBoxMqttPubTopic.Text); } if (ConfigHelper.Check("MqttSubTopic")) { textBoxMqttSubTopic.Text = ConfigHelper.GetConfig("MqttSubTopic"); } else { ConfigHelper.SetConfig("MqttSubTopic", textBoxMqttSubTopic.Text); } if (ConfigHelper.Check("CmdProdxy")) { var tmp = ConfigHelper.GetConfig("CmdProdxy"); comboBoxCmdProdxy.SelectedIndex = comboBoxCmdProdxy.Items.IndexOf(tmp); } else { ConfigHelper.SetConfig("CmdProdxy", comboBoxCmdProdxy.Text); } if (ConfigHelper.Check("MqttClient_Checked")) { radioButtonMqttClient.Checked = DgiotHelper.StrTobool(ConfigHelper.GetConfig("MqttClient_Checked")); } else { ConfigHelper.SetConfig("MqttClient_Checked", DgiotHelper.BoolTostr(radioButtonMqttClient.Checked)); } }
private void CheckBoxReconnectCheckedChanged(object sender, EventArgs e) { ConfigHelper.SetConfig("ReconnectChecked", DgiotHelper.BoolTostr(checkBoxReconnect.Checked)); }
private void CheckBoxDisplayHexCheckedChanged(object sender, EventArgs e) { ConfigHelper.SetConfig("DisplayHex", DgiotHelper.BoolTostr(checkBoxDisplayHex.Checked)); LogHelper.Config(); }
public static string Key(TreeNode parentNode, string itemid) { return(DgiotHelper.Md5(parentNode.FullPath + "/" + itemid).Substring(0, 10)); }
private void CheckBoxBridge_CheckedChanged(object sender, EventArgs e) { ConfigHelper.SetConfig("Bridge_Checked", DgiotHelper.BoolTostr(checkBoxBridge.Checked)); }
private void CheckBoxOPCDA_CheckedChanged(object sender, EventArgs e) { ConfigHelper.SetConfig("OPCDACheck", DgiotHelper.BoolTostr(checkBoxOPCDA.Checked)); OPCDAHelper.StartMonitor(); }