|
@@ -88,67 +88,66 @@ public class ModbusTcpWeigherClient {
|
|
return modbusMasterUtil.readHoldingRegister(1, 3, DATA_TYPE_WRAPPER.TWO_BYTE_INT_UNSIGNED).intValue();
|
|
return modbusMasterUtil.readHoldingRegister(1, 3, DATA_TYPE_WRAPPER.TWO_BYTE_INT_UNSIGNED).intValue();
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * 道闸是否开门到位
|
|
|
|
- *
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- public Boolean readGateOpenState() {
|
|
|
|
- ModbusMasterUtil modbusMasterUtil = modbusTcpMasterTemplateFirst.getModbusMasterUtil();
|
|
|
|
- short i = read(modbusMasterUtil,1, 4, 1);
|
|
|
|
- return i == 1;
|
|
|
|
- }
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 道闸是否关门到位
|
|
|
|
- *
|
|
|
|
- * @return
|
|
|
|
|
|
+ * 清除开门状态
|
|
*/
|
|
*/
|
|
- public Boolean readGateCloseState() {
|
|
|
|
- ModbusMasterUtil modbusMasterUtil = modbusTcpMasterTemplateFirst.getModbusMasterUtil();
|
|
|
|
- short i = read(modbusMasterUtil,1, 5, 1);
|
|
|
|
- return i == 1;
|
|
|
|
|
|
+ public Boolean clearOpenStaate() {
|
|
|
|
+ Number number = read1(1, 4);
|
|
|
|
+ boolean[] booleans = ConvertUtil.convertToBooleans(number);
|
|
|
|
+ booleans[15] = false;
|
|
|
|
+ int i = ConvertUtil.convertToInt(booleans);
|
|
|
|
+ return write(1, 7, i);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 清除开门状态
|
|
|
|
|
|
+ * 清除关门状态
|
|
*/
|
|
*/
|
|
- public Boolean clearOpenStaate() {
|
|
|
|
- ModbusMasterUtil modbusMasterUtil = modbusTcpMasterTemplateFirst.getModbusMasterUtil();
|
|
|
|
- return write(modbusMasterUtil,1, 7, 0);
|
|
|
|
|
|
+ public Boolean clearCloseState() {
|
|
|
|
+ Number number = read1(1, 5);
|
|
|
|
+ boolean[] booleans = ConvertUtil.convertToBooleans(number);
|
|
|
|
+ booleans[15] = false;
|
|
|
|
+ int i = ConvertUtil.convertToInt(booleans);
|
|
|
|
+ return write(1, 6, i);
|
|
}
|
|
}
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 道闸开门
|
|
* 道闸开门
|
|
*/
|
|
*/
|
|
public Boolean writeGateOpen() {
|
|
public Boolean writeGateOpen() {
|
|
- ModbusMasterUtil modbusMasterUtil = modbusTcpMasterTemplateFirst.getModbusMasterUtil();
|
|
|
|
- return write(modbusMasterUtil,1, 7, 1);
|
|
|
|
|
|
+ Number number = read1(1, 4);
|
|
|
|
+ boolean[] booleans = ConvertUtil.convertToBooleans(number);
|
|
|
|
+ booleans[15] = true;
|
|
|
|
+ int i = ConvertUtil.convertToInt(booleans);
|
|
|
|
+ return write(1, 7, i);
|
|
}
|
|
}
|
|
-
|
|
|
|
/**
|
|
/**
|
|
- * 清除关门状态
|
|
|
|
|
|
+ * 道闸关门
|
|
*/
|
|
*/
|
|
- public Boolean clearCloseState() {
|
|
|
|
- ModbusMasterUtil modbusMasterUtil = modbusTcpMasterTemplateFirst.getModbusMasterUtil();
|
|
|
|
- return write(modbusMasterUtil,1, 6, 0);
|
|
|
|
|
|
+ public Boolean writeGateClose() {
|
|
|
|
+ Number number = read1(1, 5);
|
|
|
|
+ boolean[] booleans = ConvertUtil.convertToBooleans(number);
|
|
|
|
+ booleans[15] = true;
|
|
|
|
+ int i = ConvertUtil.convertToInt(booleans);
|
|
|
|
+ return write(1, 6, i);
|
|
}
|
|
}
|
|
|
|
+
|
|
/**
|
|
/**
|
|
- * 道闸关门
|
|
|
|
|
|
+ * 获取道闸门状态
|
|
*/
|
|
*/
|
|
- public Boolean writeGateClose() {
|
|
|
|
|
|
+ public int redGateState(int offset) {
|
|
ModbusMasterUtil modbusMasterUtil = modbusTcpMasterTemplateFirst.getModbusMasterUtil();
|
|
ModbusMasterUtil modbusMasterUtil = modbusTcpMasterTemplateFirst.getModbusMasterUtil();
|
|
- return write(modbusMasterUtil,1, 6, 1);
|
|
|
|
|
|
+ return modbusMasterUtil.readHoldingRegister(1, offset, DATA_TYPE_WRAPPER.TWO_BYTE_INT_UNSIGNED).intValue();
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
- private short read(ModbusMasterUtil modbusMasterUtil,int slaveId, int offset, int len) {
|
|
|
|
- ReadResponse readResponse = modbusMasterUtil.readHoldingRegisters(slaveId, offset, len);
|
|
|
|
- short[] shortData = readResponse.getShortData();
|
|
|
|
- return shortData[0];
|
|
|
|
|
|
+ private Number read1(int slaveId, int offset) {
|
|
|
|
+ ModbusMasterUtil modbusMasterUtil = modbusTcpMasterTemplateFirst.getModbusMasterUtil();
|
|
|
|
+ Number number = modbusMasterUtil.readHoldingRegister(slaveId, offset, DATA_TYPE_WRAPPER.TWO_BYTE_INT_UNSIGNED);
|
|
|
|
+ return number;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
- private Boolean write(ModbusMasterUtil modbusMasterUtil,int slaveId, int offset, int value) {
|
|
|
|
|
|
+ private Boolean write(int slaveId, int offset, int value) {
|
|
|
|
+ ModbusMasterUtil modbusMasterUtil = modbusTcpMasterTemplateFirst.getModbusMasterUtil();
|
|
return modbusMasterUtil.writeHoldingRegisters(slaveId, offset, value);
|
|
return modbusMasterUtil.writeHoldingRegisters(slaveId, offset, value);
|
|
}
|
|
}
|
|
}
|
|
}
|