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

Example on Ubuntu 22.10 throws errno = 22 #68

Open
Schwusch opened this issue Jan 3, 2023 · 9 comments
Open

Example on Ubuntu 22.10 throws errno = 22 #68

Schwusch opened this issue Jan 3, 2023 · 9 comments
Assignees

Comments

@Schwusch
Copy link

Schwusch commented Jan 3, 2023

Running the example on Ubuntu 22.10 with Flutter 3.7.0-1.2.pre gives this error on startup:

══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY╞═══════════════════════════════════════════════════════════
The following SerialPortError was thrown building Builder(dirty):
Invalid argument, errno = 22

The relevant error-causing widget was:
  Builder
  Builder:file:///home/schwusch/development/flutter_libserialport/example/lib/main.dart:52:17

When the exception was thrown, this was the stack:
#0      Util.call (package:libserialport/src/util.dart:39:7)
#1      Util.toInt (package:libserialport/src/util.dart:77:16)
#2      _SerialPortImpl.busNumber (package:libserialport/src/port.dart:284:17)
#3      _ExampleAppState.build.<anonymous closure>
(package:flutter_libserialport_example/main.dart:59:52)
#4      Builder.build (package:flutter/src/widgets/basic.dart:7448:48)

Running flutter --version:

Flutter 3.7.0-1.2.pre • channel beta • https://github.com/flutter/flutter.git
Framework • revision c29b09b878 (2 weeks ago) • 2022-12-19 18:30:12 -0600
Engine • revision 8c99b0feaf
Tools • Dart 2.19.0 (build 2.19.0-444.2.beta) • DevTools 2.20.0
@Schwusch Schwusch changed the title Example on Ubuntu 22.10 gives errno = 22 Example on Ubuntu 22.10 throws errno = 22 Jan 3, 2023
@Schwusch
Copy link
Author

Schwusch commented Jan 3, 2023

When skimming through old issues, I saw the trick with LIBSERIALPORT_DEBUG=1, and this is the output:

sp: sp_get_port_by_name(/dev/ttyS4, 0x7f48e80c4990) called.
sp: Building structure for port /dev/ttyS4.
sp: get_port_details returning SP_OK.
sp: sp_get_port_by_name returning SP_OK.
sp: sp_get_port_description(0x7f48e847dde0) called.
sp: sp_get_port_description returning ttyS4.
sp: sp_get_port_transport(0x7f48e847dde0) called.
sp: sp_get_port_transport returning 0.
sp: sp_get_port_usb_bus_address(0x7f48e847dde0) called.
sp: sp_get_port_usb_bus_address returning SP_ERR_ARG: Port does not use USB transport.
sp: sp_last_error_message() called.
sp: sp_last_error_message returning Invalid argument.
sp: sp_free_error_message(Invalid argument) called.
sp: sp_free_error_message returning.
sp: sp_last_error_code() called.
sp: sp_last_error_code returning 22.
sp: sp_last_error_message() called.
sp: sp_last_error_message returning Invalid argument.
sp: sp_free_error_message(Invalid argument) called.
sp: sp_free_error_message returning.
sp: sp_last_error_code() called.
sp: sp_last_error_code returning 22.

@mateen-demah
Copy link

@Schwusch did you find a fix or workaround for this error? Facing the problem here.

@Schwusch
Copy link
Author

@mateen-demah I did port the Golang serial library function for getting a more valid list of ports, but abandoned that code in favour of just filtering on vendor/product ID.
I seriously considered porting all of Golangs serial library in order to have a pure Dart implementation (no libserialport dependency).
Maybe at some point in the future.

@mateen-demah
Copy link

@mateen-demah I did port the Golang serial library function for getting a more valid list of ports, but abandoned that code in favour of just filtering on vendor/product ID. I seriously considered porting all of Golangs serial library in order to have a pure Dart implementation (no libserialport dependency). Maybe at some point in the future.

@Schwusch how did you do that? From the example app, you'd have create a SerialPort object to get access to the vendor/product ID. And the error occurs at the point of SerialPort object creation.

@Schwusch
Copy link
Author

My use case was to present the user with a list of available ports to choose from, and that is possible without instantiating a SerialPort object, by enumerating the files in the /dev directory like they do it in go-serial.
After that, you can instantiate the object with the chosen name SerialPort(name);.
Also, it is a good idea to wrap the instantiation with a try-catch :)

@Schwusch
Copy link
Author

Also, you can read the vid/pid from the file system

@mateen-demah
Copy link

Thanks @Schwusch I'll try that out. In my case, I don't just want to present the ports so I really need that object.

@mingpepe
Copy link

When skimming through old issues, I saw the trick with LIBSERIALPORT_DEBUG=1, and this is the output:

sp: sp_get_port_by_name(/dev/ttyS4, 0x7f48e80c4990) called.
sp: Building structure for port /dev/ttyS4.
sp: get_port_details returning SP_OK.
sp: sp_get_port_by_name returning SP_OK.
sp: sp_get_port_description(0x7f48e847dde0) called.
sp: sp_get_port_description returning ttyS4.
sp: sp_get_port_transport(0x7f48e847dde0) called.
sp: sp_get_port_transport returning 0.
sp: sp_get_port_usb_bus_address(0x7f48e847dde0) called.
sp: sp_get_port_usb_bus_address returning SP_ERR_ARG: Port does not use USB transport.
sp: sp_last_error_message() called.
sp: sp_last_error_message returning Invalid argument.
sp: sp_free_error_message(Invalid argument) called.
sp: sp_free_error_message returning.
sp: sp_last_error_code() called.
sp: sp_last_error_code returning 22.
sp: sp_last_error_message() called.
sp: sp_last_error_message returning Invalid argument.
sp: sp_free_error_message(Invalid argument) called.
sp: sp_free_error_message returning.
sp: sp_last_error_code() called.
sp: sp_last_error_code returning 22.

Seems like your serial port is not USB type, hence no bus number can be provided.
Possible throw an exception from here, then trace code can find that the library just complain about it's type when getting bus number.
https://github.com/jpnurmi/libserialport.dart/blob/main/lib/src/port.dart#L285
https://github.com/martinling/libserialport/blob/master/serialport.c#L172

@mateen-demah
Copy link

Thanks @mingpepe . For my usecase I'm only interested in USB devices so I put a try block around the port creation code and just skipped when something went wrong. Worked like a charm; all the USB devices showed up.

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

No branches or pull requests

4 participants