Пример #1
0
        private static void Received(object sender, SerialDataReceivedEventArgs e)
        {
            var rxlen = port.BytesToRead;
            var data  = new byte[rxlen];

            port.Read(data, 0, rxlen);
            LogHelper.Log("SerialPort Recv: [" + LogHelper.Logdata(data, 0, rxlen) + "]");
            TcpClientHelper.Write(data, 0, rxlen);
        }
Пример #2
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
     {
     }
 }
Пример #3
0
        private static void Read(IAsyncResult ar)
        {
            try
            {
                var rxbytes = stream.EndRead(ar);
                if (rxbytes > 0)
                {
                    var offset = 0;
                    stream.BeginRead(tcpdata, 0, tcpdata.Length, Read, null);
                    LogHelper.Log("N->S: tcpServer recv [ " + LogHelper.Logdata(tcpdata, offset, rxbytes - offset) + "]");
                    TcpClientHelper.Write(tcpdata, offset, rxbytes - offset);

                    // Write(tcpdata, offset, rxbytes - offset);
                }

                if (rxbytes == 0)
                {
                    LogHelper.Log("Client closed");
                    OnConnectClosed();
                }
            }
            catch (Exception e)
            {
                if (e is ObjectDisposedException)
                {
                    LogHelper.Log("Connection closed");
                }
                else if (e is IOException && e.Message.Contains("closed"))
                {
                    LogHelper.Log("Connection closed");
                }
                else
                {
                    LogHelper.Log("Exception: " + e.Message);
                }

                OnConnectClosed();
            }
        }