http://www.perlmonks.org?node_id=18663

Odud has asked for the wisdom of the Perl Monks concerning the following question:

Has anyone experience of using the serial ports under Windows? I'm trying to send commands to the modem and read the response. I thought that I'd read all the relevant bits in the open tutorial and I have the following code
use warnings; use Fcntl; my $tty = "COM3"; my $text = shift || "ATH0"; sysopen(COM,$tty,O_RDWR) || die "Can't open $tty $^E"; transmit("$text"); receive(); sub transmit { my $data = shift; $data .= "\r"; @ascii = unpack("C*",$data); print "transmit: [@ascii]\n"; syswrite(COM,$data); } sub receive { sysread(COM,$buf,4); @ascii = unpack("C*",$buf); print "receive: [@ascii]\n"; return $buf; }
However when I run the script it hangs on the sysread instead of returning O.K. as expected. I think the port is opening correctly, because when something else is using the port the open fails with an "Access denied" message.