Closed hasanuc20 closed 8 months ago
This is an example for reading bit/bool values
import 'package:logging/logging.dart';
import 'package:modbus_client/modbus_client.dart';
import 'package:modbus_client_tcp/modbus_client_tcp.dart';
void main() async {
// Simple modbus logging
ModbusAppLogger(Level.FINE);
// Create a modbus int16 register element
var bitValue = ModbusCoil(name: "My Bit", address: 1);
// Create the modbus client.
var modbusClient = ModbusClientTcp("127.0.0.1", unitId: 1);
// Send a read request from the element
await modbusClient.send(bitValue.getReadRequest());
print(bitValue.value);
// Ending here
modbusClient.disconnect();
}
Looking to the implementation I see I forgot to add the "onUpdate" parameter to Coil and Descrete Input register. I will do a new package release to handle it. With that new release the code can look like this:
// Create a modbus int16 register element
var bitValue =
ModbusCoil(name: "My Bit", address: 1, onUpdate: (self) => print(self));
Please close the issue if the example fits your requirements, thanks
New modbus_client 1.0.4 is available
Thank you.
Hello, how can I read the data of the coil or data? I want to read bool variable data with address 1, but I couldn't.