• Register
    • Login
    • Search
    • Recent
    • Tags
    • Popular

    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

    Modbu4J, Help for read register

    Modbus4J general discussion
    2
    7
    5209
    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.
    • F
      fabou3377 last edited by

      Hi,
      thanks for your library.. Have you an sample to read a marker (word) in a plc?
      Thanks

      1 Reply Last reply Reply Quote 0
      • F
        fabou3377 last edited by

        Here my code:

        
           public static void main(String[] args) {
               
                    ModbusFactory m = new ModbusFactory();
                    IpParameters ip = new IpParameters();
                    ip.setHost("127.0.0.1");
                    ip.setPort(502);
                    ModbusMaster mp = m.createTcpMaster(ip, false);
                try {
                    mp.init();
                    ModbusRequest req = new ReadInputRegistersRequest(1, 0, 1);
                    ReadInputRegistersResponse rep = (ReadInputRegistersResponse) mp.send(req);
                    System.out.println(rep.getData());
        
                } catch (Exception ex) {
                    Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
                }
              
            }
        
        
        

        I've this exception:

        
        
        Exception in thread "main" java.lang.NoSuchMethodError: com.serotonin.io.messaging.StreamTransport.<init>(Ljava/io/InputStream;Ljava/io/OutputStream;)V
                at com.serotonin.modbus4j.ip.tcp.TcpMaster.openConnection(TcpMaster.java:113)
                at com.serotonin.modbus4j.ip.tcp.TcpMaster.send(TcpMaster.java:62)
                at javaapplication6.Main.main(Main.java:45)
        
        
        
        
        

        Thanks for your furture help

        1 Reply Last reply Reply Quote 0
        • M
          mlohbihler last edited by

          Is seroUtils.jar in your classpath?

          Best regards,
          Matthew

          1 Reply Last reply Reply Quote 0
          • F
            fabou3377 last edited by

            Ok its works..
            my code :

            public static void main(String[] args) {
                   
                        ModbusFactory m = new ModbusFactory();
                        IpParameters ip = new IpParameters();
                        ip.setHost("192.168.10.2");
                        ip.setPort(502);
                        ModbusMaster mp = m.createUdpMaster(ip);
                    try {
                        mp.init();
                        ModbusRequest req = new WriteRegisterRequest(1,0,1800);
                        mp.send(req);
                        ModbusRequest req2 = new ReadHoldingRegistersRequest(1,0,1);
                        ReadResponse rep = (ReadResponse) mp.send(req2);
                        System.out.println(rep.getShortData()[0]);
                        
                    } catch (Exception ex) {
                        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
                    }
                  
                }
            

            in my classpath:
            axis.jar
            bacnet.jar
            modbus4j.jar
            RTXXcomm.jar
            serioUtil.jar

            All this library are necessary?

            It's not possible to get direct the value short double string? In the good typage?

            Thanks four your help and for your job, it's great and its works under windows and linux, before I've tried UDP under linux with jamod and there is serious problems..

            It's should be very interessant if the necessary library are of sourceforge.net..

            For the novice, a little tutorial should be nice..

            1 Reply Last reply Reply Quote 0
            • M
              mlohbihler last edited by

              You shouldn't need bacnet.jar and axis.jar. And if you're using UDP you shouldn't need RXTX either.

              Regarding your code, you should be able to simplify it a bit. ModbusMaster has a number of "getValue" and "setValue" convenience methods. For example, here's something you could do:

               // Define the point locator.
              ModbusLocator loc = new ModbusLocator(1, RegisterRange.HOLDING_REGISTER, 0, DataType.TWO_BYTE_INT_UNSIGNED);
              
              // Set the point value
              master.setValue(loc, 1800);
              
              // Get the point value
              System.out.println(master.getValue(loc));
              
              

              Best regards,
              Matthew

              1 Reply Last reply Reply Quote 0
              • F
                fabou3377 last edited by

                Thanks!

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