• Recent
    • Tags
    • Popular
    • Register
    • Login

    Please Note This forum exists for community support for the Mango product family and the Radix IoT Platform. Although Radix IoT employees participate in this forum from time to time, there is no guarantee of a response to anything posted here, nor can Radix IoT, LLC guarantee the accuracy of any information expressed or conveyed. Specific project questions from customers with active support contracts are asked to send requests to support@radixiot.com.

    Radix IoT Website Mango 3 Documentation Website Mango 4 Documentation Website Mango 5 Documentation Website

    Handling of IEC 61131-3 data type BYTE

    Modbus4J general discussion
    1
    3
    2.4k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J
      jmbsps
      last edited by

      Hello,

      thanks for providing modbus4j as free software.
      Recently I started using modbus4j in a little project feeding some data from our house into rrdtool for long term visualisation.

      I was wondering how to handle the IEC 61131-3 data type BYTE which is defined as an 8-bit bit string.
      There is no 8-bit data type in modbus4j.

      I know that Modbus only defines single bit or register (16-bit) operations. On the slave I can define 8-bit BYTE values and it would be great if there would be a convenience method retrieving it.

      Something like the convenience methods for retrieving bit values.

      batchRead.addLocator("FirstByteValue", slaveId, RegisterRange.INPUT_REGISTER, 256, DataType.BYTE, (byte) 0); //retrieves first byte from register 256
      batchRead.addLocator("SecondByteValue", slaveId, RegisterRange.INPUT_REGISTER, 256, DataType.BYTE, (byte) 1); //retrieves second byte from register 256

      I planned on hacking this into my own modified version of modbus4j.
      My plan is to define this as java primitive short since BYTE in IEC 61131-3 is unsigned and there is no unsigned 8-bit value in java.

      Is this something of general interest? Since modbus4j is free software I'd like to offer my modifications back to the project.

      Regards
      jmbsps

      1 Reply Last reply Reply Quote 0
      • J
        jmbsps
        last edited by

        Hello,

        so far getting byte values is working but I'd like some opinions on the byte order.

        Should byte 0 be the LSB or MSB?

        Modbus being big-endian the first byte in the register (register is a 16-bit word) is the MSB. The second is the LSB.
        But in my PLC when I configure the variables the first byte value at a given address is the LSB, the second the MSB.

        To summarize:

        PLC configuration
        BYTE first AT %QB616
        BYTE second AT %QB617

        MODBUS register 308 (word value)
        second | first

        modbus4j
        should this be
        batchRead.addLocator("second", slaveId, RegisterRange.INPUT_REGISTER, 308, DataType.BYTE, (byte) 0);
        batchRead.addLocator("first", slaveId, RegisterRange.INPUT_REGISTER, 308, DataType.BYTE, (byte) 1);
        or
        batchRead.addLocator("first", slaveId, RegisterRange.INPUT_REGISTER, 308, DataType.BYTE, (byte) 0);
        batchRead.addLocator("second", slaveId, RegisterRange.INPUT_REGISTER, 308, DataType.BYTE, (byte) 1);

        I would prefer the latter.

        Regards
        jmbsps

        1 Reply Last reply Reply Quote 0
        • First post
          Last post