Php Serial Port Communication Linux

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

How To Check and Use Serial Ports Under Linux. Linux serial port, linux serial port communication, linux serial port. 25 PHP Security Best Practices For Sys. 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. Read serial port with PHP is so simple in Linux machine for windows will write another article soon. Just download the read serial port with php script just below. And extract it to your /var/www/html/ folder. Jun 10, 2014  Control Arduino Using PHP. By rhbvkleef in Technology Arduino. You grant PHP to use the serial port (USB) If you are not running Linux you don't have to run this command, in fact, you can't. For other linux distributions you are going to have to check its documentation (same for osx). Linux system generally call serial ports /dev/ttySxxx instead. To summarize, when programming for the serial interface of a Unix system it is highly advisable to provide complete configuration for the device name.

PHP Serial was written at a time where I did not know any other language thanPHP and I started to get seriously bored with its abilities.

  • 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.
  • We will use this extension for serial port communication. On unix system install the extension using PECL, open a terminal and type: sudo pecl install dio-0.0.7. In order to test sending and receiving serial data in PHP, the other end of the serial port should be open.

I somehow got hold of a « Citizen C2202-PD » point-of-sale display, and I wantedto play around with it. I also managed to get the documentation of it, andcreated a convenience class to access the serial port though the Linux file.

Afterwards, I posted it to PHP Classes,and this probably is what brought it any visibility.

Example

Library

State of the project

Interestingly enough, this piece of code that is widely untested has created alot if interest ever since it was created, and especially nowadays witheverybody toying around with Arduinos and Raspberry Pis. I receive about 1 emailevery month asking for help with the code or sending patches/suggestions.

I think that it is time for me to remove the dust off this project and to giveit a full visibility on modern tools, aka GitHub.

This tool will download and update the correct HP Compaq 6910p (6900) driver versions automatically, protecting you against installing the wrong Compaq 6910p drivers. Solvusoft's close relationship with Microsoft as a Gold Certified Partner enables us to provide best-in-class software solutions that are optimized for performance on Windows operating systems. Solvusoft: Microsoft Gold Certified Company Recognized for best-in-class capabilities as an ISV (Independent Software Vendor) Solvusoft is recognized by Microsoft as a leading Independent Software Vendor, achieving the highest level of completence and excellence in software development. Hp compaq 6910p base system device drivers.

Serial

Bugs

There is lots of bugs. I know there is. I just don't know which are they.

Platform support

  • Linux: the initially supported platform, the one I used. Probably the lessbuggy one.
  • MacOS: although I never tried it on MacOS, it is similar to Linux and somepatches were submitted to me, so I guess it is OK
  • Windows: it seems to be working for some people, not working for someothers. Theoretically there should be a way to get it done.

Concerns

I have a few concerns regarding the behaviour of this code.

  • Inter-platform consistency. I seriously doubt that all operations go the sameway across all platforms.
  • Read operations. Reading was never needed in my project, so all the tests Idid on that matter were theoretic. I was also quite naive, so the API isprobably not optimal. What we need is to re-think reading from scratch.
  • Configuration done by calling functions. This is so Java. It would be muchbetter to be able to pass a configuration array once and for all. Furthermore,I suspect that the order of call matters, which is bad.
  • Auto-closing the device. There is an auto-close function that is registeredat PHP shutdown. This sounds quite ridiculous, something has to be done aboutthat.
  • Use exceptions. Currently there is an heavy use of the errors system to reporterrors (2007 baby), but this is seriously lame. They have to be replaced byactual exceptions.

Call for contribution

I have about 0 time to code or test this project. However, there is clearly aneed for it.

As in all open-source projects, I need people to fit this to their needs and tocontribute back their code.

What is needed, IMHO:

  • Address the concerns listed above, and find new ones.
  • Create a reproducible test environment for each OS, and prove that eachfeature works (basically, unit-testing).
  • Report of use cases, bugs, missing features, etc.

If you feel like doing any of those, do not hesitate to create an issue or apull-request, I'll gladly consider consider it :)

Php Serial Port Communication Linux Mint

Licence

PHP SerialCopyright (C) 2007-2014 PHP Serial's contributors (see CONTRIBUTORS file)

This program is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2 of the License, or(at your option) any later version.

This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.

Linux Serial Port Read

You should have received a copy of the GNU General Public License alongwith this program; if not, write to the Free Software Foundation, Inc.,51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.