Waseem
Waseem

Reputation: 11941

Can I control hardware via PHP Language?

I wondered if I can use PHP to control an external hardware connected with the parallel port or USB port ? any ideas or resources ?

Upvotes: 17

Views: 19211

Answers (8)

Hamid Hemani
Hamid Hemani

Reputation: 21

You might wanna look into Node js with socket io npm package.. I have built a smiliar system where I can control my hardware directly through web api interface. My linux machine is Raspberry Pi that is controlling a hardware attached to ots I/O. My Node js webserver is in raspberry pi, Node js not only listen web instruction from front end javascript but can also control hardware through npm hardware I/O packages.

Upvotes: 0

Your Common Sense
Your Common Sense

Reputation: 157889

Well, it was an LPT port and a binary, both for Lin and Win and small PHP code to call this binary:

http://www.epanorama.net/circuits/parallel_output.html

Upvotes: 0

edouardklein
edouardklein

Reputation: 33

If you intend to run this on a *NIX system, you may want to look at Plan 9 From User Space. With these libraries, you could write a C program that make your hardware appear as a part of your file system, i.e. you mount it as you would mount a USB drive, for example. Once mounted, you can use PHP's function for manipulating files to control your hardware.

If you don't know what Plan 9 is, this may not be very clear. Let me illustrate by an dummy example : your hardware is an electronic board displaying the number of logged in user via a 7 segment display. You use Plan 9 from user space to write a program that mounts 2 files :

/somewhere/input

/somewhere/output

Writing "42" (as you would do with a text file) to input will make your board display 42. Reading output will for example tell you for how long this number did not change.

This may not be the easiest way to achieve your goal, as learning to use the Plan 9 libraries is not very easy (although people on IRC are very nice and helpful), but it is in my opinion the most elegant way.

With this, you would also be able to control your hardware from any other language, for all languages I know can manipulate files.

Upvotes: 0

naivists
naivists

Reputation: 33511

If you can write a program in C++ that communicates with that device, you can create a PHP extension: http://www.devarticles.com/c/a/Cplusplus/Developing-Custom-PHP-Extensions-Part-1/

Upvotes: 2

symcbean
symcbean

Reputation: 48357

As per my comment on Filip Ekberg's answer....maybe.

It depends on your OS and the level of access required - should it be bi-directional? Are you trying to use the control lines for purposes other than flow control? Do you know the details of the communications protocol?

C.

Upvotes: 0

Andy
Andy

Reputation: 17771

This is a useful class for serial attatched devices on Linux: PHP Serial

Serial ports are often used to communicate with peripheral devices, such as: modems, POS terminals, special printers, etc..

This class can be used to communicate and configure peripherals connected to a serial port under Linux, simplifying the development of applications that need access serial devices.

Upvotes: 5

Filip Ekberg
Filip Ekberg

Reputation: 36297

You might want to look into php exec. PHP doesn't allow Direct access to Hardware through the API, you need to call sub-programs to do that.

Upvotes: 4

lajuette
lajuette

Reputation: 1017

You have to write a program that you can call via system calls. PHP code can't access your hardware directly.

Upvotes: 0

Related Questions