PHP to read a COM port??

From: Date: Wed, 08 Nov 2000 08:52:05 +0000
Subject: PHP to read a COM port??
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-24283@lists.php.net to get a copy of this message
Hi Perry, Well, the main reason is that I like PHP very much I know a great deal about it and how to do things with it.... It would be very nice to do this also in PHP.. I don't want to figure out how to do this in C (though I think that the similarity would be very great).. Also another problem when I do it in C is that I would need to get this data in my Mysql database.. (I also need to check some things in the database..) Again here I don't want to figure out how to get my C program communicating with MySQL.. All docs are there, but the time it takes to all figure it out is such a waste if you already know how to do it in PHP.. I did think about trying to find a small C program and alter this to write the scanned data to file and run a Cron Job every minute that starts a PHP script which looks for this file and sucks it in.. This would also work, but if it isn't necessary I would rather do it directly throught PHP.. I was thinking, before I try anything I would first think how the code would look like.. I thought that starting with something like below is the bare minimum ?? $fp = fopen ("/dev/ttyS0", "r"); while (!feof($fp)) {echo fgets ($fp,128); } Only thing I don't understand/know is if you are polling the COM port the whole time in the above example.. (Or is /dev/ttS0 a small unix layer which unix handles by retrieving all data from serial devices and then stores this up to XXXX bytes in a buffer and which means that I only have to check if there is data in /dev/ttyS0... If this is not the case it would be very hard in PHP to write some code which prevents you from not loosing any serial data when the PHP code is processing scanned data.. Any suggestions on the code greatly appreciated... Bye bye David > Yeah it is known that UNIX treats everything as files, so I believe it is > possible to use fopen to connect to your serial port. And then using pack() > to pack your data into a binary string before sending it to the serial port. > Have you considered alternatives for developing the app for your barcode? I > guess there must be a reason why you would want to do it via PHP, rather > than maybe write a Win32 prog or Linux prog. :) > To: "Perry Loh" <skeevs@crosswinds.net> > Cc: <php-general@lists.php.net> > Sent: Tuesday, November 07, 2000 2:02 AM > Subject: Re: [PHP] PHP to read a COM port?? > > > Hi Perry.. > > > > Thanks for your mail, for you and everyone else just a small word how > > everything works with a barcode scanner: > > > > Basically this barcode scanner (and 99% of all other serial barcode > > scanners) work like this: > > > > To setup the barcode scanner you use the manual which consists of special > > barcodes with which you > > can change the parameters in the barcode (scanning speed/type of barcodes > > etc..) by scanning these barcodes these parameters are changed.. > > > > When setup the way you want you scan the barcode and this data is send to > > the computer via the serial cable.. > > You can view these results via a standard modem program like minicom in > unix > > or hyperteminal in windows.. (Most scanners connect to the computer at a > > speed of 9600 baud) > > > > If you would be able to send data to the modem, the respones that come > back > > (O.K, NO CARRIER. NO DIALTONE) basically are the same data as which the > > scanners sends back.. > > (Only he sends the contents of the barcode) > > > > So if you would be able to send commands to a modem and read the results > > back via PHP, you would have enough code to read the barcode.. > > > > I first thought about using a old windows machine with barcode software > > which writes all scanned barcodes to a file on a directory on my linux > > machine which is shared with Samba.. :-) > > And then I run PHP every few minutes to look if there are new files to be > > processed.. :-) > > > > I am not that experienced with unix, but I always hear that do everything > > with file pointers.. This is how I thought of the idea to use the PHP > fopen > > command to directly read from the barcode scanner via > > /dev/ttyS0.. > > > > What I have already succeeded in is to use the PDF functions in PHP to > > generate a PDF file with embedded barcodes.. > > This PDF contains a order made through internet. These are printed out and > > should then be scanned with the barcode reader so the computer knows they > > have been processed.. :-) > > > > Here comes my problem on getting the data from the scanner... > > > > If someone has already done something like this in PHP I would like to > hear > > it very much.. I do see that PHP has got some functions for windows NT to > > communicate with the serial ports.. > > These are not available in PHP so I will probably be right by thinking of > > using fopen on /dev/ttySxx.. > > > > Can anybody help..? > > > > Bye Bye > > David > > > > PS: Perry, thanks for replying, the easiest way to try some stuff would > > probably be by using a modem.. I only have no idea how you can write to > the > > modem. > > > > > This is quite interesting. I wish I could do some testing myself, but I > > > don't have a barcode scanner..What other serial port devices do you > think > > we > > > could mess with ? > > > > > > Regards, > > > > > > Perry Loh > > > Lead Developer, KlikInTouch.com > > > perryloh@klikintouch.com > > > - Just about Anywhere you go - > > > > > I have a serial barcode scanner which I would like to use with PHP to > > enter > > > Barcode data and store this with PHP > > > in a MySQL database.. > > > > > > This barcode scanner is serial and I would like to know if there is a > > > possibility to read the serial port with PHP.? > > > > > > I found the following postings on internet: > > > > > > >I recently received some barcode scanners that plug directly into a > > serial > > > port, such as tty/b01. I read that I can >disable getty, make a node and > > > open the tty as an input file, but I don't know how to identify the > > > file/pointer/??? to >open the file. Can anyone help with a simple C > > language > > > program? thanks > > > > > > And this is the answer > > > >I got this one from a consultant...when reading directly from a port > for > > a > > > barcode scanner/decoder, simply fopen >the device name, such as ttyb16, > > but > > > remember to fopen in the "rb" mode. "b" denotes binary. Use stty > > > to set > > the > > > >speed and parameters of the port. > > > > > > Is something like this possible with PHP..? > > > My question, if I setup the above (with fopen(/dev/tty01) ??) what > should > > I > > > do to let PHP stop reading the Serial port and continue after a barcode > is > > > scanned.? (If I don't do anything he will probably just wait for more > > data) > > > > > > Barcodes begin with a * character and also end with one.. Is is possible > > to > > > do some kind of while loop till I detect the * character for a second > > time? > > > > > > If I anyone has experience on reading a serial port under unix I would > > > greatly appreciate help. I am used to windows and what I understand is > > that > > > you can use file pointers to all kinds of devices under Linux/Unix.. > > > > > > Thanks in advance.. > > > (PS: Please also send a copy to my email when replying) > > > > > > David > > > > > > > > > > > > > > > >

« previous php.general (#24283) next »