I'm trying to get a script to save a barcode scanner's output to a log file. 
I've been trying to use Win32::SerialPort and my script has begun to slip into a 
"grasping at straws" state of disarray. I found a script by Bruce S. Garlock 
that I thought would do about what I wanted. Here's what it's degenerated into:

use Win32::SerialPort;
# use strict;
use warnings;

$LOGDIR    = 'c:\perl\scripts';              # path to data file
$LOGFILE   = "router.log";            # file name to output to
$PORT      = "COM2";          # port to watch

#
#
# Serial Settings
#
#

$ob = Win32::SerialPort->new ($PORT) || die "Can't Open $PORT: $!";
$ob->baudrate(9600)   || die "failed setting baudrate";
$ob->parity("none")    || die "failed setting parity";
$ob->databits(8)       || die "failed setting databits";
$ob->handshake("none") || die "failed setting handshake";
# $ob->write_settings    || die "no settings";

#
# Send a string to the port
#
#

#$pass=$ob->write("AT");
#sleep 1;

#
# open the logfile, and Port
#

open(LOG,">>${LOGDIR}/${LOGFILE}")
    ||die "can't open smdr file $LOGDIR/$LOGFILE for append:\n";

#open(DEV, "<$PORT") 
#    || die "Cannot open $PORT: $_";

$ob = tie (*BIFF, 'Win32::SerialPort')
       || die "Can't tie: $^E\n";

select(LOG), $| = 1;      # set nonbufferd mode

#
# Loop forver, logging data to the log file
#

while($_ = <BIFF>){        # print input device to file
    print LOG $_;
}

undef $ob;

This script was originally using Device:SerialPort. The two commented lines 
above the tie statement are the original ones that made perl complain.
The error message I get now is: "Can't tie:"
I REALLY don't understand the docs for this module and can't find any examples 
of reading from a port. I'm doing the tie incorrectly but don't know what else 
to try. I don't have any experience with tied file handles... shoes and women 
but not file handles.
Any help you can give me would be appreciated.

Ron W

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to