I cannot get PHP dio to work on linux. I receive no error messages, but nothing is output to the serial device when I use dio_write nand reads are always null. I initiate the serial port with
$bbSerialPort = dio_open($portName, O_CREAT | O_RDWR);
This seems to accpt the connection. When I use
dio_write($bbSerialPort, $dataToSend);
it retuns with the number of bytes sent, but nothing is sent. When I use
$data = dio_read($bbSerialPort, 2);
it always returns NULL.
I have tested the /dev/ttyUSB0
port using minicom
and all works correctly. I have also tried the same code on both MAC OS and Windows and all works OK.
I am wondering if it is something to do with permissions and owners for the device on the different platforms?
I have tried re-installing both php and thje dio extension on both Debian and Ubuntu – always the same result – no errors but the dio_write never writes anything to the serial device.
2
Answers
Thanks to Peter, I have finally resolved my issues. It was indeed related to the serial port settings and the way my PHP code accessed the port. The serial port was set to 9600 baud and I was not leaving enough time before reading the reply from my remote system. All working now.
When file position of the given file descriptor is at the end, position needs to be set to the beginning of the file if the dio_read() has been called somewhere after the dio_write(). With dio_seek() the position can be set to the beginning (or adjusted for your use case):