D:\PerlDev\Exercise>perl exSerialPort.pl
Can't locate loadable object for module Win32::API in @INC (@INC contains: c:/Pe
rl/lib c:/Perl/site/lib .) at c:/Perl/site/lib/Win32API/CommPort.pm line 5
Compilation failed in require at c:/Perl/site/lib/Win32API/CommPort.pm line 5.
BEGIN failed--compilation aborted at c:/Perl/site/lib/Win32API/CommPort.pm line
5.
Compilation failed in require at c:/Perl/site/lib/SerialPort.pm line 4.
BEGIN failed--compilation aborted at c:/Perl/site/lib/SerialPort.pm line 4.
Compilation failed in require at exSerialPort.pl line 6.
BEGIN failed--compilation aborted at exSerialPort.pl line 6.作者: Chennysky 时间: 2006-01-09 10:55
#c:/Perl/site/lib/Win32API/CommPort.pm
package Win32API::CommPort;
读数据时也是这样
如何才可以将所有数据无丢失的读出呢?
继续努力中!
加油哦作者: peakgod 时间: 2006-01-13 11:08 标题: 回复 5楼 Chennysky 的帖子 看你一个人,兄弟我来陪一程!
虽然解答不了你的问题,但是可以在你的问题中学习!作者: Chennysky 时间: 2006-01-13 13:30 标题: 谢谢! #!C:\Perl\bin
# driverreg.pl
# This is a Perl program for Driver Regression Test with Serial Port.
# Run on Windows OS.
#Define title of the software.
format SYSNAME=
========================================
Driver Regression Test System [Ver 1.0]
========================================
.
use File::Copy;
use Win32::SerialPort;
use Time::HiRes qw /usleep/; #Sleep for some time less than 1 second.
#use strict;
# Define some values
my $drvCaseFile = "D:/PerlDev/DrvTest/drvcase.txt";
my $drvTestReport = "D:/PerlDev/DrvTest/DrvTestReport.txt";
my $portCom1;
my $Configuration_File_Name = "D:/PerlDev/DrvTest/Com1Port.cfg";
# Start test.
$| = 1; # Update before write or read.
$~=SYSNAME; #Display the title.
write;
if (-e $drvTestReport) #Delete the report file if exist.
{
print "Exist file $drvTestReport.";
system ("rm -f $drvTestReport");
}
# SerialPort Constructor
unless ($portCom1 = Win32::SerialPort->new ('com1')) {
printf "Could not open port COM1: $^E\n";
exit 1;
}
# Set parameters
$portCom1->user_msg(ON);
$portCom1->baudrate(115200) || die "bad baudrate";
$portCom1->databits(8) || die "bad databits";
$portCom1->parity('none') || die "bad parity";
$portCom1->stopbits(1) || die "bad stopbits";
# After new, must check for failure
$portCom1->write_settings || undef $portCom1;
print "Can't change Device_Control_Block: $^E\n" unless ($portCom1);
print "write_settings done\n";
# Before using start, restart, or tie
$portCom1->save($Configuration_File_Name)
|| warn "Can't save $Configuration_File_Name: $^E\n";
my ($BlockingFlags, $InBytes, $OutBytes, $LatchErrorFlags) = $portCom1->status
|| warn "could not get port status\n";
print "The value of \$BlockingFlags is $BlockingFlags\n";
$portCom1->lookclear;
undef $portCom1;
$portCom1 = tie (*FH, 'Win32::SerialPort', $Configuration_File_Name)
|| die "Can't tie: $^E\n"; ## TIEHANDLE ##
open (CASEFILE, "<$drvCaseFile")||die "$!\nCannot open case file $drvCaseFile\n";
my @comLineArr = <CASEFILE>;
close (CASEFILE);
print "@comLineArr\n";
open (REPORTFILE, ">>$drvTestReport")
||die "$!\nCannot write to report file $drvCaseFile\n";
print (REPORTFILE " This Is The Driver Test Report\n");
foreach my $comLineOrg (@comLineArr)
{
my $startTime = time;
chomp ($comLineOrg);
print "The command line is: $comLineOrg!\n\n";
print (REPORTFILE "\n\n========== Test case:$comLineOrg ==========\n");
@comLine = split (//, $comLineOrg); #Get the character one by one
# sleep 1;
# print "Run to here1\n";
INPUTCMD:
sleep 1;
print "The command by character is: @comLine!\n\n";
foreach my $comChar (@comLine)
{
syswrite (FH, $comChar); ## WRITE ##
usleep (10000);
}
$enterChar = "\r";
syswrite (FH, $enterChar, length($enterChar), 0); ## WRITE ##
my @com1OutArr;
for (my $i = 0;;$i++)
{
$lineFromCom1 = <FH>;
if ($lineFromCom1 ne "")
{
print "The line from COM1 $i: $lineFromCom1";
open (REPORTFILE, ">>$drvTestReport") ||die "$!\nCannot write to report file $drvCaseFile\n";
print (REPORTFILE "$lineFromCom1");
chomp ($lineFromCom1);
chop ($lineFromCom1);
goto INPUTCMD if($lineFromCom1 =~ "Invalid command");
@com1OutArr = split (/>/, $lineFromCom1);
}
my $curTime = time;
my $testPeriod = $curTime - $startTime;
last if (($lineFromCom1 eq $comLineOrg)
||($lineFromCom1 =~ "ss")
# ||($com1OutArr[$#com1OutArr] eq $comLineOrg)
||($com1OutArr[$#com1OutArr] =~ "End of mp3.")
||(300 <= $testPeriod));
}
}
close (REPORTFILE);
close FH || warn "Close failed\n"; ## CLOSE ##
undef $portCom1;
untie *FH; ## DESTROY ##