Closed sm9i closed 3 months 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
@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
os:mac flutter version:
I got more ports in Java,But flutter only read half of it。