Php Serial Class
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.
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. When serialize() serializes objects, the leading backslash is not included in the class name of namespaced classes for maximum compatibility. See Also unserialize() - Creates a PHP value from a stored representation. Try composer require hyperthese/php-serial The only tiny gotcha is you need to make sure the user/program is able to access the dialout group. For example, apache requires a sudo usermod -a -G dialout www-data.
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
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.
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 :)
Licence
Hp envy beats audio driver windows 10. 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.
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.
I wonder if there is a way to accomplish reading my serial port via PHP - that works :-)
In practising my Arduino skills, I developed a simple LED ON/OFF sketch. It works by entering on or off in the serial monitor.
Next step, I put together a webpage to act as an GUI interface to click a link and perform the on and off function above. This webbased GUI works via PHP.I am using the PHP SERIAL class to interact with the serial port my Arduino is using.
The issue is I need to find a way of getting feedback from the serial port. Using the Arduino IDE serial monitor, I can see my printed messages in response to each of my serial input and I need to retrieve the same feedback in my PHP code.
The PHP Serial class offers a readPort() function but I does not return my data.
Php Class Constant
UPDATE[2]:
ARDUINO:
PHP/HTML:
3 Answers
I assume you work on linux.
First setup your serial port:
Then you can use good old fashion fread/fwrite
There is only one thing you have to remember. Arduino will restart on every connection. If you don't know that It will confuse you. For instance if you connect (fopen) and instantly send data Arduino will miss it because it's booting (which takes a sec or two). Experiment with sleep to give it some time. If you want to disable restarting use 10uF capacitor from GRD to RST.
Good luck
ps. you can troubleshoot with 'screen'
Post about setting PHP with Arduino http://systemsarchitect.net/connecting-php-with-arduino-via-serial-port-on-linux/ and one more here http://systemsarchitect.net/arduino-and-php-serial-communication-with-a-protocol/.
/dev/ttyUSB0 running with user root, if your using apache try chown /dev/ttyUSB0 to apache or user is logged in.
and then try again, or try logout from ubuntu and login as root user.
You are probably trying to read when is no data on the serial port. You need to implement JavaScript code to call PHP code that can read at regular intervals.
When you have got data, you should process it.
readPort()
has worked fine for me. If the baud rate, parity, etc. is adjusted properly, then you should not have any problem reading the serial port.
Here is a sample of using the library for Arduino. It worked for me some time ago:
Peter MortensenPhp Serial Class Example
protected by Community♦Nov 15 '13 at 8:19
Php Serial Number Generator
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?