MaxRegisterTest.java 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package com.serotonin.modbus4j.test;
  2. import com.serotonin.modbus4j.BatchRead;
  3. import com.serotonin.modbus4j.ModbusFactory;
  4. import com.serotonin.modbus4j.ModbusMaster;
  5. import com.serotonin.modbus4j.code.DataType;
  6. import com.serotonin.modbus4j.code.RegisterRange;
  7. import com.serotonin.modbus4j.locator.StringLocator;
  8. public class MaxRegisterTest {
  9. public static void main(String[] args) {
  10. BatchRead<Integer> batch;
  11. int index;
  12. boolean contiguous = true;
  13. ModbusMaster master = new ModbusFactory().createUdpMaster(null);
  14. master.setMaxReadBitCount(100);
  15. master.setMaxReadRegisterCount(11);
  16. batch = new BatchRead<Integer>();
  17. index = 0;
  18. batch.addLocator(index++, new StringLocator(1, RegisterRange.HOLDING_REGISTER, 0, DataType.CHAR, 50));
  19. batch.addLocator(index++, new StringLocator(1, RegisterRange.HOLDING_REGISTER, 50, DataType.CHAR, 50));
  20. batch.addLocator(index++, new StringLocator(1, RegisterRange.HOLDING_REGISTER, 100, DataType.CHAR, 50));
  21. batch.addLocator(index++, new StringLocator(1, RegisterRange.HOLDING_REGISTER, 150, DataType.CHAR, 50));
  22. batch.addLocator(index++, new StringLocator(1, RegisterRange.HOLDING_REGISTER, 200, DataType.CHAR, 50));
  23. batch.addLocator(index++, new StringLocator(1, RegisterRange.HOLDING_REGISTER, 250, DataType.CHAR, 50));
  24. batch.setContiguousRequests(contiguous);
  25. batch.getReadFunctionGroups(master);
  26. batch = new BatchRead<Integer>();
  27. index = 0;
  28. batch.addLocator(index++, new StringLocator(1, RegisterRange.HOLDING_REGISTER, 0, DataType.CHAR, 49));
  29. batch.addLocator(index++, new StringLocator(1, RegisterRange.HOLDING_REGISTER, 50, DataType.CHAR, 50));
  30. batch.addLocator(index++, new StringLocator(1, RegisterRange.HOLDING_REGISTER, 100, DataType.CHAR, 50));
  31. batch.addLocator(index++, new StringLocator(1, RegisterRange.HOLDING_REGISTER, 150, DataType.CHAR, 50));
  32. batch.addLocator(index++, new StringLocator(1, RegisterRange.HOLDING_REGISTER, 200, DataType.CHAR, 49));
  33. batch.addLocator(index++, new StringLocator(1, RegisterRange.HOLDING_REGISTER, 250, DataType.CHAR, 50));
  34. batch.setContiguousRequests(contiguous);
  35. batch.getReadFunctionGroups(master);
  36. batch = new BatchRead<Integer>();
  37. index = 0;
  38. batch.addLocator(index++, new StringLocator(1, RegisterRange.HOLDING_REGISTER, 0, DataType.CHAR, 50));
  39. batch.addLocator(index++, new StringLocator(1, RegisterRange.HOLDING_REGISTER, 50, DataType.CHAR, 50));
  40. batch.addLocator(index++, new StringLocator(1, RegisterRange.HOLDING_REGISTER, 100, DataType.CHAR, 50));
  41. batch.addLocator(index++, new StringLocator(1, RegisterRange.HOLDING_REGISTER, 100, DataType.CHAR, 25));
  42. batch.addLocator(index++, new StringLocator(1, RegisterRange.HOLDING_REGISTER, 150, DataType.CHAR, 50));
  43. batch.addLocator(index++, new StringLocator(1, RegisterRange.HOLDING_REGISTER, 200, DataType.CHAR, 50));
  44. batch.addLocator(index++, new StringLocator(1, RegisterRange.HOLDING_REGISTER, 250, DataType.CHAR, 50));
  45. batch.setContiguousRequests(contiguous);
  46. batch.getReadFunctionGroups(master);
  47. }
  48. }