http://opalkelly.com/

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

0 Members and 1 Guest are viewing this topic.

Offline faekjarz

  • Contributor
  • Posts: 40
  • Country: de
  • I'm half cat, half platypus, and half pink! :3
iterating serial ports to identify the target device
« on: April 21, 2017, 09:59:35 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?
« Last Edit: April 21, 2017, 10:20:26 PM by faekjarz »
 

Offline Jeroen3

  • Super Contributor
  • ***
  • Posts: 2256
  • Country: nl
  • Embedded Engineer
    • jeroen3.nl
Re: iterating serial ports to identify the target device
« Reply #1 on: April 21, 2017, 10: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

  • Frequent Contributor
  • **
  • Posts: 912
  • Country: au
Re: iterating serial ports to identify the target device
« Reply #2 on: April 21, 2017, 11: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: 338
  • Country: gb
Re: iterating serial ports to identify the target device
« Reply #3 on: April 22, 2017, 12:00:51 AM »
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

 

Offline Monkeh

  • Super Contributor
  • ***
  • Posts: 4913
  • Country: gb
Re: iterating serial ports to identify the target device
« Reply #4 on: April 22, 2017, 12:05:29 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?

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

Offline faekjarz

  • Contributor
  • Posts: 40
  • 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 22, 2017, 01:27:39 AM »
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