jpnurmi / flutter_libserialport

Serial Port for Flutter
https://pub.dev/packages/flutter_libserialport
MIT License
140 stars 80 forks source link

There are ports that cannot be read. #55

Closed sm9i closed 3 months ago

sm9i commented 1 year ago

os:mac flutter version:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.0.4, on macOS 12.4 21F79 darwin-x64, locale zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0-rc1)
[✓] Xcode - develop for iOS and macOS (Xcode 13.4.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2020.3)
[✓] IntelliJ IDEA Ultimate Edition (version 2022.1.2)
[✓] IntelliJ IDEA Community Edition (version 2021.2.2)
[✓] VS Code (version 1.67.2)
[✓] Connected device (2 available)
[✓] HTTP Host Availability

I got more ports in Java,But flutter only read half of it。

sm9i commented 1 year ago

kotlin code and console:

fun getAllDevice() {
    val portList = CommPortIdentifier.getPortIdentifiers()
    while (portList.hasMoreElements()) {
        val device: CommPortIdentifier = portList.nextElement() as CommPortIdentifier
        println("可用端口:${device.name}")
    }
}

console:

可用端口:/dev/tty.BLTH
可用端口:/dev/cu.BLTH
可用端口:/dev/tty.Bluetooth-Incoming-Port
可用端口:/dev/cu.Bluetooth-Incoming-Port
可用端口:/dev/tty.usbserial-14210
可用端口:/dev/cu.usbserial-14210

dart code:

  void initPorts() {
    setState(() => availablePorts = SerialPort.availablePorts);
    availablePorts.forEach((item) {
      print(item);
    });
  }

console:

flutter: /dev/cu.BLTH
flutter: /dev/cu.Bluetooth-Incoming-Port
flutter: /dev/cu.usbserial-14210
lucafabbri commented 3 months ago

@sm9i dev/tty represent the current terminal, I think the answer lays in the way CommPortIdentifier ask the os for the list of devices. In your case in kotlin you have 2 file descriptors for the same resource, while in Flutter only one. The flutter behavior seems to me more clear and safe.

Closed