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
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.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; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Accessing serial ports under Windows
by chromatic (Archbishop) on Jun 17, 2000 at 23:43 UTC | |
by Odud (Pilgrim) on Jun 18, 2000 at 00:00 UTC | |
(jcwren) RE: Accessing serial ports under Windows
by jcwren (Prior) on Jun 17, 2000 at 23:50 UTC | |
Re: Accessing serial ports under Windows
by Anonymous Monk on Jun 16, 2008 at 21:08 UTC | |
by Odud (Pilgrim) on Jul 22, 2008 at 18:59 UTC | |
RE: Accessing serial ports under Windows
by Odud (Pilgrim) on Jun 18, 2000 at 00:02 UTC |
Back to
Seekers of Perl Wisdom