I've set up a Modbus-tcp slave using NModbus4 library.
I want to show the slave's status, whether it's listening(running?) or not running(idle?) - to show visually with green/red indicators.
I've looked through NModbus4 library and couldn't find any function that indicates the slave's status. Below is my best shot but it doesn't indicate if the slave stopped.
case "TCP":
try
{
TcpListener slaveTcpListener = new TcpListener(IP, Port);
slaveTcpListener.Start();
slave = ModbusTcpSlave.CreateTcp(SlaveID, slaveTcpListener);
slave.DataStore = DataStoreFactory.CreateDefaultDataStore(MaxCoil, MaxDI, MaxHR, MaxIR);
slave.DataStore.DataStoreReadFrom += new EventHandler<DataStoreEventArgs>(dataStore_DataStoreReadFrom);
slave.ModbusSlaveRequestReceived += Slave_ModbusSlaveRequestReceived;
slave.Listen();
lblCommStatus.Text = "Listening";
btnIndicator.BackColor = Color.Green;
}
catch
{
// Exception Handle
}
Any help is appreciated.
Thanks.