use of net.wimpi.modbus.procimg.SimpleProcessImage in project openhab1-addons by openhab.
the class TestCaseSupport method startServer.
private void startServer() throws UnknownHostException, InterruptedException {
spi = new SimpleProcessImage();
ModbusCoupler.getReference().setProcessImage(spi);
ModbusCoupler.getReference().setMaster(false);
ModbusCoupler.getReference().setUnitID(SLAVE_UNIT_ID);
if (ServerType.TCP.equals(serverType)) {
startTCPServer();
} else if (ServerType.UDP.equals(serverType)) {
startUDPServer();
} else if (ServerType.SERIAL.equals(serverType)) {
startSerialServer();
} else {
throw new NotImplementedException();
}
}
use of net.wimpi.modbus.procimg.SimpleProcessImage 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();
}
}
use of net.wimpi.modbus.procimg.SimpleProcessImage in project openhab1-addons by openhab.
the class TCPSlaveTest method main.
public static void main(String[] args) {
ModbusTCPListener listener = null;
SimpleProcessImage spi = null;
int port = Modbus.DEFAULT_PORT;
try {
if (args != null && args.length == 1) {
port = Integer.parseInt(args[0]);
}
System.out.println("jModbus Modbus Slave (Server)");
// 1. prepare a process image
spi = new SimpleProcessImage();
spi.addDigitalOut(new SimpleDigitalOut(true));
spi.addDigitalOut(new SimpleDigitalOut(true));
spi.addDigitalIn(new SimpleDigitalIn(false));
spi.addDigitalIn(new SimpleDigitalIn(true));
spi.addDigitalIn(new SimpleDigitalIn(false));
spi.addDigitalIn(new SimpleDigitalIn(true));
// allow checking LSB/MSB order
spi.addDigitalIn(new SimpleDigitalIn(true));
spi.addDigitalIn(new SimpleDigitalIn(true));
spi.addDigitalIn(new SimpleDigitalIn(true));
spi.addDigitalIn(new SimpleDigitalIn(true));
spi.addRegister(new SimpleRegister(251));
spi.addInputRegister(new SimpleInputRegister(45));
// 2. create the coupler holding the image
ModbusCoupler.getReference().setProcessImage(spi);
ModbusCoupler.getReference().setMaster(false);
ModbusCoupler.getReference().setUnitID(15);
// 3. create a listener with 3 threads in pool
if (Modbus.debug) {
System.out.println("Listening...");
}
listener = new ModbusTCPListener(3);
listener.setPort(port);
listener.start();
} catch (Exception ex) {
ex.printStackTrace();
}
}
use of net.wimpi.modbus.procimg.SimpleProcessImage in project openhab1-addons by openhab.
the class UDPSlaveTest method main.
public static void main(String[] args) {
ModbusUDPListener listener = null;
SimpleProcessImage spi = null;
int port = Modbus.DEFAULT_PORT;
try {
if (args != null && args.length == 1) {
port = Integer.parseInt(args[0]);
}
System.out.println("jModbus Modbus/UDP Slave v0.1");
// 1. Prepare a process image
spi = new SimpleProcessImage();
spi.addDigitalOut(new SimpleDigitalOut(true));
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));
ModbusCoupler.getReference().setProcessImage(spi);
ModbusCoupler.getReference().setMaster(false);
ModbusCoupler.getReference().setUnitID(15);
// 2. Setup and start listener
listener = new ModbusUDPListener();
listener.setPort(port);
listener.start();
} catch (Exception ex) {
ex.printStackTrace();
}
}
Aggregations