armadsen / ORSSerialPort

Serial port library for Objective-C and Swift macOS apps
MIT License
751 stars 183 forks source link

[SerialPort] existing port must be the same device #144

Closed KevinVitale closed 5 years ago

KevinVitale commented 5 years ago

Comparing only the path between an existing port and a new port is not enough when considering equality. Doing so causes the ORSSerialPortManager to keep ports with valid paths, but with invalid (terminated) IOKitDevice objects, thus making subsequent calls to IORegistryEntryCreateIterator ineffectual.


Shown below is my own output for this code example to retrieve product and vendor IDs. After being removed at least once, calls to the IORegistryEntryCreateCFProperties function will no longer return any attributes for the port's IOKitDevice, since that object has become invalid (terminated). Yet, KVO changes on availablePorts continue to include the ORSSerialPort port, so long as it is connected to the same path.

Note: I'm defaulting to NSNotFound when ID values return nil.

1 /dev/cu.usbserial-1410 (29987, 6790) 48643
2 /dev/cu.usbserial-1410 (9223372036854775807, 9223372036854775807) 48643

However, when applying this change, IORegistryEntryCreateIterator will work correctly:

1 /dev/cu.usbserial-1410 (29987, 6790) 48643
2 /dev/cu.usbserial-1410 (29987, 6790) 59155

Notice that the io_object_t's numeric value has been changed to the valid (connected) port, and that the product and vendor ID's are now correct. The path hasn't changed.

KevinVitale commented 5 years ago

@armadsen ping (╹◡╹)

armadsen commented 5 years ago

Thanks so much for this, Kevin!