cabbi / modbus_client_tcp

BSD 3-Clause "New" or "Revised" License
5 stars 3 forks source link

onUpdate do not work when other programe changed the value #10

Open KemingRen opened 1 month ago

KemingRen commented 1 month ago

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

cabbi commented 1 month ago

What is the res value of client.send?

KemingRen commented 1 month ago

unit.getReadRequest()

KemingRen commented 1 month ago

You can look at my code above

KemingRen commented 1 month ago

image

cabbi commented 1 month ago

I mean, does sending the request succeed? Can you please enable logs and show them?

KemingRen commented 1 month ago

Yes, This is the passed value that I printed, but it can only be listened to once
image

KemingRen commented 1 week ago

hey, my brother。

cabbi commented 1 week ago

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");