Php Serial Port Communication Linux Operating
- Linux Serial Port Program
- Php Serial Port Communication Linux Operating Software
- Linux Serial Communication Program

Just for information. I've a dual-boot PC (WIN XP and Ubuntu linux 9.04) so the hardware (PC, serial port, fiscal printer) are exactly the same for both operating system. I'm developing a cross-platform application (WIN/Linux) so I MUST find a way to make the serial port to be read correctly on both o.s. How to open, read, and write from serial port in C? Ask Question. For demo code that conforms to POSIX standard as described in Setting Terminal Modes Properly and Serial Programming Guide for POSIX Operating Systems. Linux - Multiple Serial Port Communication with C.
Linux Serial Port Program
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!
AlexAlex5 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.
X TianPrograms 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.
Unit 731 Testimony [Hal Gold] on Amazon.com. *FREE* shipping on qualifying offers. Unit 731 is a riveting and disturbing account of the medical atrocities performed in and around Japan during WWII. Some of the cruelest deeds of Japan's war in Asia did not occur on the battlefield. 31 Testimony / Avax. This is a riveting and disturbing account of the medical atrocities performed in Japan during WWII. In the first part of Unit 7. Testimony, author Hal Gold draws upon a painstakingly accumulated reservoir of sources to construct a portrait of the Imperial Japanese Army's most notorious. 
protected by dr01Jun 24 at 7:18
Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
Not the answer you're looking for? Browse other questions tagged serial-port or ask your own question.
I try to read serial port on Linux platform using PHP.
But I cant read any data. When I try to read using .net, this time I can read.
I use 'php_serial.class.php' class for serial port operations. You can read this class from this link :
here
My code is like this :
the line 'print_r(' (size '.strlen($read). ' ) ');' always return zero. What is the reason why I cant read data from serial port?
3 Answers
I am sure you have rsolved this by now, but here is my 2c worth.
You read the serial port twice. Once to check if there is data and then again when there is data. In my experience, reading it once clears the buffer and thus reading it again will yield an empty result.
Php Serial Port Communication Linux Operating Software
Just do not read it the second time
Had the same problem. I needed two options set using stty -isig -icanon once they were set the script read no problem.
Hello this is REALLY old but I am currently (still am) working on this, I got the bytes back correctly (remove ord() to read as a string btw).
The reason it is coming through as zero is because of the infinite loop, even if you send something nothing is being returned (so it would seem) Though using your code I managed to get things returned as strings.
I actually entered data the device side into the console..this then returned me what i entered into the device, it appears you would need to fork the process in order to do it 100% your way. The reason it works sometimes is because if you enter a command which returns a few lines it will most likely get some of them.
use screen to connect to the device and then just type random things and hit enter.. you will see it appear on your php output.