The above replies were very helpful.
I have tried the following code with the wires hooked up as instructed.
But it aways warns "Port is blocked".
I checked BIOS and serial is indeed COM1. It writes the config file.
use Win32::SerialPort;
$PortName = "COM1";
$quiet = 0;
$Configuration_File_Name = "c:/com1_config.txt";
$PortObj = new Win32::SerialPort ($PortName, $quiet)
|| die "Can't open $PortName: $^E\n"; # $quiet is optional
$PortObj->user_msg(ON);
$PortObj->databits(8);
$PortObj->baudrate(1200);
$PortObj->parity("none");
$PortObj->stopbits(1);
$PortObj->handshake("none");
$PortObj->buffers(4096, 4096);
$PortObj->write_settings || undef $PortObj;
$PortObj->save($Configuration_File_Name);
$PortObj->baudrate(300);
$PortObj->restart($Configuration_File_Name); # back to 1200 baud
($BlockingFlags, $InBytes, $OutBytes, $LatchErrorFlags)
= $PortObj->status
|| warn "could not get port status\n";
if ($BlockingFlags) { warn "Port is blocked"; }
if ($BlockingFlags & BM_fCtsHold) { warn "Waiting for CTS"; }
if ($LatchErrorFlags & CE_FRAME) { warn "Framing Error"; }
($count_in, $string_in) = $PortObj->read($InBytes);
print "Count: $count_in \n";
print "String: $string_in \n";
$PortObj->close || die "failed to close";
undef $PortObj;
The written config file looks like this...
Win32::SerialPort_Configuration_File -- DO NOT EDIT --
COM1
CFG_1,none
eol,10
clear,-@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
+@@@@@@@@@@@@@-
RCONST,0
istrip,0
CFG_2,none
XOFFCHAR,19
PARITY_EN,0
WCONST,200
intr,3
U_MSG,1
STOP,1
XONLIM,2048
erase,8
XONCHAR,17
BINARY,1
RTOT,0
echonl,0
XOFFLIM,512
icrnl,0
inlcr,0
READBUF,4096
igncr,0
EOFCHAR,0
WRITEBUF,4096
RINT,4294967295
ocrnl,0
bsdel,
opost,0
echoke,1
PARITY,none
HNAME,localhost
echoctl,0
CFG_3,none
EVTCHAR,0
icanon,0
isig,0
HADDR,0
E_MSG,0
DATA,8
DVTYPE,none
echo,0
quit,4
s_eof,26
s_kill,21
ERRCHAR,0
onlcr,1
ALIAS,COM1
HSHAKE,none
DATYPE,raw
echok,1
echoe,1
BAUD,1200
WTOT,10
Once I get this working I'll write a howto and maintain it online with my several others, and link to it with a final comment here. Thanks again.
|