| | |
| | | * @throws ModbusTransportException |
| | | * @throws ErrorResponseException |
| | | */ |
| | | public static Boolean readInputStatus(String ip, int port, int offset) throws ModbusInitException, ModbusTransportException, ErrorResponseException { |
| | | public static Boolean readInputStatus(String ip, int port, int offset) throws ModbusInitException, ModbusTransportException, ErrorResponseException, InterruptedException { |
| | | BaseLocator<Boolean> inputStatus = BaseLocator.inputStatus(slaveId, offset); |
| | | |
| | | Thread.sleep(3000); |
| | | Boolean res = getMaster(ip, port).getValue(inputStatus); |
| | | return res; |
| | | } |
| | |
| | | * @throws ModbusTransportException |
| | | * @throws ModbusInitException |
| | | */ |
| | | public static Boolean writeCoilStatus(String ip, int port, int offset, boolean status) throws ModbusTransportException, ModbusInitException { |
| | | boolean coilValue = status; |
| | | WriteCoilRequest coilRequest = new WriteCoilRequest(slaveId, offset, coilValue); |
| | | public static Boolean writeCoilStatus(String ip, int port, int offset, boolean status) throws ModbusTransportException, ModbusInitException, InterruptedException { |
| | | // boolean coilValue = status; |
| | | // WriteCoilRequest coilRequest = new WriteCoilRequest(slaveId, offset, coilValue); |
| | | // WriteCoilResponse coilResponse = (WriteCoilResponse) getMaster(ip, port).send(coilRequest); |
| | | // return !coilResponse.isException(); |
| | | |
| | | WriteCoilRequest coilRequest = new WriteCoilRequest(slaveId, offset, status); |
| | | Thread.sleep(3000); |
| | | WriteCoilResponse coilResponse = (WriteCoilResponse) getMaster(ip, port).send(coilRequest); |
| | | |
| | | //发送清除命令 |
| | | WriteCoilRequest coilRequest1 = new WriteCoilRequest(slaveId, offset, !status); |
| | | getMaster(ip, port).send(coilRequest1); |
| | | |
| | | return !coilResponse.isException(); |
| | | } |
| | | |