use of net.wimpi.modbus.net.ModbusSerialListener in project openhab1-addons by openhab.
the class SerialSlaveTest method main.
public static void main(String[] args) {
ModbusSerialListener listener = null;
SimpleProcessImage spi = new SimpleProcessImage();
String portname = args[0];
if (Modbus.debug) {
System.out.println("jModbus ModbusSerial Slave");
}
try {
// 1. Prepare a process image
spi = new SimpleProcessImage();
spi.addDigitalOut(new SimpleDigitalOut(true));
spi.addDigitalOut(new SimpleDigitalOut(false));
spi.addDigitalIn(new SimpleDigitalIn(false));
spi.addDigitalIn(new SimpleDigitalIn(true));
spi.addDigitalIn(new SimpleDigitalIn(false));
spi.addDigitalIn(new SimpleDigitalIn(true));
spi.addRegister(new SimpleRegister(251));
spi.addInputRegister(new SimpleInputRegister(45));
// 2. Create the coupler and set the slave identity
ModbusCoupler.getReference().setProcessImage(spi);
ModbusCoupler.getReference().setMaster(false);
ModbusCoupler.getReference().setUnitID(2);
// 3. Set up serial parameters
SerialParameters params = new SerialParameters();
params.setPortName(portname);
params.setBaudRate(115200);
params.setDatabits(8);
params.setParity("None");
params.setStopbits(1);
params.setEncoding("ascii");
params.setEcho(false);
params.setReceiveTimeoutMillis(100);
if (Modbus.debug) {
System.out.println("Encoding [" + params.getEncoding() + "]");
}
// 4. Set up serial listener
listener = new ModbusSerialListener(params);
listener.setListening(true);
} catch (Exception ex) {
ex.printStackTrace();
}
}
Aggregations