You are not logged in.

#1 2016-06-30 10:59:40

Payal
Member
Registered: 2016-06-30
Posts: 3

Change the serial port for a device

I would want to know the commands or the procedure to change/replace the comports number in archlinux, as done in windows by going into device manager.

Basically I have a sensor connected to the system which sends ascii codes to the archlinux system. I want to replace this sensor by another one, which is serially connected to the archlinux system and simply change the comports of these two sensors, so that the system takes the same ascii code from the new sensor and performs accordingly.

Offline

#2 2016-06-30 15:06:12

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,793

Re: Change the serial port for a device

Welcome to Arch Linux.   I am a little confused by your post so I'll make some assumptions.  Bear with me.

You have a sensor attached to the system which "Sends ASCII codes to the Arch Linux system".  I assume this is a serial device?  I also assume you have some program, or some script that reads these.  If so, the serial device has a device node in /dev;  likely something like /dev/ttyS0.  Unlike toy operating systems, *NIX maps these serial devices as pseudo files, not "COM ports".

You have a different device that is also serial.  You want to attach this to a different serial port which will also be mapped into a device node, say /dev/ttyS1.   You want to be able to select the device with which you wish to communicate.  The usual way of handling this is to tell the script or program which port to use.  Are you saying you want to change the name of the device node?  If so, that would probably have to be done with custom udev scripts.  I don't recommend that.  This could be complicated in that some serial ports (/dev/ttySx) use traditional bus based UARTS/USARTS.   Others are spawned when you connect a USB device that contains a USB to serial bridge; these are usually called /dev/ttyUSBx.

Give us a little more detail as to what you are trying to do, and how you are communicating with these sensors.


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#3 2016-06-30 17:06:13

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,532
Website

Re: Change the serial port for a device

To build on the above, many serial communications devices will send a form of individual ID in response to the appropriate query.  So if you want to be sure you listed on the right /dev/ttyS* node when multiple are present, you can query each one until you find the one you want.

The specifics on how to send this individual ID request depend on what the devices are (a large number of simple usb sensors run on a PIC 18F chip or close relative) and also on the programming/scripting language you are using to interact with it.  But at the most general level, you send the proper byte string to the device node with a write() and then read() the response.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#4 2016-07-01 10:52:41

Payal
Member
Registered: 2016-06-30
Posts: 3

Re: Change the serial port for a device

Sorry for not being clear enough with the information provided.

But your assumptions (#2) are correct.
I have found the devices and their ports by $ lsusb , $ dmesg. Also their id by $ udevadm info --name=/dev/ttyUSBx The sensor which sends the ascii code to the archlinux system is at ttyUSB1 and the system reads these ascii codes from ttyUSB1. I have connected a new senor to send the same ascii codes which is at ttyUSB0. I want to set this new sensor to the port ttyUSB1, so that instead of reading from the old sensor, i could use this new sensor to feed  ascii codes to the archlinux system.

I am trying to :
edit /etc/udev/rules.d/99-XXXX.rules to add a device mapping rule for the device.
For example:
SUBSYSTEM=="tty", ATTRS{idVendor}=="XXXX", ATTRS{idProduct}=="XXXX", SYMLINK+="leapmotion".

But i am a little unclear if this would port the new sensor to ttyUSB1.

How do i proceed?

Last edited by Payal (2016-07-01 10:57:17)

Offline

#5 2016-07-01 11:58:23

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,532
Website

Re: Change the serial port for a device

Obviously that udev rule will not link the device of interest to ttyUSB1, it will link it to leapmotion.

The ttyUSB number is arbitrary and should not be relied on.  I'm not sure if it depends on order of detection or on the actual usb port the device is plugged into (or a mixture of both) but it works a lot like block device names vs UUIDs.  If you want a /dev/ entry that will always be for that specific device, use the udev rule you specified and tell the software to communicate with it on /dev/leapmotion.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#6 2016-07-01 12:26:09

Payal
Member
Registered: 2016-06-30
Posts: 3

Re: Change the serial port for a device

Exactly! I have saved the ttyUSB0 to /dev/leapmotion. in the /etc/udev/rules.d/99-XXXX.rules .

As you suggested: use the udev rule you specified and tell the software to communicate with it on /dev/leapmotion.

How do i do that. Could you assist me with the commands?

Offline

#7 2016-07-01 12:30:09

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,532
Website

Re: Change the serial port for a device

No, because you haven't told us anything about the software.  You've only said that "the system" communicates with the device on ttyUSB1.  Is this your software or someone else's software?  If the latter, what is it?  Does it have documentation?  Is source code available?  Any program that communicates with a serial device should either autodetect the device itself, or have a configuration file or command line parameter with which you can set the device node to talk to.

Please don't feed us a string of minimal information or X-Y problems.  Describe exactly what you are trying to do.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

Board footer

Powered by FluxBB