• Recent
    • Tags
    • Popular
    • Register
    • Login
    1. Home
    2. Vicarious

    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
    V
    • Profile
    • Following 0
    • Followers 0
    • Topics 1
    • Posts 5
    • Best 0
    • Controversial 0
    • Groups 0

    Vicarious

    @Vicarious

    0
    Reputation
    748
    Profile views
    5
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    Vicarious Unfollow Follow

    Latest posts made by Vicarious

    • RE: Read more than a register in one request

      Hi, I'm not bkhashfeh but I have the same problem and I'd apreciate the help :D . Here is my code where I'm reading three registers per second (or trying).

      package modbusmastertest;

      import com.serotonin.modbus4j.ModbusFactory;
      import com.serotonin.modbus4j.ModbusMaster;
      import com.serotonin.modbus4j.code.DataType;
      import com.serotonin.modbus4j.ip.IpParameters;

      import java.io.FileWriter;
      import java.io.PrintWriter;
      import java.util.Calendar;

      class MBMasterTest {
      public static void main(String[] args) throws Exception {
      // Modbus master settings
      ModbusFactory factory = new ModbusFactory();
      IpParameters params = new IpParameters();
      params.setHost("192.168.0.1");
      params.setPort(502);
      params.setEncapsulated(false);
      ModbusMaster master = factory.createTcpMaster(params, false);
      master.setTimeout(333);
      master.setRetries(1);
      // CSV writter settings
      FileWriter fwriter;
      fwriter = new FileWriter("C:/Users/NESTOR/Dropbox/Siemens_S7-1200.csv");
      PrintWriter outputFile = new PrintWriter(fwriter);
      outputFile.println("Date,Sensor_1,Sensor_2,Sensor_3"); // Primera línea
      Object []Register = new Object[3];
      // Date settings
      Calendar cal = Calendar.getInstance();
      long elapsedTime = 0;
      long time = 0;

      	    // Cuerpo del programa
      	long start = System.currentTimeMillis(); // Tiempo de inicio
      	try {
      		master.init();
      		while(System.currentTimeMillis()<(start+10000)) {
      			time = System.currentTimeMillis();
      			for(int i = 0; i<3; i++) {
      				Register* = master.getValue(1,40001+i,DataType.TWO_BYTE_INT_SIGNED);
      			}
      			System.out.println(Register[0]+","+Register[1]+","+Register[2]);
      			System.out.println(""
      					+ "");
      			elapsedTime = System.currentTimeMillis()-time;
      			cal.setTimeInMillis(cal.getTime().getTime() + elapsedTime);
      			outputFile.println(cal.getTime().toString()+","+Register[0]+","+Register[1]+","+Register[2]); // Se escribe nueva linea en archivo
      		}
      		outputFile.close(); // Se cierra el archivo
      	}
      	finally {
      		master.destroy(); //Se destruye el objeto master
      	}
      	
      	System.out.println(""
      			+ "");
      	System.out.println("Tardo " + (System.currentTimeMillis()-start) + "ms");
      
      }
      

      }

      posted in Modbus4J general discussion
      V
      Vicarious
    • RE: Modbus4j modbus/tcp client with Siemens s7 1200 slave "Test" code

      I got help and figured it out. My PLC can't read encapsulated data.. at least with my current configuration I think.. It works perfectly.

      posted in Modbus4J general discussion
      V
      Vicarious
    • RE: Modbus4j modbus/tcp client with Siemens s7 1200 slave "Test" code

      @Vicarious said:

      Hi, I'm trying to run the Test code from the modbus4j-scr folder to communicate with my s7 1200. I wanna read the first 10 holding register values from the PLC and I know my modbus server configuration is OK because I've got those 10 values with the ICC modbus master tool.

      My Server's IP is 192.168.0.1 and its slaveID is 1. My code is:

      package modbusmastertest;

      import com.serotonin.modbus4j.ModbusFactory;
      import com.serotonin.modbus4j.ModbusMaster;
      import com.serotonin.modbus4j.code.DataType;
      //import com.serotonin.modbus4j.code.RegisterRange;
      import com.serotonin.modbus4j.ip.IpParameters;

      class MBMasterTest {
      public static void main(String[] args) throws Exception {
      ModbusFactory factory = new ModbusFactory();
      IpParameters params = new IpParameters();
      //params.setHost("127.0.0.1");
      params.setHost("192.168.0.1"); // Server's IP adress
      params.setPort(502);
      params.setEncapsulated(true);
      ModbusMaster master = factory.createTcpMaster(params, false);
      // master.setRetries(4);
      master.setTimeout(2000);
      master.setRetries(0);

         long start = System.currentTimeMillis();
         try {
             master.init();
             for (int i = 0; i < 10; i++) {
                 //System.out.println(master.getValue(127, RegisterRange.HOLDING_REGISTER, 1220, DataType.TWO_BYTE_INT_UNSIGNED));
             	//System.out.print(master.getValue(1, RegisterRange.HOLDING_REGISTER, 1220, DataType.TWO_BYTE_INT_UNSIGNED));
             	System.out.println(master.getValue(1,RegisterRange.HOLDING_REGISTER, 1 , DataType.TWO_BYTE_INT_SIGNED));  // ERROR LINE  :?
                 //System.out.println(master.getValue(1, 40001, 1 , DataType.TWO_BYTE_INT_SIGNED));
             }
         }
         finally {
             master.destroy();
         }
      
         System.out.println("Took: " + (System.currentTimeMillis() - start) + "ms");
      

      }
      }

      but when I press run i get a TimeoutException from the 28th code line (the one I comment as the ERROR LINE: "System.out.println..."). I'm a little noobie at modbus and to be honest.. I don't get what's going on in that loop.. If someone helps me I'd really appreciate it, thanks.

      posted in Modbus4J general discussion
      V
      Vicarious
    • Modbus4j modbus/tcp client with Siemens s7 1200 slave "Test" code

      Hi, I'm trying to run the Test code from the modbus4j-scr folder to communicate with my s7 1200. I wanna read the first 10 holding register values from the PLC and I know my modbus server configuration is OK because I've got those 10 values with the ICC modbus master tool.

      My Server's IP is 192.168.0.1 and its slaveID is 1. My code is:

      package modbusmastertest;

      import com.serotonin.modbus4j.ModbusFactory;
      import com.serotonin.modbus4j.ModbusMaster;
      import com.serotonin.modbus4j.code.DataType;
      //import com.serotonin.modbus4j.code.RegisterRange;
      import com.serotonin.modbus4j.ip.IpParameters;

      class MBMasterTest {
      public static void main(String[] args) throws Exception {
      ModbusFactory factory = new ModbusFactory();
      IpParameters params = new IpParameters();
      //params.setHost("127.0.0.1");
      params.setHost("192.168.0.1"); // Server's IP adress
      params.setPort(502);
      params.setEncapsulated(true);
      ModbusMaster master = factory.createTcpMaster(params, false);
      // master.setRetries(4);
      master.setTimeout(2000);
      master.setRetries(0);

          long start = System.currentTimeMillis();
          try {
              master.init();
              for (int i = 0; i < 10; i++) {
                  //System.out.println(master.getValue(127, RegisterRange.HOLDING_REGISTER, 1220, DataType.TWO_BYTE_INT_UNSIGNED));
              	//System.out.print(master.getValue(1, RegisterRange.HOLDING_REGISTER, 1220, DataType.TWO_BYTE_INT_UNSIGNED));
              	System.out.println(master.getValue(1,RegisterRange.HOLDING_REGISTER, 1 , DataType.TWO_BYTE_INT_SIGNED));  // ERROR LINE  :?
                  //System.out.println(master.getValue(1, 40001, 1 , DataType.TWO_BYTE_INT_SIGNED));
              }
          }
          finally {
              master.destroy();
          }
      
          System.out.println("Took: " + (System.currentTimeMillis() - start) + "ms");
      }
      

      }

      but when I press run i get a TimeoutException from the 28th code line (the one I comment as the ERROR LINE: "System.out.println..."). I'm a little noobie at modbus and to be honest.. I don't get what's going on in that loop.. If someone helps me I'd really appreciate it, thanks.

      posted in Modbus4J general discussion
      V
      Vicarious
    • RE: Modbus4j modbus/tcp client with Siemens s7 1200 slave "Test" code

      Hi, I'm trying to run the Test code from the modbus4j-scr folder to communicate with my s7 1200. I wanna read the first 10 holding register values from the PLC and I know my modbus server configuration is OK because I've got those 10 values with the ICC modbus master tool.

      My Server's IP is 192.168.0.1 and its slaveID is 1. My code is:

      package modbusmastertest;

      import com.serotonin.modbus4j.ModbusFactory;
      import com.serotonin.modbus4j.ModbusMaster;
      import com.serotonin.modbus4j.code.DataType;
      //import com.serotonin.modbus4j.code.RegisterRange;
      import com.serotonin.modbus4j.ip.IpParameters;

      class MBMasterTest {
      public static void main(String[] args) throws Exception {
      ModbusFactory factory = new ModbusFactory();
      IpParameters params = new IpParameters();
      //params.setHost("127.0.0.1");
      params.setHost("192.168.0.1"); // Server's IP adress
      params.setPort(502);
      params.setEncapsulated(true);
      ModbusMaster master = factory.createTcpMaster(params, false);
      // master.setRetries(4);
      master.setTimeout(2000);
      master.setRetries(0);

          long start = System.currentTimeMillis();
          try {
              master.init();
              for (int i = 0; i < 10; i++) {
                  //System.out.println(master.getValue(127, RegisterRange.HOLDING_REGISTER, 1220, DataType.TWO_BYTE_INT_UNSIGNED));
              	//System.out.print(master.getValue(1, RegisterRange.HOLDING_REGISTER, 1220, DataType.TWO_BYTE_INT_UNSIGNED));
              	System.out.println(master.getValue(1,RegisterRange.HOLDING_REGISTER, 1 , DataType.TWO_BYTE_INT_SIGNED));  // ERROR LINE  :?
                  //System.out.println(master.getValue(1, 40001, 1 , DataType.TWO_BYTE_INT_SIGNED));
              }
          }
          finally {
              master.destroy();
          }
      
          System.out.println("Took: " + (System.currentTimeMillis() - start) + "ms");
      }
      

      }

      but when I press run i get a TimeoutException from the 28th code line (the one I comment as the ERROR LINE: "System.out.println..."). I'm a little noobie at modbus and to be honest.. I don't get what's going on in that loop.. If someone helps me I'd really appreciate it, thanks.

      posted in Modbus4J general discussion
      V
      Vicarious