我正在尝试使用 nmodbus 在 Socomec Diris A40 上访问诸如 50526 之类的地址。与我看到的其他以 3 或 4 开头的示例不同,这些地址都以 5 开头。50544、50550、50556 只是我感兴趣的几个。
目前就我的理解,第一个数字代表的是Modbus功能,实际上并不是指真正的地址,即30000地址使用04功能,40000地址使用03功能(?)。我已经看到省略了第一个数字,其余的用作地址。如果我用我的 50000 个地址尝试这个,我会取得一些成功,但不是所有的值,结果似乎不正确。MODPOLL 返回与我的代码相同的结果。
我真的可以使用一些帮助!如果有人能告诉我如何访问这些 5xxxx 寄存器,我将不胜感激。
方法代码:
public static void ModbusSerialRtuMasterReadRegisters()
{
using (SerialPort port = new SerialPort("COM1"))
{
// configure serial port
port.BaudRate = 9600;
port.DataBits = 8;
port.Parity = Parity.None;
port.StopBits = StopBits.One;
try
{
port.Open();
Console.WriteLine("port " + port.PortName + " open: " + port.IsOpen + "\n");
}
catch(Exception ex)
{
Console.WriteLine("Unable to open port: " + ex);
}
// create modbus master
IModbusSerialMaster master = ModbusSerialMaster.CreateRtu(port);
byte slaveId = 1;
ushort startAddress = 1;
ushort numRegisters = 5;
ushort[] registers = new ushort[numRegisters];;
// read registers
try
{
registers = master.ReadHoldingRegisters(slaveId, startAddress, numRegisters);
for (int i = 0; i < numRegisters; i++)
Console.WriteLine("Register {0}={1}", startAddress + i, registers[i]);
}
catch (Modbus.SlaveException se)
{
Console.WriteLine("Could not find register... \n \n" + se);
}
try
{
port.Close();
Console.WriteLine("\nport " + port.PortName + " open: " + port.IsOpen + "\n");
}
catch (Exception ex)
{
Console.WriteLine("Unable to close port: " + ex);
}
}