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

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
robster
Forum Contributor
Posts: 360
Joined: Wed Jul 16, 2003 8:28 am
Location: Sunshine Coast, Australia

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

Post 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.
Last edited by robster on Sat Mar 19, 2005 10:08 pm, edited 1 time in total.
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

Have you looked at using PHP sockets?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
robster
Forum Contributor
Posts: 360
Joined: Wed Jul 16, 2003 8:28 am
Location: Sunshine Coast, Australia

Post 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.
User avatar
robster
Forum Contributor
Posts: 360
Joined: Wed Jul 16, 2003 8:28 am
Location: Sunshine Coast, Australia

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

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