Page 1 of 1

Reading and Writing to a SERIAL port w/ PHP (was USB port)

Posted: Sat Mar 19, 2005 6:03 am
by robster
Can this be done?

I've actually learned to programme on other languages YEARS ago and left them behind as I only use web applications now and use the browser for display.

I now have a need to access a port to send and receive data and was wondering if we can do this with PHP?

I'm running OSX if that makes ANY difference at all (doubt it eh ;)).

Pretty interesting this one I think. Really looking forward to hearing what people have to say.

Posted: Sat Mar 19, 2005 7:21 am
by Maugrim_The_Reaper
Have you looked at using PHP sockets?

Posted: Sat Mar 19, 2005 8:58 am
by feyd
what does sockets have to do with USB ports? :?

Depending on the device, it's fairly easy. A USB drive for instance, will automatically mount to the system when it's attached. Other devices are more complicated, but still possible. I don't remember how the new Mac system hardware access works, but under unix, if the device can be mounted to a device slot eg. /dev/hda1 then it can be accessed. How easily, depends on the device and the OS making nice with PHP about it. :)

If you can find a command line tool that does it already, I'd suggest going through that, as writing your own may be far more headache than you want to afford it.

Posted: Sat Mar 19, 2005 7:24 pm
by robster
Thanks for that reply :)

What I'm after though is not actually access to a USB drive, but the port itself. I have an application where I need to send signals to some LED's and although I would have attempted this via the com port, looking at the back of this mac it seem I have none.

So I have firewire and USB to play with.

I need to actually send data out of that USB port (and have a circuit that turns this into an LED flash, but that's another story) and I need to read data coming from the USB port (again, via a circuit, another story, etc ;)).

I really want to use PHP, as, I really want this to work over the web, remotely and I love using the language.

Thanks again, I look forward to any advice.

Posted: Sat Mar 19, 2005 10:04 pm
by robster
turns out it may actually need to be for a SERIAL port, not a USB port.

This could make things easier (not?) :)

Any ideas there?

Posted: Sat Mar 19, 2005 10:14 pm
by feyd
From what I remember, Macs with OS X will have the /dev/* stuff.. I'd look into a compiled program that has access to the device and can provide a simple interface for you to communicate with it, then just make calls to it via shell_exec() or its siblings.