Menu

Reading a WORD from modbus device

fizzle1967
2020-07-02
2021-08-17
  • fizzle1967

    fizzle1967 - 2020-07-02

    I am trying to read a 16 Bit word from a Modbus device. When the following reaches 32767 it rolls over to negative. Is there a way I can read larger values from a single register?

    int[] readHoldingRegisters = modbusClient.ReadHoldingRegisters(0, 8);
    label2.Text = readHoldingRegisters[7].ToString();

     
    • Rossmann Engineering

      Double - Please check a few Posts below

       
  • Anonymous

    Anonymous - 2020-07-08

    I have attempted a few things but am not sure this is what I need. Should the standard method int[] ReadHoldingRegisters(int startingAddress, int quantity) be able to read int values above 32767? It appears tha the other methods combine multiple registers to create either the double, or float. I was able to get the FLoat conversion to work fine on registers that use IEEE -754 , but in this case I just want to read one register that has a value that reaches 65,000 plus. I feel I am just using the ReadHoldingRegisters method incorrectly, and perhaps it is what I need. Can you provide any additional thoughts on what I may have set up incorrectly? This line gives some very large result:
    double varTest4 = ModbusClient.ConvertRegistersToDouble(modbusClient.ReadHoldingRegisters(0, 4));

     
    • Rossmann Engineering

      That is NOT a Modbus Issue, thats simple C# programming and you'll find some anwers already in this duscussion (or ask google). A Modbus Register contains 16 Bit and is handles is signed value -32768 - 32768. If you need values between 0 - 65535, you have to convert.

       
  • yasin

    yasin - 2021-08-17

    so why can't we write decimal value? float values ​​are rounded

     
  • Anonymous

    Anonymous - 2021-09-01
    Post awaiting moderation.

Anonymous
Anonymous

Add attachments
Cancel