Read serial port data using Perl and PHP under windows Post date: Category:, Author: Comments: Tags:, Read serial port data using Perl and PHP under windows Read serial port data using Perl is very easy compare to PHP in Windows OS. The PHP serial port reading has some complication in Windows Os. In Linux serial port reading is very simple using PHP, but on Windows it makes more difficult that is why I choose Perl. Using Perl we can easily done this, with the help of Win32 Serial port library.
Socket_create_listen() creates a new socket resource of type AF_INET listening on all local interfaces on the given port waiting for new connections. This function is meant to ease the task of creating a new socket which only listens to accept new connections. Serial port access from PHP with Raspberry Pi. Adapted from: One very interesting type.
Make sure your windows machine is installed with Perl and Win32 serial port lib. The easiest option is just install the and install with basic options. Now you have to install with administrator privileged terminal. 6 thoughts on “ Read serial port data using Perl and PHP under windows”. Hi, thanks first for hints. I did all steps but not being a professional maybe I’m missing something on last step.
I installed perl and Win32 serial port package, I did the first test from dos cmd using perl serial.pl and it worked. It reads the barcode only once (is it correct?). Last step I did a php program copying this code without the baud and port variable just becouse I’m using com3 and 9600 as default. Header(‘Access-Control-Allow-Origin:.’); //$port = $REQUEST‘port’; //$baudrate = $REQUEST‘baudrate’; //$perlresult = `perl serial.pl $port $baudrate`; $perlresult = `perl serial.pl`; $data = strreplace(“Content-type: text/plain”,””,$perlresult); echo trim($data); running the php do not happens nothing. You talk about exec but I don’t know how to implement it. Last but not least.
How can leave the barcode scanner open for receiving every entry all over the day long? Many thanks on. We followed exactly the same steps as mentioned. When executed on the browser localhost/index.php, it shows that something going on but even after 10-15 min.
There is no message or error. Rajeev on. The serial port installation makes the work faster and more productive. I am sure that each user will appreciate these benefits. Oops on. hey i installed the Win32 Serial Port but its showing the same undefined index for “port” and “baudrate” vikas on. Thank for your article.
I have installed XAMPP parked with Perl and downloaded the zipped package you attached to this article but the test file doesnt is only showing undefined index for “port” and “baudrate”. Do I still need to install Win32 Serial Port or XAMPP is sufficient. Please help with where I am missing it. Ademola on. Yes For windows platform you have to install Win32 serial port package.
Then only it works fine. For linux you don’t need that with PHP you can make it works.
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. 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.
'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. 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.
Comments are closed.
|
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |