Test3.java 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. Copyright (C) 2006-2007 Serotonin Software Technologies Inc.
  3. @author Matthew Lohbihler
  4. */
  5. package com.serotonin.modbus4j.test;
  6. import com.serotonin.modbus4j.ModbusFactory;
  7. import com.serotonin.modbus4j.ModbusMaster;
  8. import com.serotonin.modbus4j.code.DataType;
  9. import com.serotonin.modbus4j.locator.BaseLocator;
  10. /**
  11. * @author Matthew Lohbihler
  12. */
  13. public class Test3 {
  14. public static void main(String[] args) throws Exception {
  15. String commPortId = "COM1";
  16. int baudRate = 9600;
  17. int flowControlIn = 0;
  18. int flowControlOut = 0;
  19. int dataBits = 8;
  20. int stopBits = 2;
  21. int parity = 0;
  22. TestSerialPortWrapper wrapper = new TestSerialPortWrapper(commPortId, baudRate, flowControlIn, flowControlOut, dataBits, stopBits, parity);
  23. ModbusMaster master = new ModbusFactory().createRtuMaster(wrapper);
  24. master.init();
  25. System.out.println(master.testSlaveNode(5));
  26. // Define the point locator.
  27. BaseLocator<Number> loc = BaseLocator.holdingRegister(1, 0, DataType.TWO_BYTE_INT_UNSIGNED);
  28. // Set the point value
  29. master.setValue(loc, 1800);
  30. // Get the point value
  31. System.out.println(master.getValue(loc));
  32. }
  33. }