martinling / libserialport

Unofficial personal repository for libserialport - see git://sigrok.org/libserialport for official repo
http://sigrok.org/wiki/Libserialport
GNU Lesser General Public License v3.0
65 stars 34 forks source link

Symlink b #41

Open mechsin opened 3 years ago

mechsin commented 3 years ago

I submitted a pull request on the official sigrok repo with this same change but it seems like your repo gets a bit more action. So I though I would post a PR here as well. I am new to this so let me know if there are any issues with what I have done.

I like to add the ability for libserialport to recognize and use symlinks on Linux. This is primarily in support of the Arduino IDE which uses libserialport to enumerate and list serial ports however it seems like it would be beneficial to any libserialport users. Symlinks are created on Linux when udev rules are used to map a specific device or class of devices to a symlink. In order to accommodate this I have added code to find symlinks base on TTY devices found and then I removed a block of code that ensure a real path was passed to the serial port creator and moved this call in the Linux only portion of the code. Based on some research Mac OSX doesn't seem allow for symlink serial ports and there was a guard on the code already to stop it from running on Windows so that leaves BSD which I am unfamiliar with. I am sure BSD allows for symlinks but it doesn't look like it uses the same path searching method to determine port characteristics so I though moving that bit of code would be safe. I have another version of this feature where I added a realpath element to the sp_port struct. This would leave that realpath block in place but assign that real path to the struct there however that seemed more error prone. I was able to get all of the examples to run with my code modifications.

The only other note is that there is two commits here the first adds the code to allow the symlinks to be found. The second moves the realpath code to allow the symlink port names to pass through.