Open KemingRen opened 1 month ago
What is the res
value of client.send
?
unit.getReadRequest()
You can look at my code above
I mean, does sending the request succeed? Can you please enable logs and show them?
Yes, This is the passed value that I printed, but it can only be listened to once
hey, my brother。
Hi, I've asked you to enable logs and show them, but I still do not see them, Please add this line of code at beginning of your program and debug it on your PC so you will see the Modbus debug logs.
// Simple modbus logging
ModbusAppLogger(Level.FINE);
I've also asked you if sending the request succeeds and I'm still waiting this as well:
final res = await client.send(unit.getReadRequest());
print("request result: $res");
Future<int?> listenIntValue( int address, String key, ValueChanged<double?> onData) async { final client = await MBUtils.getClient(); if (client == null) { return null; } var unit = ModbusInt16Register( name: key, type: ModbusElementType.holdingRegister, address: address, onUpdate: (self) { onData(self.value); }, ); final res = await client.send(unit.getReadRequest()); if (res == ModbusResponseCode.requestSucceed) { print(unit.value); } return unit.value as int; } listenIntValue(100, "value", (v) { print("vvvv:$v"); });
There is a modbus device that controlled by other soft, I need watch one modbus address value,but when the value changed,the onUpdate function do not excute