Active2 years ago
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! I want to write data to a serial port in C (linux) for a a Propeller board. Program works fine when taking input from the console, but when I write strings to it always return: ERROR - Invalid command from the device. Writing to serial port from linux command line. Ask Question Asked 7 years. I was using the suggestions in this post to write to a serial port, then using the info from another post to read from the port, with mixed results. I found that using screen is an 'easier' solution, since it opens a terminal session directly with that port.
This question already has an answer here:
Linux system generally call serial ports /dev/ttySxxx instead. To summarize, when programming for the serial interface of a Unix system it is highly advisable to provide complete configuration for the device name. Not even the typical /dev path should be hard coded. Serial Port programming in Linux using C - Working code. For my application, i wanted to communicate with SIM900 GSM module which was connected to my PC running Ubuntu OS. The SIM900 GSM module was connected to the PC using a CP2102 USB-UART bridge. Do remember that you need to select the right port code in the Array of ports in the library.
- How to send data to a serial port and see any answer? 5 answers
I have a web application running on an Raspberry Pi Server (Debian).
The application send a simple echo over the commandline to a serialport.
I think the serialport is configured correctly.
The Echo:
echo 'G0030af13403b1610097ee8' > /dev/ttyUSB0
When i send the command nothing happend.
But when i open a cat session in a other terminal everything works fine !
cat /dev/ttyUSB0
I think the serialport does not open with the
echo
alone ...Is there a way to open the port and send the echo in one commandline ?
Kingofkech48311 gold badge66 silver badges2020 bronze badges
PatrickPatrick
marked as duplicate by Romeo Ninov, Stephen Rauch, Anthon, Rui F Ribeiro, G-ManSep 27 '17 at 20:09
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
1 Answer
Thanks to all i have found a solution ...
I have to run cat in background.
cat /dev/ttyusb0 &
then echo to it .
echo 'G0030af13403b1610097ee8' > /dev/ttyUSB0
and kill the
cat
process.I have solved it in a litte shell script:
KingofkechLinux Write To Serial Port Numbers
48311 gold badge66 silver badges2020 bronze badges
PatrickPatrick