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 MqttClientHelper GetInstance() { if (instance == null) { instance = new MqttClientHelper(); } return(instance); }
private void SendBridge_Click(object sender, EventArgs e) { byte[] payload = LogHelper.Payload(textToPayload.Text.ToCharArray()); LogHelper.Log(bridges[comboBoxBridge.SelectedIndex] + " send [" + LogHelper.Logdata(payload, 0, payload.Length) + "]"); // PrinterHelper.SetTextData(textToPayload.Text); PrinterHelper.PrintPage(textToPayload.Text); if (bridges[comboBoxBridge.SelectedIndex] == "SerialPort") { } else if (bridges[comboBoxBridge.SelectedIndex] == "TcpServer") { TcpServerHelper.Write(payload, 0, payload.Length); } else if (bridges[comboBoxBridge.SelectedIndex] == "Barcode_Printer") { TcpServerHelper.Write(payload, 0, payload.Length); } else if (bridges[comboBoxBridge.SelectedIndex] == "PLC") { } else if (bridges[comboBoxBridge.SelectedIndex] == "OPCUA") { } else if (bridges[comboBoxBridge.SelectedIndex] == "BACnet") { BACnetHelper.Write(payload, 0, payload.Length); } else if (bridges[comboBoxBridge.SelectedIndex] == "Control") { } else if (bridges[comboBoxBridge.SelectedIndex] == "Access") { } else if (bridges[comboBoxBridge.SelectedIndex] == "SqlServer") { } else if (bridges[comboBoxBridge.SelectedIndex] == "MqttClient") { MqttClientHelper.Write(payload, 0, payload.Length); } else if (bridges[comboBoxBridge.SelectedIndex] == "MqttServer") { MqttServerHelper.Write(payload, 0, payload.Length); } else if (bridges[comboBoxBridge.SelectedIndex] == "TcpClient") { TcpClientHelper.Write(payload, 0, payload.Length); } else if (bridges[comboBoxBridge.SelectedIndex] == "UdpClient") { } else { } }
/// <summary> /// 接收到消息 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private static void MqttServer_ApplicationMessageReceived(object sender, MqttApplicationMessageReceivedEventArgs e) { string data = Encoding.UTF8.GetString(e.ApplicationMessage.Payload); LogHelper.Log("mqtt server recv :topic: " + e.ApplicationMessage.Topic.ToString() + " payload: " + data + " ClientId " + e.ClientId); Regex r_pubtopic = new Regex(pubtopic + clientid); // 定义一个Regex对象实例 Match m_pubtopic = r_pubtopic.Match(e.ApplicationMessage.Topic); // 在字符串中匹配 if (m_pubtopic.Success) { MqttClientHelper.Write(e.ApplicationMessage); } }
private void Resh_Config() { MqttClientHelper.Config(); MqttServerHelper.Config(); TcpClientHelper.Config(); TcpServerHelper.Config(); UDPClientHelper.Config(); UDPServerHelper.Config(); SerialPortHelper.Config(); PLCHelper.Config(config.AppSettings.Settings); OPCDAHelper.Config(); OPCUAHelper.Config(config.AppSettings.Settings); AccessHelper.Config(config.AppSettings.Settings); SqlServerHelper.Config(config.AppSettings.Settings); }
private void ToStop() { try { buttonStartStop.Text = @"Start"; bIsRunning = false; MqttClientHelper.Stop(); MqttServerHelper.Stop(); TcpClientHelper.Stop(); TcpServerHelper.Stop(); UDPClientHelper.Stop(); UDPServerHelper.Stop(); } catch (Exception e) { Log("stop server exception:" + e.Message); return; } }
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 void Scan_mdb(Dictionary <string, object> json) { if (json.ContainsKey("dbq")) { try { dbq = (string)json["dbq"]; } catch (Exception ex) { Console.WriteLine("{0}", ex.ToString()); } } if (json.ContainsKey("security")) { try { security = (string)json["security"]; security = security.ToUpper(); } catch (Exception ex) { Console.WriteLine("{0}", ex.ToString()); } } if (json.ContainsKey("uid")) { try { uid = (string)json["uid"]; } catch (Exception ex) { Console.WriteLine("{0}", ex.ToString()); } } if (json.ContainsKey("pwd")) { try { pwd = (string)json["pwd"]; } catch (Exception ex) { Console.WriteLine("{0}", ex.ToString()); } } if (security == "TRUE") { odbcconnectionString = "Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=" + dbq + "; Uid=" + uid + "; Pwd=" + pwd + ";"; } else { odbcconnectionString = "Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=" + dbq; } Console.WriteLine(odbcconnectionString); using (var db = new OdbcConnection(odbcconnectionString)) { db.Open(); var schemaTable = db.GetSchema("Tables"); var dataSet = new DataSet(); for (var i = 0; i < schemaTable.Rows.Count; i++) { // only source tables if (schemaTable.Rows[i]["TABLE_TYPE"].ToString() == "TABLE") { var tableName = schemaTable.Rows[i]["TABLE_NAME"].ToString(); var sql = "SELECT TOP 1 * FROM [" + tableName + "]"; var dataTable = new DataTable(tableName); using (var command = new OdbcCommand(sql, db)) { using (var adapter = new OdbcDataAdapter(command)) { adapter.Fill(dataTable); } } // Console.WriteLine(tableName + "(" + dataTable.Rows.Count + " rows)"); dataSet.Tables.Add(dataTable); } } dataSet.AcceptChanges(); var jsonResults = DataSetToJson(dataSet); MqttClientHelper.Publish(scantopic, Encoding.UTF8.GetBytes(jsonResults.ToString())); LogHelper.Log(jsonResults); } }