K
Kean
I have a Barcode-Scanner wich is connected to a com-port. When i start
the Hyperterminal and set the comport, i see the data that sends the
Scanner when i scan a label. This works fine.
Yet i will use the Scanner with this PerlScript:
use Win32::API;
use Win32::SerialPort;
my $Port = 'com7';
$Configuration_File_Name = 'config.sys';
$handle = new Win32::SerialPort ($Port, $quiet)
|| die "Can't open $PortName: $^E\n";
$handle->baudrate(9600);
$handle->parity('none');
$handle->databits(8);
$handle->stopbits(1);
$handle->handshake('rts');
$handle->write_settings || die "Can't initialize Handle\n";
$handle->save($Configuration_File_Name)
|| warn "Can't save $Configuration_File_Name: $^E\n";
$handle->restart($Configuration_File_Name)
|| warn "Can't reread $Configuration_File_Name: $^E\n";
open (LOG,">barcode.log") || die "Can't open 'barcode.log': $!\n";
while (1) {
my $reply = HardwareReply($handle,100);
print LOG "> Rx: $reply\n";
}
close LOG;
sub HardwareReply {
my ($Port,$timeout) = @_;
$Port->purge_all;
my $in;
my $max = 500;
my $count = 0;
my $return;
my $to_read;
my $readcount;
my $input;
my $counter=0;
$timeout ||= '100';
do {
select(undef,undef,undef, 0.1);
$to_read = $max - $count;
($readcount, $input) = $Port->read($to_read);
$in.=$input;
$count+=$readcount;
if ( $in=~/[\n\r]$/ ) {
$return=$in;
}
$counter++;
} while ((!$return) && ($counter<$timeout));
$return=~s/[\r\n]//g;
return $return;
}
The Script opens the comport, but the sub HardwareReply doesnt work.
Have anyone an idea what the problem is?
Thanks
the Hyperterminal and set the comport, i see the data that sends the
Scanner when i scan a label. This works fine.
Yet i will use the Scanner with this PerlScript:
use Win32::API;
use Win32::SerialPort;
my $Port = 'com7';
$Configuration_File_Name = 'config.sys';
$handle = new Win32::SerialPort ($Port, $quiet)
|| die "Can't open $PortName: $^E\n";
$handle->baudrate(9600);
$handle->parity('none');
$handle->databits(8);
$handle->stopbits(1);
$handle->handshake('rts');
$handle->write_settings || die "Can't initialize Handle\n";
$handle->save($Configuration_File_Name)
|| warn "Can't save $Configuration_File_Name: $^E\n";
$handle->restart($Configuration_File_Name)
|| warn "Can't reread $Configuration_File_Name: $^E\n";
open (LOG,">barcode.log") || die "Can't open 'barcode.log': $!\n";
while (1) {
my $reply = HardwareReply($handle,100);
print LOG "> Rx: $reply\n";
}
close LOG;
sub HardwareReply {
my ($Port,$timeout) = @_;
$Port->purge_all;
my $in;
my $max = 500;
my $count = 0;
my $return;
my $to_read;
my $readcount;
my $input;
my $counter=0;
$timeout ||= '100';
do {
select(undef,undef,undef, 0.1);
$to_read = $max - $count;
($readcount, $input) = $Port->read($to_read);
$in.=$input;
$count+=$readcount;
if ( $in=~/[\n\r]$/ ) {
$return=$in;
}
$counter++;
} while ((!$return) && ($counter<$timeout));
$return=~s/[\r\n]//g;
return $return;
}
The Script opens the comport, but the sub HardwareReply doesnt work.
Have anyone an idea what the problem is?
Thanks