|
@@ -295,10 +295,11 @@ public class ModbusTcpServer { |
|
|
try { |
|
|
try { |
|
|
ReadHoldingRegistersResponse res = ModbusTcpHelper.get().syncReadHoldingRegisters(1, add, length); |
|
|
ReadHoldingRegistersResponse res = ModbusTcpHelper.get().syncReadHoldingRegisters(1, add, length); |
|
|
byte[] data = res.getData(); |
|
|
byte[] data = res.getData(); |
|
|
|
|
|
|
|
|
|
|
|
byte[] data1= Arrays.copyOfRange(data, 0, 36); |
|
|
|
|
|
//36 GUID 18 Number |
|
|
String id=""; |
|
|
String id=""; |
|
|
try { |
|
|
try { |
|
|
id = new String(data, "UTF-8"); |
|
|
|
|
|
|
|
|
id = new String(data1, "UTF-8").trim(); |
|
|
} catch (UnsupportedEncodingException ex) { |
|
|
} catch (UnsupportedEncodingException ex) { |
|
|
} |
|
|
} |
|
|
if(callback!=null) callback.onSuccess(id); |
|
|
if(callback!=null) callback.onSuccess(id); |
|
@@ -314,6 +315,36 @@ public class ModbusTcpServer { |
|
|
MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); |
|
|
MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void WriteString(String Address, int length, IWriteCallBack callback) { |
|
|
|
|
|
int add = GetAddress(Address); |
|
|
|
|
|
if (add < 0) return; |
|
|
|
|
|
short[] send = new short[length]; |
|
|
|
|
|
for (short item:send) |
|
|
|
|
|
{ |
|
|
|
|
|
item=0; |
|
|
|
|
|
} |
|
|
|
|
|
try { |
|
|
|
|
|
ModbusTcpHelper.get().syncWriteRegisters(1, add, send); |
|
|
|
|
|
if(callback!=null) |
|
|
|
|
|
callback.onSuccess(); |
|
|
|
|
|
} catch (InterruptedException e) { |
|
|
|
|
|
MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); |
|
|
|
|
|
if(callback!=null)callback.onFailure(e.toString()); |
|
|
|
|
|
} catch (ExecutionException e) { |
|
|
|
|
|
MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); |
|
|
|
|
|
if(callback!=null)callback.onFailure(e.toString()); |
|
|
|
|
|
} catch (ModbusTransportException e) { |
|
|
|
|
|
MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); |
|
|
|
|
|
if(callback!=null)callback.onFailure(e.toString()); |
|
|
|
|
|
} catch (ModbusInitException e) { |
|
|
|
|
|
MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); |
|
|
|
|
|
if(callback!=null)callback.onFailure(e.toString()); |
|
|
|
|
|
} catch (ModbusRespException e) { |
|
|
|
|
|
MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); |
|
|
|
|
|
if(callback!=null)callback.onFailure(e.toString()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
public void ReadShort(String Address, int length, IReadCallBack<short[]> callback) { |
|
|
public void ReadShort(String Address, int length, IReadCallBack<short[]> callback) { |
|
|
int add = GetAddress(Address); |
|
|
int add = GetAddress(Address); |
|
|
if (add < 0) return; |
|
|
if (add < 0) return; |
|
|