Php Serial Port Communication Linux Wine

Posted By admin On 17.12.19
I'm using PHP to interface my AVR microcontroller in /dev/ttyS0. I bet someone else does the same.
Here's some hint :
- dio_tcsetattr -> is set to enable :
- RTS / CTS hardware control
- ICANON mode
(means that dio_read will wait until 0x0A/LF or other control character is entered in /dev/ttyS0 before it returns reading result, when you use dio_write it will also send 0x0A/LF automatically in the end of the message to your device).
For those who dont need RTS/CTS and/or ICANON, you can use linux command : stty.
Here's mine :
<?php
exec
('stty -F /dev/ttyS0 4800 raw');
$fd=dio_open('/dev/ttyS0',O_RDWR O_NOCTTY O_NDELAY);
dio_fcntl($fd,F_SETFL,0);
dio_write($fd,'x41',1); // write 0x41 or 'A' to /dev/ttyS0
// Replace result_length with your expected command result length
for ($i=0;$i < result_length;$i++) {
$result .=dio_read($fd, 1);
}
echo
$result;
?>

Refer to :
- Serial Programming Guide for POSIX Operating Systems, http://www.easysw.com/~mike/serial/
- stty man pages
  1. Linux Serial Port Example
  2. Linux Serial Port Software
  3. Linux Serial Port Programming
Active3 years, 8 months ago

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 :

Hi, I am trying to use a Wine application that use a serial cable to connect with a device to be programmed. Until now I had no success and I need yor help, please. LinuxQuestions.org > Forums > Linux Forums > Linux - Software: Wine + Serial Port? Wine + Serial Port? I have added the links to my serial ports as documented.

Php Serial Port Communication Linux Wine

This class can be used to communicate with a serial port under Linux or Windows. It takes the path (like '/dev/ttyS0' for linux or 'COM1' for windows) of serial device and checks whether it is valid before opening a connection to it. Once the connection is opened, it can send data to the serial port. Wine + Serial Port? I've installed wine and my programming software, the program runs perfectly, but doesn't list any com ports in the setup menu. There are no errors in the console window when I start the app. Changing permissions on serial port. How can I get communication with my Arduino Uno over the serial port to work? Unix & Linux; Ask Different (Apple). Php read data from serial port on linux. Ask Question. Up vote 1 down vote favorite. 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.

the line 'print_r(' (size '.strlen($read). ' ) ');' always return zero. What is the reason why I cant read data from serial port?

cukcukcukcuk

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.

Serial port communication software

Just do not read it the second time

mrmin24mrmin24

Had the same problem. I needed two options set using stty -isig -icanonCanon ir 5000 copier. Hp compaq dc7900 small form factor pc audio driver. once they were set the script read no problem.

thenetimpthenetimp
5,8125 gold badges22 silver badges36 bronze badges

Linux Serial Port Example

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.

Linux Serial Port Software

TheHiddenTheHidden

Linux Serial Port Programming

Not the answer you're looking for? Browse other questions tagged phplinuxserial-port or ask your own question.