Modbus.Net
Modbus.Net copied to clipboard
Connect to the ModBus.Slave simulator
I need some help to understand how your library works. I'm in the following condition I've to connect to a Modbus.Slave (which has been given to me) with a config file and need to read those data (I think in polling). When one parameter changes I need to perform some action but that's a later point and there's no need right now to specify further.
So consider I've the Modbus.Slave running on localhost port 504 , how do I set my code to read data from it? I've tried to understand your sources but with no luck
Here's my snippet of code
private async void ButtonBase_OnClick(object sender, RoutedEventArgs e) { if (machine == null) { machine = new ModbusMachine(ModbusType.Tcp, "127.0.0.1:504", new List<AddressUnit>() {
new AddressUnit()
{
Id = "1",
Area = "4X",
Address = 1,
CommunicationTag = "Add1",
DataType = typeof(ushort),
Zoom = 1,
DecimalPos = 0
}
}, 2, 0);
}
machine.KeepConnect = true;
machine.Connect();
var resultFormat = (await machine.GetDatasAsync(MachineGetDataType.CommunicationTag))
.MapGetValuesToSetValues();
}
I got null and IsConnected is set to false. Any suggestion? Thanks
Hello, from my experience, please ensure that the Modbus Slave software is not on the same machine as your software, because port 504 will be occupied. In my method, Modbus Slave software is deployed on the virtual machine, and then accessed with Modbus.Net
There are more error message printing in dev channel. I will first close this issue. If you have more questions, please post it after that.