How do I read from a serial port?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Newbie here,

I've got a digital scale attached to the first serial port of my Linux
OS computer: /dev/ttyS0
How would I set up the serial port for reading data and then how would
I turn that data into a variable that I could use in a PHP program?

Thanks for any help,

Re: How do I read from a serial port?


If your scale uses the same settings as your OS (speed, etc) it should
be enough to fopen /dev/ttyS0 and use it like a file. Note: You can not
read and write with one socket - in this case you have to use two.


$string = "foobar\n";
$pointer = fopen("/dev/ttyS0","w");
fwrite ($pointer, $string);

Florian schrieb:
Quoted text here. Click to load it

Site Timeline