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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.