d3vdpro
d3vdpro

Reputation: 2997

running a parallel port controlling program through php

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.. .

Upvotes: 2

Views: 1671

Answers (3)

user50049
user50049

Reputation:

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().

Upvotes: 0

Piskvor left the building
Piskvor left the building

Reputation: 92792

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.

Upvotes: 1

Anthony
Anthony

Reputation: 37065

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.

Upvotes: 0

Related Questions