如何访问5xxxx Modbus地址
我正在尝试使用 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);
}
}
I am trying to access addresses such as 50526 on a Socomec Diris A40 using nmodbus. Unlike other examples I have seen which start with 3 or 4, these addresses all start with a 5. 50544, 50550, 50556 are but a few more im intersted in.
As far as I understand it at the moment, the first number represents the Modbus function and does not actually refer to the real address, i.e. 30000 addresses use function 04, 40000 addresses function 03 (?). I have seen the first digit omitted and the rest used as the address. If I try this with my 50000 addresses I get some success, but not with all values and the results dont seem correct. MODPOLL returns the same results as my code.
I could really use some help! If anyone can advise me on how to access these 5xxxx registers, I would be extremely grateful.
Method code:
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);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试从 5xxxx 地址(以 1 或 0 开头的地址)中减去 40001 或 40000。
Try to subtract 40001 or 40000 from 5xxxx address (addresses start with 1 or 0).
地址为 5xxxx 的寄存器是保持寄存器。 (40001 至 5xxxx 范围)
因此,要找到 Modbus 寄存器地址,您应该从 40001 中减去它的地址。
例如 50512 - 40001=10511 (290F H)
祝你好运
Registers with 5xxxx address are holding registers. (40001 to 5xxxx range)
So to find Modbus register address you should subtract its address from 40001.
for example 50512 - 40001=10511 (290F H)
good luck