Hi
I'm using this code to send command via tcp to some device on the network,
The device sending feedback and I want to use it.
I'm not really know how to "capture the command" and using the feedback to something else.
how it's possible?
The command that came from the device is ">FN,OUT,OFF,2"
var remoteserver = "192.168.1.147";
Action<string>
HandleStringReceived = (string message) => {
// this will be called every time a message is received from the remote endpoint
Program.Notify("TcpClient String", message);
};
Action<byte[]>
HandleMessageReceived = (byte[] message) => {
// this will be called every time a message is received from the remote endpoint
Program.Notify("TcpClient Bytes", BitConverter.ToString(message));
};
Action<bool>
HandleStatusChanged = (bool connected) => {
// this will be called every time the connection status changes
Program.Notify("TcpClient Status", connected ? "CONNECTED!" : "DISCONNECTED!");
};
// open the serial port channel and register handlers
TcpClient
.Service( remoteserver ) // server
.OnStatusChanged( HandleStatusChanged )
.OnMessageReceived( HandleMessageReceived )
.OnStringReceived( HandleStringReceived )
.Connect( 7078 ); // port
// this is the main program loop
while (Program.IsEnabled)
{
if (TcpClient.OnMessageReceived(">FN,OUT,OFF,2")
{
TcpClient.SendMessage("FN,TOG,1\x0D");
}
Pause(3);
TcpClient.Disconnect();
Pause(3);
//
break;
}