views:

317

answers:

4

I have a program that is interacting with hardware via parallel port programming. i had compiled it and using its object file to interact with the hardware (a simple led). when i execute it directly on the shell it serves the purpose of glowing the LED but when i execute it using shell_exec() in php the command is executed but unable to interact with the hardware. i am totally confused.. .

A: 

This may be way off, but if you're going to use PHP to do hardware-interfacing, I'd throw some AJAX in there as well.

Basically have your javascript pass keystrokes to the server via an Ajax function. Everytime PHP gets a new request via javascript, it looks up the keystroke in an array of pre-written set of shell_exec() commands and runs the one for that keystroke.

Have the javascript listen for key presses, and have the array of shell commands directly correlate to each possible keystroke (or combination of strokes, if you can get fancy).

I'd start off with something really simple like dots and dashes, but I bet you can get really cool stuff fast.

Anthony
+1  A: 

If your PHP script is running as different user (e.g. if you run it as Apache module, it may be user apache), it may not have the same access to HW as when logged in as yourself. Check the permissions needed to interact with the parallel port.

Piskvor
If the shell_exec isn't firing at all, he should run the script in CGI mode for sure. I thought he was saying it only fired the command but didn't give him any interaction after that.
Anthony
He states that "the command is executed but unable to interact with the hardware", which to me also sounds like a permissions problem. The script will probably run as the apache user, and apache will not have the necessary rights. So either he should create a wrapper script with ie. setuid bit set or a daemon that interacts with the HW and call that from PHP, or give the apache user (or whatever user the PHP script is run as) the appropriate permissions. Checking /var/log/messages for any error messages might help too to find the actual reason why the script fails.
wimvds
A: 

I would set up some kind of socket server on the host that connected to the parallel port and provided a domain socket that PHP could talk with. Its really the only way you are going to deal with streaming I/O over a RESTful protocol.

As Anthony mentioned, a little AJAX would make this rather seamless as far as the user experience went.

This lets you use simple PHP sockets to connect, send, get a response, display it and then wash / rinse / repeat per request. A lot easier than dealing with shell_exec().

Tim Post
A: 

i want to display led through lamp server... lamp means linux,apache,my sql&php. plz tell me what is the php programme for led displaying throgh parallel port(db25).. how i control parallel port for led display..

Ravi