Getting ASCII text into Mysql

M

Thread Starter

mike d

I have a UNIX based vision system that outputs a ASCII text string every time a read cycle is performed, the text is also followed by a <CR> character. I want to get this text string and place it into a Mysql database that is running on a separate Win2000 machine. The text string is outputted at the serial port on the Unix machine (9600 N 8 1). I need to add some extra fields to the ASCII string in order to have a useful bit of data I want to add an Index_ and a Timestamp_ , from there my task is plain sailing but its getting it in that’s the problem. I wanted to try PHP but not sure if it will handle serial ports that well.
Any help would be greatly appreciated.
 
<p>ah yes php4
in c on linux i would use ioctl() on the opened
/dev/ttyS0 (for COM1:) but in php-
here is a snippet i found on php's forum:
jared at dctkc dot com
22-Apr-2002 12:33
<pre>
?php
// HOW TO USE PHP TO WRITE TO YOUR SERIAL PORT: TWO METHODS
$serproxy=true;
if ($serproxy) {
// Use this code in conjunction with SERPROXY.EXE
// (http://www.lspace.nildram.co.uk/freeware.html)
// which converts a Serial stream to a TCP/IP stream
$fp = fsockopen ("localhost", 5331, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)";
} else {
$e = chr(27);
$string = $e . "A" . $e . "H300";
$string .= $e . "V100" . $e . "XL1SATO";
$string .= $e . "Q1" . $e . "Z";
echo $string;
fputs ($fp, $string );
fclose ($fp);
}
} elseif ($com1) {
// Use this code to write directly to the COM1 serial port
// First, you want to set the mode of the port. You need to set
// it only once; it will remain the same until you reboot.
// Note: the backticks on the following line will execute the
// DOS 'mode' command from within PHP
`mode com1: BAUD=9600 PARITY=N data=8 stop=1 xon=off`;
$fp = fopen ("COM1:", "w+");
if (!$fp) {
echo "Uh-oh. Port not opened.";
} else {
$e = chr(27);
$string = $e . "A" . $e . "H300";
$string .= $e . "V100" . $e . "XL1SATO";
$string .= $e . "Q1" . $e . "Z";
echo $string;
fputs ($fp, $string );
fclose ($fp);
}
}
?
</pre>
 
H

Higginbotham Ricky \(External\)

I recommend Python. There are several free modules done by different people to handle serial ports with python, along with connections to Mysql and most other databases.

google "python serial port" and you'll get several hits. You'll also want pythonwin if your running on a windows machine. I think it comes with some serial port support, but I don't think there very much in the way of documentation on how to use it. There is a module to wrap it and make it easier to use (uspp i think), but I haven't used it, I haven't had any need to get data from a serial port.

Richard Higginbotham
 
B

Blaine Hilton

Good code example, but is there a way to access a serial port using Serproxy, and using a setting to turn on xon? Also this will write to the serial port, but to get data INTO mySQL can you also read from Serproxy?

--
Thanks in advance
Blaine Hilton
http://www.blainehilton.com/
 
G

Greg Goodman

> Good code example, but is there a way to access
> a serial port using Serproxy, and using a
> setting to turn on xon?

Serproxy's handling of the serial port currently affects only the baud, parity, stopbits and databits. There's no code in it to set XON/XOFF or other line control parameters. It's a pretty trivial change, though, and the software is GPL; feel free to modify the code to support any options you want. (You want to focus on the sio_open() routine in sio.c, and modify the termios.c_flag with the IXON/IXOFF constants.)

> Also this will write to the serial port, but to
> get data INTO mySQL can you also read from
> Serproxy?

Yes. Serproxy is a bidirectional redirector. Reading and writing a socket effectively reads/writes a serial port.

Regards,

Greg
 
Top