Open uevan2 opened 1 year ago
I am getting this issue when running the following code:
flutter: Available Ports: [COM3, COM6] flutter: written bytes: -1
(It sometimes states that written bytes is 1 at the start but then upon a hot restart it prints -1)
`import 'dart:convert'; import 'dart:typed_data'; import 'package:flutter/material.dart'; // import 'package:flutter_libserialport/flutter_libserialport.dart'; import 'package:libserialport/libserialport.dart'; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { List<String> availablePort = SerialPort.availablePorts; print('Available Ports: $availablePort'); SerialPort port4 = SerialPort('COM6'); port4.openReadWrite(); try { print('written bytes: ${port4.write(_stringToUint8List("Hello"))}'); } on SerialPortError catch (err, _) { print(SerialPort.lastError); port4.close(); } return Container(); } } Uint8List _stringToUint8List(String s) { List<int> codeUnits = s.codeUnits; Uint8List uint8list = Uint8List.fromList(codeUnits); return uint8list; } class SerialPortExample extends StatefulWidget { @override _SerialPortExampleState createState() => _SerialPortExampleState(); } `
Did you check return value of openReadWrite?
openReadWrite
I am getting this issue when running the following code:
(It sometimes states that written bytes is 1 at the start but then upon a hot restart it prints -1)