Jump to content

PHP and serial ports


killboy

Recommended Posts

I've been searching around and I found that it's possible to read/write to external devices such serial ports with PHP through the Direct IO functions in Windows. Problem is, I don't really know how to use them and the examples I've found are all taken from the PHP.Net site which don't tell me much. Can anyone enlighten me with these functions? Any good example? Or did I just misunderstand what these functions are about?Thanks.

Link to comment
Share on other sites

Do you know much about communication with something like a serial port? It would be hard to explain what PHP can do if you don't know how communication with ports like that works, and the PHP manual probably isn't the best place to learn about serial I/O.

Link to comment
Share on other sites

Not much actually.What I really need is to be able to read data from the port (any port will do, I just thought I'd be luckier searching for serial ports).Just so I don't miss the point: the communication between the port and PHP must be local, right? I can't access to an external device through a remote page, can I?

Link to comment
Share on other sites

Just so I don't miss the point: the communication between the port and PHP must be local, right? I can't access to an external device through a remote page, can I?
AFAIK, yes. I guess if the OS itself exposed a way to connect to a remote device (UNC style), this extension will use it, but I'm not sure.Also notice that this extension actually deals with file descriptors. On UNIX, devices are associated with filepaths, so you can essentially deal with devices as if they're files. But the extension won't really work on Windows, as Windows forces communication with devices to be done via its APIs (which you can connect to with another (Windows specific) extension.
Link to comment
Share on other sites

What about COM functions and sockets?Heck, I'm totally lost here. I will expose what I need as clear as possible:In my university, I'm working with some teachers in a project with Systems and Electronics. They're building a sort of robot which will be connected to the computer. This robot will be walking through a sort of board, drawing a geometric figure and passing the XY points to PHP.They said the robot will send the data by a port (of any kind), thing is, I must get the data sent by this device and make other things that don't have to do with the topic.Do you know someone or have some code making something similar?I hope I was clear enough; my english is not perfect.Thanks for the help.

Link to comment
Share on other sites

"COM" isn't the same "COM#" from a serial port device's properties... "COM" is a language-neutral way of communicating across languages, similar to .NET in essense. Just as one .NET program can communicate with another program that supports .NET, so can COM programs. PHP is just a program that can connect to COM programs (i.e. APIs).The COM functions are useful if the device comes with a certain COM API on its own. If it does, it would be this APIs responsibility to translate raw device instructions into something PHP could directly call, ideally in a convinient fashion, in your case - a function accepting an array of XY points.sockets are useful if the device is available via a TCP/IP kind of connection (local or remote). Not necesarily HTTP... think MySQL, SSH and FTP... all protocols running over TCP/IP. Sockets allow you to implement those or other device/platform specific protocols.It all depends on what the device supports. If it's over a serial or USB port connecting to a Windows OS, you must write and install a "driver" for the device - a separate program written in C++ or another compiled language (i.e. not PHP) that will communicate with the device. The program should of course have a way of accepting input from other programs such as PHP. This way could be via a COM API or a TCP/IP socket."port of any kind" is a little too vague is what I'm saying. If you're willing to use a UNIX OS, you could at least reduce things to the Direct IO functions.

Link to comment
Share on other sites

Well, that's what they say: "The port can be any kind", I guess I'm gonna stick with serial port.Unfortunately, it's not up to me to decide what OS to use. What they told me is that this robot interacting with the language is going to be presented in a school, where all the computers run Windows.I've been doing more research and found this:http://www.easyvitools.com/phpserial/index.htmlAnyway. Do you think all this port stuff is too much to deal with PHP? Would you recommend me to switch to Java?

Link to comment
Share on other sites

Interesting extension.... that's EXACTLY what you need to communicate to serial port devices. Heck, I think I'm gonna keep a copy of this just in case :) .Now the only thing you're missing is the device's protocol spec. It needs to tell you the kind of settings you need to set upon openning the connection (bitrate, partiy, etc.) as well as how must the input to the device be formed and if there's any output from the device after each call. Do you have such a spec?With this extension at your disposal, you don't need to migrate to JAVA or anything else. Even if you do, you'll still need the device's protocol spec unless the device comes along with a more high level API for you to install.

Link to comment
Share on other sites

  • 2 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...