if (msm.writeCoil(slaveId, 4, true) == true) {
System.out.println("Set output 5 to true");
} else {
System.err.println("Error setting slave " + slaveId + " output 5");
}
BitVector coils = msm.readCoils(slaveId, 0, 8);
if (coils != null) {
System.out.print("Coils:");
for (int i = 0; i < coils.size(); i++) {
System.out.print(" " + i + ": " + coils.getBit(i));
}
System.out.println();
try {
msm.writeMultipleCoils(slaveId, 0, coils);
} catch (ModbusException ex) {
System.out.println("Error writing coils: " + result);
}
} else {
System.out.println("Outputs: null");
msm.disconnect();
System.exit(-1);
}
BitVector digInp = msm.readInputDiscretes(slaveId, 0, 8);
if (digInp != null) {
System.out.print("Digital Inputs:");
for (int i = 0; i < digInp.size(); i++) {
System.out.print(" " + i + ": " + digInp.getBit(i));
}
System.out.println();
System.out.println("Inputs: " + ModbusUtil.toHex(digInp.getBytes()));
} else {
System.out.println("Inputs: null");
msm.disconnect();
System.exit(-1);
}