|
|
@@ -55,7 +55,7 @@ public class Wok2ModbusTcpServer { |
|
|
|
|
|
|
|
public void DisConnect(){ |
|
|
|
plcIsConnect = false; |
|
|
|
WokModbusTcpHelper.get().release(); |
|
|
|
Wok2ModbusTcpHelper.get().release(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@@ -107,7 +107,7 @@ public class Wok2ModbusTcpServer { |
|
|
|
.setRetries(0) |
|
|
|
.setEncapsulated(false) |
|
|
|
.setKeepAlive(true); |
|
|
|
WokModbusTcpHelper.get().init(param, new ModbusCallback<ModbusMaster>() { |
|
|
|
Wok2ModbusTcpHelper.get().init(param, new ModbusCallback<ModbusMaster>() { |
|
|
|
@Override |
|
|
|
public void onSuccess(ModbusMaster modbusMaster) { |
|
|
|
MessageLog.ShowInfo("炒锅设备 " + ModbusCenter.wokAddress + " 连接成功"); |
|
|
@@ -316,7 +316,7 @@ public class Wok2ModbusTcpServer { |
|
|
|
int add = GetAddress(Address); |
|
|
|
if (add < 0) return; |
|
|
|
try { |
|
|
|
ReadHoldingRegistersResponse res = WokModbusTcpHelper.get().syncReadHoldingRegisters(1, add, length); |
|
|
|
ReadHoldingRegistersResponse res = Wok2ModbusTcpHelper.get().syncReadHoldingRegisters(1, add, length); |
|
|
|
byte[] data = res.getData(); |
|
|
|
byte[] tempData = new byte[6]; |
|
|
|
tempData[0] = data[1]; |
|
|
@@ -334,7 +334,7 @@ public class Wok2ModbusTcpServer { |
|
|
|
int add = GetAddress(Address); |
|
|
|
if (add < 0) return; |
|
|
|
try { |
|
|
|
ReadHoldingRegistersResponse res = WokModbusTcpHelper.get().syncReadHoldingRegisters(1, add, length); |
|
|
|
ReadHoldingRegistersResponse res = Wok2ModbusTcpHelper.get().syncReadHoldingRegisters(1, add, length); |
|
|
|
short[] data = res.getShortData(); |
|
|
|
if (data.length == length) { |
|
|
|
if (callback != null) callback.onSuccess(data); |
|
|
@@ -351,7 +351,7 @@ public class Wok2ModbusTcpServer { |
|
|
|
int add = GetAddress(Address); |
|
|
|
if (add < 0) return; |
|
|
|
try { |
|
|
|
ReadCoilsResponse res = WokModbusTcpHelper.get().syncReadCoil(1, add, length); |
|
|
|
ReadCoilsResponse res = Wok2ModbusTcpHelper.get().syncReadCoil(1, add, length); |
|
|
|
boolean[] data = res.getBooleanData(); |
|
|
|
boolean[] result = Arrays.copyOfRange(data, 0, length); |
|
|
|
if (result.length == length) { |
|
|
@@ -369,7 +369,7 @@ public class Wok2ModbusTcpServer { |
|
|
|
int add = GetAddress(Address); |
|
|
|
if (add < 0) return; |
|
|
|
try { |
|
|
|
ReadHoldingRegistersResponse res = WokModbusTcpHelper.get().syncReadHoldingRegisters(1, add, length*2); |
|
|
|
ReadHoldingRegistersResponse res = Wok2ModbusTcpHelper.get().syncReadHoldingRegisters(1, add, length*2); |
|
|
|
byte[] data = res.getData(); |
|
|
|
float[] tempValues = new float[length]; |
|
|
|
for (int i = 0; i < length; i++) { |
|
|
@@ -394,7 +394,7 @@ public class Wok2ModbusTcpServer { |
|
|
|
int add = GetAddress(Address); |
|
|
|
if (add < 0) return; |
|
|
|
try { |
|
|
|
ReadHoldingRegistersResponse res = WokModbusTcpHelper.get().syncReadHoldingRegisters(1, add, length * 2); |
|
|
|
ReadHoldingRegistersResponse res = Wok2ModbusTcpHelper.get().syncReadHoldingRegisters(1, add, length * 2); |
|
|
|
byte[] data = res.getData(); |
|
|
|
int[] tempValues = new int[length]; |
|
|
|
if(data.length>=4) |
|
|
@@ -430,7 +430,7 @@ public class Wok2ModbusTcpServer { |
|
|
|
short[] send = new short[1]; |
|
|
|
send[0] = Value; |
|
|
|
try { |
|
|
|
WokModbusTcpHelper.get().syncWriteRegisters(1, add, send); |
|
|
|
Wok2ModbusTcpHelper.get().syncWriteRegisters(1, add, send); |
|
|
|
if (callback != null) |
|
|
|
callback.onSuccess(); |
|
|
|
} catch (InterruptedException | ExecutionException | ModbusTransportException | |
|
|
@@ -444,7 +444,7 @@ public class Wok2ModbusTcpServer { |
|
|
|
int add = GetAddress(Address); |
|
|
|
if (add < 0) return; |
|
|
|
try { |
|
|
|
WokModbusTcpHelper.get().syncWriteCoil(1, add, Value); |
|
|
|
Wok2ModbusTcpHelper.get().syncWriteCoil(1, add, Value); |
|
|
|
if (callback != null) |
|
|
|
callback.onSuccess(); |
|
|
|
} catch (InterruptedException | ExecutionException | ModbusTransportException | |
|
|
@@ -462,7 +462,7 @@ public class Wok2ModbusTcpServer { |
|
|
|
short[] send = IntToShorts(intBits); |
|
|
|
// short[] send = new short[]{(short) ((intBits >> 16) & 0xffff), (short) (intBits & 0xffff)}; |
|
|
|
try { |
|
|
|
WokModbusTcpHelper.get().syncWriteRegisters(1, add, send); |
|
|
|
Wok2ModbusTcpHelper.get().syncWriteRegisters(1, add, send); |
|
|
|
|
|
|
|
if (callback != null) callback.onSuccess(); |
|
|
|
} catch (InterruptedException | ExecutionException | ModbusTransportException | |
|
|
@@ -477,7 +477,7 @@ public class Wok2ModbusTcpServer { |
|
|
|
if (add < 0) return; |
|
|
|
short[] send = IntToShorts(Value); |
|
|
|
try { |
|
|
|
WokModbusTcpHelper.get().syncWriteRegisters(1, add, send); |
|
|
|
Wok2ModbusTcpHelper.get().syncWriteRegisters(1, add, send); |
|
|
|
if (callback != null) callback.onSuccess(); |
|
|
|
} catch (InterruptedException | ExecutionException | ModbusTransportException | |
|
|
|
ModbusInitException | ModbusRespException e) { |
|
|
|