Can I get results of a void function?

Resolved

Hello everyone,

I am trying to use modbus_client_tcp as so:

import 'package:logging/logging.dart';
import 'package:synchronized/synchronized.dart';
import 'package:collection/collection.dart';
import 'package:modbus_client/modbus_client.dart';
import 'package:modbus_client_tcp/modbus_client_tcp.dart';

Future<void> modbusData() async {
  // Simple modbus logging
  ModbusAppLogger(Level.FINE);

  // Create a modbus int16 register element
  var gridVoltage_p1 = ModbusInt16Register(
      name: "GridVoltagePhase1",
      type: ModbusElementType.inputRegister,
      address: 106,
      uom: "V",
      multiplier: 0.1,
      onUpdate: (self) => print(self));

  // Discover the Modbus server
  var serverIp = await ModbusClientTcp.discover("192.168.0.0");
  if (serverIp == null) {
    return ModbusAppLogger.shout("No modbus server found!");
  }

  // Create the modbus client.
  var modbusClient = ModbusClientTcp(serverIp, unitId: 1);

  // Send a read request from the element
  await modbusClient.send(gridVoltage_p1.getReadRequest());

  // Ending here
  modbusClient.disconnect();
}

How can I print the results of this function in the UI?

I've tried to use Action on tap of a button to get the results but as this is void function it does not provide any Action output.

Any ideas how to approach this?

Thanks in advance.

1
2 replies