Test.java 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import com.serotonin.modbus4j.ip.encap.EncapMessageParser;
  2. import com.serotonin.modbus4j.sero.messaging.IncomingMessage;
  3. import com.serotonin.modbus4j.sero.util.queue.ByteQueue;
  4. public class Test {
  5. // public static void main(String[] args) {
  6. // NumericLocator l = new NumericLocator(0, 0, 0, DataType.FOUR_BYTE_INT_UNSIGNED_SWAPPED);
  7. // System.out.println(l.bytesToValue(new byte[] { (byte) 0xE8, 0x03, 0x00, 0x00 }, 0));
  8. // }
  9. public static void main(String[] args) throws Exception {
  10. {
  11. ByteQueue b = new ByteQueue("01040000000271cb");
  12. EncapMessageParser parser = new EncapMessageParser(false);
  13. IncomingMessage m = parser.parseMessage(b);
  14. System.out.println(m);
  15. }
  16. {
  17. ByteQueue b = new ByteQueue("01040404d2162ed4f1");
  18. EncapMessageParser parser = new EncapMessageParser(true);
  19. IncomingMessage m = parser.parseMessage(b);
  20. System.out.println(m);
  21. }
  22. }
  23. // public static void main(String[] args) throws Exception {
  24. // ModbusFactory factory = new ModbusFactory();
  25. // IpParameters params = new IpParameters();
  26. //
  27. // // params.setHost("127.0.0.1");
  28. // // params.setPort(502);
  29. // // params.setEncapsulated(true);
  30. //
  31. // params.setHost("10.1.10.10");
  32. // params.setPort(502);
  33. // params.setEncapsulated(false);
  34. //
  35. // ModbusMaster master = factory.createTcpMaster(params, true);
  36. // // master.setRetries(4);
  37. // master.setTimeout(2000);
  38. // master.setRetries(0);
  39. //
  40. // long start = System.currentTimeMillis();
  41. // try {
  42. // master.init();
  43. // for (int i = 0; i < 100; i++) {
  44. // System.out.println(master.getValue(new NumericLocator(1, RegisterRange.HOLDING_REGISTER, 11,
  45. // DataType.TWO_BYTE_INT_SIGNED)));
  46. // }
  47. // }
  48. // finally {
  49. // master.destroy();
  50. // }
  51. //
  52. // System.out.println("Took: " + (System.currentTimeMillis() - start) + "ms");
  53. // }
  54. // public static void main(String[] args) throws Exception {
  55. // ModbusFactory factory = new ModbusFactory();
  56. // IpParameters params = new IpParameters();
  57. // params.setHost("localhost");
  58. // params.setPort(12345);
  59. // ModbusMaster master = factory.createTcpMaster(params, true, false);
  60. // // master.setRetries(4);
  61. // master.setRetries(0);
  62. // try {
  63. // master.init();
  64. // master.getValue(1, RegisterRange.HOLDING_REGISTER, 0, DataType.TWO_BYTE_INT_UNSIGNED);
  65. // }
  66. // finally {
  67. // master.destroy();
  68. // }
  69. // }
  70. }