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(); } }
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); }
public static TcpClientHelper GetInstance() { if (instance == null) { instance = new TcpClientHelper(); } 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 { } }
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; } }
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(); } }