use Win32::SerialPort; use strict; use warnings; my $Port = "COM9"; # port to watch my $Baud=15200; my $PortObj = Win32::SerialPort->new ($Port,1) || die "Can't Open $Port: $!"; $PortObj->write_settings || undef $PortObj; print "Can't change Device_Control_Block: $^E\n" unless ($PortObj); $PortObj->baudrate($Baud) || die "failed setting baudrate to $Baud"; $PortObj->parity("none") || die "failed setting parity"; $PortObj->databits(8) || die "failed setting databits"; $PortObj->handshake("none") || die "failed setting handshake"; my $rtn=$PortObj->write("help"); print $rtn; sleep 1; print "DONE\n"; undef $PortObj; exit; #### #!perl $port="COM9"; sysopen(COM,$port,O_RDWR) || die "Can't open $port $^E"; $length=1024; while(1){ print ">"; $cmd=; if($cmd=~/^(x|q|exit|quit)$/is){last;} $cmd =~s/[\r\n]+$//; print "Cmd: $cmd\n"; my $packcmd=pack("A*",$cmd); print "Send: $packcmd\n"; syswrite(COM,$packcmd); #sends $string to COM1 print "Reading...\n"; #code to read data from port sysread(COM,$buf,$length); #read $length bytes print "Buf: $buf\n"; $received = unpack("C*",$buf); #unpack them print "Receive: $received\n"; } exit;