It's pretty much just reading incoming data from the serial port and then inserting it into a MySQL DB.
The MySQL part is okay as far as I can tell, it's just the serial comms I need to sort out. I'm not experienced with perl either *cough* so I've taken the clearest way of handling that side of things. Put the serial comms I use below.
my $loSerial = new Device::SerialPort (PORT);
#Configure the port.
$loSerial->baudrate(BAUD) || (Log("ERROR - ERR06 Failed setting baud rate.") && die("ERROR - ERR06 Failed setting baud rate."));
$loSerial->parity(PRTY) || (Log("ERROR - ERR05 Failed setting parity.") && die("ERROR - ERR05 Failed setting parity."));
$loSerial->databits(DBTS) || (Log("ERROR - ERR04 Failed setting data bits.") && die("ERROR - ERR04 Failed setting data bits."));
$loSerial->stopbits(SBTS) || (Log("ERROR - ERR03 Failed setting stop bits.") && die("ERROR - ERR03 Failed setting stop bits."));
$loSerial->handshake(FLOW) || (Log("ERROR - ERR02 Failed setting flow control.") && die("ERROR - ERR02 Failed setting flow control."));
if (open(DEV, "< ".PORT.""))
{
my $loInfo= "";
#Read incoming data.
while($_ = <DEV>)
{
$loInfo .= $_;
if (length($loInfo) >= MSGLEN)
{
#Process the info and store it in the database.
Process(substr($loInfo, 0, MSGLEN));
$loInfo = substr($loInfo, MSGLEN);
}
sleep(0.1);
}
} else
{
Log("ERROR - ERR01 Can't open ".PORT.": $!") && die("ERROR - ERR01 Can't open ".PORT.": $!");
}