Serial Port Communication C++ Linux [closed] Ask Question. Up vote 3 down vote favorite. I'm looking for a easy to use C++ librairie to dialog with Serial Port under Linux. I looked at Boost::Asio but it look like very complicated for my little usage. I just want to received some information on the Serial Port and record them in a database. I want to make sure my serial port driver is installed and configured the serial port or not. > Linux - Software: serial port communication. Linux Wiki; Distro. Home » Linux » Automating serial port communication on Linux Automating serial port communication on Linux Posted by: admin December 24, 2017 Leave a comment. Mar 01, 2010 Introduction to Linux - A Hands on Guide This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter. PHP by default does not offer good COM port support however a PHP extension called Direct IO does offers low level access to IO. We will use this extension for serial port communication. On unix system install the extension using PECL, open a terminal and type.
Active1 month ago
EDIT: I have done some testing with the following script (found here: PHP serial port data return from Arduino). It appears that even using fwrite to /dev/ttyUSB0 outputs my new command plus the last command sent from the device. This makes me think that maybe the serial port was not set up correctly (e.g. might need to use stty to change settings to clear the buffer) or there is something else I need to do (with php) to clear the buffer at /dev/ttyUSB0 before sending a new command. Any help would be appreciated, thanks.
Original question:
I'm using php-serial to communicate with a device via serial port. The device has a function to display all input and output to the serial port on a screen. When I run the following script I can see on the device that the script is taking every command output by the device and repeating it back to the device. I believe this is causing an issue in that I just want to answer 'OK' back to the device, not repeat the output and then say 'OK'. Repeating the same command back first seems to confuse it and then it will not adhere the 'OK' command. I can get around this by outputting 'OK' every 0.1 seconds on a loop, but I would rather read the output from the device and then respond to it accordingly. I don't believe there is anything in my script telling it to do repeat the commands back. Is this an issue with the php-serial class that anyone has experienced? I tried setting $autoflush = false; with no difference.
My script:
Example output on the device screen before my script is run:
Example output on the device screen while my script is running:
Community♦
MattMatt
1 Answer
install minicom and try before opening the port with:
Federico Zancan
3,17833 gold badges3434 silver badges5959 bronze badges
Jose Lopez QuinteroJose Lopez Quintero
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Not the answer you're looking for? Browse other questions tagged phpserial-portbufferstty or ask your own question.
Active2 years, 5 months ago
I have a linux server (Red Hat 4) with one serial port connection to an embedded linux device, and another serial port connection to a power controller for that device. My current way to control them is to open two minicom sessions, each in its own window. I would like to automate this communication through scripts. At first, I began to think how I could automate using minicom, then realized I shouldn't need to try to automate using a console application when a script should be able to speak to the port directly.
I know some Perl and some python. I do not have previous experience with modem communication (using AT commands). Perl has Device::Modem, though it's only beta, and Perl seems like a good choice because I prefer its text extraction and wrangling abilities. But, if I need to learn how to control a modem and write/debug a script, that adds more time to my task.
Is it possible/common to interactively control a console app like minicom with a script? If not, what are some good resources for me to learn how to use modem AT commands? Or is there another resource out there that could simplify things for me?
brian d foy
105k3030 gold badges177177 silver badges484484 bronze badges
jasper77jasper77
81833 gold badges1313 silver badges2929 bronze badges
5 Answers
Kermit is a serial communication app like minicom and it has its own script language, and I used it for some automatic upload on embedded devices. However, it is quite limited and/or buggy, so I finally switched to using python and pyserial.
Whenever you deal with texte mode, like AT command set or speaking to a shell over a serial line, it is really powerful.
If I need to do binary transfer using some standard protocol, I usually use command line tools in non interactive mode, and spawn them from my python script.
Here is some part of the tools I built : waiting for some input, sending data through xmodem, sending a command to u-boot and starting a transfer using the kermit protocol. I use it for automatic flashing and testing of embedded devices.
shodanexshodanex
11k88 gold badges4949 silver badges8282 bronze badges
I discovered runscript ('$ man runscript'), a utility that adds an expect-like scripting ability to minicom. The expect behavior is useful to me since this device uses a proprietary interactive boot sequence. It's rudimentary but sufficient. A script can be invoked when starting minicom with the '-S scriptname' flag, and specific text from within the script can be sent to a log file, which is useful when running minicom from a script. I haven't found a way to send console content to a log, so having an external script know what's going on inside minicom involves writing to a log and having the script monitor the log. I plan to use runscript only to restart and get to a shell, then ssh to the device for real interaction, within a higher level language script such as Python or Perl. If minicom weren't already in place, I would take shodanex's approach.
Runscript cannot have nested expects. Epson 1240u driver os x download without registration. I got around this by using goto's and labels, which is arguably more readable than nested expects anyway:
jasper77jasper77
81833 gold badges1313 silver badges2929 bronze badges
If it's just about controlling the devices and nothing else (like processing messages, interacting with other operating system services, etc) you can use the chat program. It's written exactly for this.You may find it in the ppp package on any Linux distro.
daxim
Linux Serial Port Example![]()
34.6k44 gold badges5353 silver badges117117 bronze badges
user237419user237419
6,11033 gold badges2424 silver badges3737 bronze badges
I'm using such a power controller which I use RS232 to control.
I script it using bash simply by issuing:
the specific device I'm using also uses 300 baud rate so I issue:
before hand.
McradleMcradle
Python now has the PySerial library: http://pyserial.sourceforge.net/
Ruby has the SerialPort gem: http://rubygems.org/gems/serialport
Perl probably has a similar library, but I was unable to find it.
I discovered both of these from the very useful Arduino Playground: http://playground.arduino.cc//Main/Interfacing
CJ
CJ.CJ.
Not the answer you're looking for? Browse other questions tagged linuxautomated-testsserial-portmodem or ask your own question.Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |