Author Topic: iterating serial ports to identify the target device  (Read 1892 times)

0 Members and 1 Guest are viewing this topic.

Offline faekjarzTopic starter

  • Regular Contributor
  • *
  • Posts: 57
  • Country: de
  • I'm half cat, half platypus, and half pink! :3
iterating serial ports to identify the target device
« on: April 21, 2017, 11:59:35 am »
Hey there, enginerds! ;D

I made this thing a few whiles ago and now i'm fed up of manually starting the thing every time. I want to "daemonize" the driving shell script. I want it to be started automatically on boot. I intend to modify the driver script and create a systemd unit file (which i will publish in the project thread).

In my case there are, at times, multiple serial devices (/dev/tty[USB]?*) connected to the host, and i'd like to pick _that one target device_.

The first approach, i thought of is to iterate every /dev/tty**?? (serial port, on Linux), connect to it, read, and expect a certain reply string, e.g. "OhaiIAmTheTargetDevice" …then pick that serial port.

1) Am i taking a detour, or is it the right direction?
2) Is there an industry standard method for iteratively identifying "ttyserial" devices, i'm not yet aware of?
3) Examples, Experiences, HowTos, Guides, Links… anyone?
« Last Edit: April 21, 2017, 12:20:26 pm by faekjarz »
 

Online Jeroen3

  • Super Contributor
  • ***
  • Posts: 4078
  • Country: nl
  • Embedded Engineer
    • jeroen3.nl
Re: iterating serial ports to identify the target device
« Reply #1 on: April 21, 2017, 12:25:48 pm »
1) No. Be polite and don't send random stuff to devices you don't know. Instead, listen for announcements.
2) Ask for hardware identification of the USB port. PID/VID should already exclude many ports.
Or don't use virtual com/tty, you can write directly to one or multiple usb endpoints.
3) Libusb?
 

Offline BradC

  • Super Contributor
  • ***
  • Posts: 2106
  • Country: au
Re: iterating serial ports to identify the target device
« Reply #2 on: April 21, 2017, 01:44:17 pm »
Here's a good start. This details the old serial plug and play spec and explains how to do it in a manner that most serial devices won't mind or may even be expecting.

http://www.osdever.net/documents/PNP-ExternalSerial-v1.00.pdf
 
The following users thanked this post: Jeroen3, faekjarz

Offline voltsandjolts

  • Supporter
  • ****
  • Posts: 2297
  • Country: gb
Re: iterating serial ports to identify the target device
« Reply #3 on: April 21, 2017, 02:00:51 pm »
If you are not adverse to using FTDI:

1/ Program the FTDI with your chosen serial number.
2/ Install the FTDI D2XX driver.
3/ Use FT_OpenEx() with FT_OPEN_BY_SERIAL_NUMBER

 

Online Monkeh

  • Super Contributor
  • ***
  • Posts: 7992
  • Country: gb
Re: iterating serial ports to identify the target device
« Reply #4 on: April 21, 2017, 02:05:29 pm »
Hey there, enginerds! ;D

I made this thing a few whiles ago and now i'm fed up of manually starting the thing every time. I want to "daemonize" the driving shell script. I want it to be started automatically on boot. I intend to modify the driver script and create a systemd unit file (which i will publish in the project thread).

In my case there are, at times, multiple serial devices (/dev/tty[USB]?*) connected to the host, and i'd like to pick _that one target device_.

The first approach, i thought of is to iterate every /dev/tty**?? (serial port, on Linux), connect to it, read, and expect a certain reply string, e.g. "OhaiIAmTheTargetDevice" …then pick that serial port.

1) Am i taking a detour, or is it the right direction?
2) Is there an industry standard method for iteratively identifying "ttyserial" devices, i'm not yet aware of?
3) Examples, Experiences, HowTos, Guides, Links… anyone?

Use a device with a unique serial number, employ udev to create a symlink. Sorted.
 

Offline faekjarzTopic starter

  • Regular Contributor
  • *
  • Posts: 57
  • Country: de
  • I'm half cat, half platypus, and half pink! :3
Re: iterating serial ports to identify the target device
« Reply #5 on: April 21, 2017, 03:27:39 pm »
Thanks everyone, so far. :-+
Keep the input flowing, if you like.

Now i'm busy reading the PDF @BradC mentioned …I'm on page 9 now "1.2. Device Implementation Considerations" …interesting…

I'd like to mention @honx on twitter, who mentioned a tool for programming a unique serial into a Prolific PL2303 and using udev.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf