Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

written bytes: 1 then written bytes: 1 #76

Open
uevan2 opened this issue May 15, 2023 · 1 comment
Open

written bytes: 1 then written bytes: 1 #76

uevan2 opened this issue May 15, 2023 · 1 comment

Comments

@uevan2
Copy link

uevan2 commented May 15, 2023

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();
}
`
@mingpepe
Copy link

Did you check return value of openReadWrite?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants