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