• 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

    Help understanding addresses (offsets)

    Modbus4J general discussion
    2
    3
    526
    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.
    • V
      VanJr
      last edited by

      I'm new to modbus4j and MODBUS. I have been tasked with reading data from a CLICK (Koyo) PLC. According to the CLICK Programming Software, the MODBUS 984 Address for the BIT I am trying to read (Address X001) is 100001 with function code 02:

      5c48b4e6-c9a8-4010-b8d3-bd508391c2b1-image.png

      However, the 100001 address doesn't seem to work with modbus4j. I suspect the value used for OFFSET is not correct. Here is what I have tried:

        public static void main( String[] args ) throws Exception
        {
          IpParameters ipParameters = new IpParameters();
          ipParameters.setHost( "10.3.17.132" );
          ipParameters.setPort( 502 );
      
          ModbusMaster master = new ModbusFactory().createTcpMaster( ipParameters, false );
          master.init();
      
          // Define the location (X001).
          BaseLocator< Boolean > inputStatus = BaseLocator.inputStatus( 1, 100001 );
          BaseLocator< Boolean > inputRegisterBit = BaseLocator.inputRegisterBit( 1, 100001, 1 );
      
          // Read the value
          System.out.println( master.getValue( inputStatus ) );
          System.out.println( master.getValue( inputRegisterBit ) );
        }
      

      This...

      BaseLocator< Boolean > inputStatus = BaseLocator.inputStatus( 1, 100001 );
      

      ...always returns FALSE. Although the BIT is TRUE/ON (software and indicator light confirm this) the code is always reporting FALSE.

      This...

      BaseLocator< Boolean > inputRegisterBit = BaseLocator.inputRegisterBit( 1, 100001, 1 );
      

      ... returns an exception:
      com.serotonin.modbus4j.exception.ModbusTransportException: Invalid offset: 100001

      Would someone please help me understand how to convert the MODBUS 984 Address to a modbus4j offset? Or am I going about this completely wrong?

      terrypackerT 1 Reply Last reply Reply Quote 0
      • terrypackerT
        terrypacker @VanJr
        last edited by

        @vanjr something isn't quite right with the image you posted. First try to understand what function code 02 is doing, Read an Input Status at an offset starting from 10001.

        https://www.simplymodbus.ca/FC02.htm

        Maybe I'm missing something but it doesn't seem possible that there is an input register at location 100001 as that offset from 10001 is larger than the 2 bytes that are allowed for the offset in the protocol message of function code 02. My guess is that there is a display error in the software you are using and the address is really 10001 in which case the offset is 0.

        V 1 Reply Last reply Reply Quote 1
        • V
          VanJr @terrypacker
          last edited by VanJr

          @terrypacker
          NOW I understand! The offset is determined using predefined starting addresses by function from the MODBUS specification! Your explanation and that website you pointed me to was far more informative than watching a bunch of YouTube videos! Thank you so much for you help!

          For those who find this thread later in life, here is what works (as of CLICK firmware 3.21):

            public static void main( String[] args ) throws Exception
            {
              /* Define Connection */
              IpParameters ipParameters = new IpParameters();
              ipParameters.setHost( "10.3.17.132" );
              ipParameters.setPort( 502 );
          
              /* Make the connection */
              ModbusMaster master = new ModbusFactory().createTcpMaster( ipParameters, false );
              master.init();
          
              /* Test connectivity */
              System.out.println( "testSlaveNode 1: " + master.testSlaveNode( 1 ) );
          
              /* Define the location points and type */
              BaseLocator< Boolean > clickX001 = BaseLocator.inputStatus( 1, 0 ); // Click X001: input BIT on CPU
              BaseLocator< Boolean > clickY001 = BaseLocator.coilStatus( 1, 0 ); // Click Y001: output COIL on CPU
              BaseLocator< Boolean > clickY002 = BaseLocator.coilStatus( 1, 1 ); // Click Y002: output COIL on CPU
              BaseLocator< Number > clickDS1 = BaseLocator.holdingRegister( 1, 0, DataType.TWO_BYTE_INT_SIGNED ); // Click DS1: Data Register Single Word
          
              /* Set/Write a value to a point */
              master.setValue( clickDS1, 1 );
          
              /* Get/Read the current value of each point */
              System.out.println( "clickX001  : " + master.getValue( clickX001 ) );
              System.out.println( "clickY001  : " + master.getValue( clickY001 ) );
              System.out.println( "clickY002  : " + master.getValue( clickY002 ) );
              System.out.println( "clickDS1   : " + master.getValue( clickDS1 ) );
            }
          

          PLC Program for testing:

          cd1664f4-d91d-4013-a770-bac216fcba96-image.png

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