开发者

How to access 5xxxx Modbus address

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("Una开发者_JAVA百科ble 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);
            }
        }


Try to subtract 40001 or 40000 from 5xxxx address (addresses start with 1 or 0).


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜