|
|
@@ -287,4 +287,71 @@ public class ModbusTcpServer { |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
public void WriteShort(String Address, short Value) { |
|
|
|
int add = GetAddress(Address); |
|
|
|
if (add < 0) return; |
|
|
|
short[] send = new short[1]; |
|
|
|
send[0] = Value; |
|
|
|
ModbusTcpHelper.get().writeRegisters(1, add, send, new ModbusCallback<WriteRegistersResponse>() { |
|
|
|
@Override |
|
|
|
public void onSuccess(WriteRegistersResponse writeRegistersResponse) { |
|
|
|
MessageLog.ShowInfo("WriteShort onSuccess,Address=" + Address + ",Value=" + Value); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onFailure(Throwable tr) { |
|
|
|
MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",Value=" + Value + ",msg:" + tr.toString()); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onFinally() { |
|
|
|
|
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
public void WriteBool(String Address, boolean Value) { |
|
|
|
int add = GetAddress(Address); |
|
|
|
if (add < 0) return; |
|
|
|
ModbusTcpHelper.get().writeCoil(1, add, Value, new ModbusCallback<WriteCoilResponse>() { |
|
|
|
@Override |
|
|
|
public void onSuccess(WriteCoilResponse writeCoilResponse) { |
|
|
|
MessageLog.ShowInfo("WriteBool onSuccess,Address=" + Address + ",Value=" + Value); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onFailure(Throwable tr) { |
|
|
|
MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",Value=" + Value + ",msg:" + tr.toString()); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onFinally() { |
|
|
|
|
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
public void WriteFloat(String Address, float Value) { |
|
|
|
int add = GetAddress(Address); |
|
|
|
if (add < 0) return; |
|
|
|
int intBits = Float.floatToRawIntBits(Value); |
|
|
|
short[] send = new short[]{(short) ((intBits >> 16) & 0xffff), (short) (intBits & 0xffff)}; |
|
|
|
ModbusTcpHelper.get().writeRegisters(1, add, send, new ModbusCallback<WriteRegistersResponse>() { |
|
|
|
@Override |
|
|
|
public void onSuccess(WriteRegistersResponse writeRegistersResponse) { |
|
|
|
MessageLog.ShowInfo("WriteFloat onSuccess,Address=" + Address + ",Value=" + Value); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onFailure(Throwable tr) { |
|
|
|
MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",Value=" + Value + ",msg:" + tr.toString()); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onFinally() { |
|
|
|
|
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
} |