obj is the slave
args is the IModbusMessage
Do you have a specific question?
I think you'd be better off using the DataStoreWrittenTo event.This
would not require another NModbusMaster or any parsing. Let me know if
you have any more questions.
Scott
void dataStore_DataStoreWrittenTo(object sender, DataStoreEventArgs e)
{
if (e.Data.Option == DiscriminatedUnionOption.A)
{
Console.WriteLine(String.Format("Coil values {0} written starting at
address {1}",
String.Join(", ", e.Data.A.Select(d => d.ToString()).ToArray()),
e.StartAddress));
}
else
{
Console.WriteLine(String.Format("Holding register values {0} written
starting at address {1}",
String.Join(", ", e.Data.A.Select(r => r.ToString()).ToArray()),
e.StartAddress));
}
}
then you need to hook up to the data store event
dataStore.DataStoreWrittenTo += new
EventHandler<DataStoreEventArgs>(dataStore_DataStoreWrittenTo);
Scott
e.Data.A is a ReadOnlyCollection<bool> representing the coil values
written to the DataStore.
e.Data.B is a ReadOnlyCollection<ushort> representing the holding
register values written to the DataStore.
In the sample code d and r represent e.Data.A and e.Data.B
respectively as lambda expression arguments provided to the Select
extension method.
Whether or not you need to create a custom DataStore object is up to
you. The DataStore object is intended to be set up to model a Modbus
device's memory map (e.g. 1000 holding registers, 500 input registers,
etc.)
Scott