示例#1
0
        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();
            }
        }
示例#2
0
        public static MqttServerHelper GetInstance()
        {
            if (instance == null)
            {
                instance = new MqttServerHelper();
            }

            bIsRuning = false;
            return(instance);
        }
示例#3
0
 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
     {
     }
 }
示例#4
0
        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);
        }
示例#5
0
 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;
     }
 }
示例#6
0
        /// <summary>
        /// 接收到消息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void MqttClient_ApplicationMessageReceived(object sender, MqttApplicationMessageReceivedEventArgs e)
        {
            Dictionary <string, object> json = Get_payload(e.ApplicationMessage.Payload);
            string topic = e.ApplicationMessage.Topic;
            string data  = Encoding.UTF8.GetString(e.ApplicationMessage.Payload);

            LogHelper.Log("mqtt recv:topic: " + e.ApplicationMessage.Topic.ToString() + " payload: " + data);

            Regex r_subtopic = new Regex(subtopic);                          // 定义一个Regex对象实例
            Match m_subtopic = r_subtopic.Match(e.ApplicationMessage.Topic); // 在字符串中匹配

            if (m_subtopic.Success)
            {
                SerialPortHelper.Write(e.ApplicationMessage.Payload, 0, e.ApplicationMessage.Payload.Length);
            }
            if (topic.IndexOf("$dg/device/" + username + "/" + dtuAddr) == 0)
            {
                if (json.ContainsKey("cmd"))
                {
                    if (json["cmd"].ToString() == "opc_items")
                    {
                        OPCDAHelper.Readitems(json);
                    }
                    else if (json["cmd"].ToString() == "opc_report")
                    {
                        OPCDAHelper.Publishvalues(json);
                    }
                    else if (json["cmd"].ToString() == "printer")
                    {
                        PrinterHelper.PrintPage(json["data"].ToString());
                    }
                }
            }

            AccessHelper.Do_mdb(topic, json, clientid);

            MqttServerHelper.Write(e.ApplicationMessage);
        }