How To Test Serial Port
The Question:

I plugged in a device (i.e. GSM modem) through a serial port (a.k.a. RS-232), and I need to see with which file in /dev/ filesystem this device was tied up, to be able to communicate with it. Unfortunately there is no newly created file in /dev/ nor can be seen anything in dmesg output. So this seems to be a hard question.
Background:
I had never worked with a serial device, so yesterday, when there appeared a need, I tried to Google it but couldn't find anything helpful. I spent a few hours in seek, and I want to share a found answer as it could be helpful for someone.
1 Answer
Unfortunately serial ports are non-PlugNPlay, so kernel doesn't know which device was plugged in. After reading a HowTo tutorial I've got the working idea.
The /dev/ directory of unix like OSes contains files named as ttySn(with n being a number). Most of them doesn't correspond to existing devices. To find which ones do, issue a command:
Above is an example output of my PC. You can see the initialization of a few serial ports:
ttyS0, ttyS1, ttyS4, ttyS5.
One of them is going to have a positive voltage upon a device plugged in. So by comparing the content of the file /proc/tty/driver/serial with and without the device plugged in we can easily find the ttyS related to our device. So, now do:
(un)plug a device
Next check the difference between the two files. Below is an output of my PC:
By comparing the three numbers with the dmesg output we can determine which one is the port:
Hence, our device is /dev/ttyS0, mission accomplished!
Not the answer you're looking for? Browse other questions tagged devicesttyserial-port or ask your own question.
On Linux, I want to send a command string (i.e. some data) to a serial port (containing control characters), and listen to the response (which also usually might contain control characters).
How can I do this as simplest as possible on Linux? An example is appreciated!
5 Answers
All devices on Unix are mapped to a device file, the serial ports would be /dev/ttyS0/dev/ttyS1 .. .
First have a look at the permissions on that file, lets assume you are using /dev/ttyS1.
ls -l /dev/ttyS1
You will want read.write access, if this is a shared system then you should consider the security consequences of opening it up for everyone.
A very simple crude method to write to the file, would use the simple echo command.
and to read
You can have cat running in one terminal, and echo in a 2nd.
If everything is gibberish, then baud rate, bit settings might need setting before you start sending. stty will do that. !! NOTE stty will use stdin as default file descriptor to affect.
Equivalent commands.
This might be enough for you to script something and log ? Not sure what you are trying to achieve.
For a more interactive, remembers your default settings approach would be to useminicom it is just a program which does everything I've mentioned so far. (similar to hyperterminal in Windows, you might be familiar).
An intermediate solution, would use a terminal program like screen which will work on a serial device.
man screenman minicomman stty for more information
All you have to do is open two terminals. In the first terminal you cat everything from the device, e.g.
in the other terminal, you can send arbitrary hex characters and text to the terminal e.g. as follows:
The echo -e command enables the interpretation of backslash escapes.
One has to make sure of course that (i) the serial settings (speed, word length, flow ctrl, etc) are correct and (ii) the serial device (on the other end) is not blocking.
AutoCAD 2015 spot a whole new interface, it comes with new 3D features and environment and it makes you wonder if this is the AutoCAD 2015 pirated original CD you’ve bought. 
Programs that talk to serial devices:
or from shell you can do:
You can read and write to a device simulataneously like so:
Your message is sent to the second cat from stdin, and the first cat relays the response to stdout, turning your terminal into a chatroom.
To finish up, ctrl-c, then run fg then ctrl-c again.