Go Down

Topic: Controlling Serial port location  (USB) (Read 3932 times) previous topic - next topic

neurascenic

I am curious if there is a way to predetermin what serial port my USB arduino is going to?

I am on Mac osX and on different machines it is choosing to be at different ports.  Forcing me to edit each time I move the arduino.

It seems that on each computer the port is constant.  (though I haven't tried restarting the computer yet)


Conversely, is there a way for the software on the computers side to determine what port it is hooked to?
so that the software can automatically adjust.
I plan on using C.

Thank you

Chris Lund
ñeurascenic

kg4wsv

what is the name of the device special file?  (e.g. /dev/tty.whatever)

The FTDI drivers for Mac OS X use a unique name involving the serial number for FTDI devices that have a serial number (as my arduino does, and I assume they all should).  If the FTDI device does not have a serial number, the driver chooses some semi-random name based on where in the USB "tree" the device gets plugged in.

For example, mine shows up as

/dev/tty.usbserial-A3000WWk

-j

neurascenic

Right!

Ok, so I tested this.  it appears that as long as I plug it into the same port, I get the same value.

So then there is no way to predetermine the port.

How about a way for my program to detect what port it is in?

would searching the dev directory for /dev/tty.*  then parsing anything that contains
".usbserial-"  ?

It appears that .usbserial-   is common to all of the ports.

Thanks for the help!

ñ

kg4wsv

Quote
Ok, so I tested this.  it appears that as long as I plug it into the same port, I get the same value.


Usually.  Using a Keyspan adapter in another application, I had an incident where the name actually changed between reboots (a "1" was prepended for each reboot!).  I do not know if this is a function of the USB enumeration of Mac os X or the Keyspan driver, but it wouldn't surprise me to see it happen with other devices.

Quote
So then there is no way to predetermine the port.


Not exactly.  An FTDI installation guide for Mac os X says:

Quote
If the device is installed properly, you will see entries in the /dev directory:

/dev/cu.usbserial-xxxxxxxx

/dev/tty.usbserial-xxxxxxxx

where xxxxxxxx is either the device's serial number or, for unserialized devices, a location string that depends on which USB port your device is connected to.


So, if the device has a serial number, you get a unique name no matter where you plug it in (or which system, for that matter).  If the device does not have a serial number, you get the behavior that you are seeing.

I got my arduino from SparkFun and it was serialized, so I didn't get the annoying behavior that you are seeing.  I do not know if all USB arduinos are supposed to be serialized, or if just the SparkFun guys do so, or maybe yours slipped through the cracks.

FTDI supplies a utility to program the EEPROM in their devices.  If you are adventurous and have access to a Windows system (unfortunately the utility is windows only, and requires at least win2k IIRC) you can load the FTDI drivers and this app to add a serial number to your device.  I had a different FTDI device (an rs232/USB adapter utilizing the same chip as the arduino) that had no serial number, and I successfully gave it a serial number and it immediately started behaving in the more desireable manner on the mac.

You could play some sort of game like

Code: [Select]
my-mac:~me$ sudo ln -s /dev/tty.usbserial-* /dev/tty.arduino

If you do this on every system, you should be able to just use /dev/tty.arduino all around (unless you get the strange reboot bahavior I referred to earlier).  I have not tested this; YMMV.

Quote
It appears that .usbserial-   is common to all of the ports.


Yep, that's what the manual and my experience both indicate.

-j

mellis

It should only be the Arduino NG's (which use the new FTDI 232RL) that are serialized.

neurascenic

kg,

Thanks for your explanations.  I may consider giving it a serial with the utilities.  I do have an XP box, though I have never turned it on.  Also, I have a couple of linux boxes just waiting to become render farms.

Unfortunately, I am not a unix/linux guy.  So... the little code snippet... does that effectively create a symbolic link to the ports?   What then, if you want multiple arduinos connected?

There has to be a way in your app that interfaces with the arduino, to have a way of detecting what port it is.
Yea, the serial number makes complete sense especially if it is up to the designer what form that serial number takes.

Even still, the arduino environment has the ability to detect a serial port with a board that does not have a SN.

I suppose I could dig through all the source code...  blech!


Thanks again for the insights, they are of great help.

ñ

kg4wsv

Quote
Unfortunately, I am not a unix/linux guy.  So... the little code snippet... does that effectively create a symbolic link to the ports?


that's exactly what it does.

Quote
What then, if you want multiple arduinos connected?


The same idea will work, but you've got to pay a bit more attention, and make sure you always plug board X into USB slot Y to make it work, and there may still be issues relating to which one gets plugged in first (you'd need more than one unserialized FTDI device to check that, and I don't have any).

Quote
There has to be a way in your app that interfaces with the arduino, to have a way of detecting what port it is.


This is a huge problem with using multiple USB/rs232 devices, or using multiple copies of any USB device at the same time.  Many vendors are quite lazy in writing the device drivers, and never even consider that you might use more than one.

Quote
Even still, the arduino environment has the ability to detect a serial port with a board that does not have a SN.


On the Mac, the arduino app shows _all_ devices that can be serial devices; my laptop's modem is even on the list. I suspect it's as simple as doing an "ls /dev/tty.* /dev/cu.*" and listing the results as available devices.

I don't know what USB device is in the arduino you have, but if it's an FTDI chip it may be worth the effort to try and add a serial number to yours.

neurascenic

kg,

Yea I will probably do just that.   I do have an FTDI chip.  I have the board that was just previous to the NG.  I also got it from Sparkfun.   After all, they are just down the road from me.

It just helps me understand to ask all of these questions.



I really do appreciate the help.

Cheers!

ñ

Go Up