打开/dev/ttyX的时候没问题,但是以写方式打开/dev/ttyACM0(我的N73,作为猫连接上了) 的时候,就阻塞了(已经有一个打开的读句柄,不知道这个东西是不是叫句柄呢?)
有没有办法同时读写呢?
代码: 全选
#!/usr/bin/perl
#################################################
## SMS Sender V0.01 ##
## Written by Proton 2009-2-8 21:22:14 ##
#################################################
#For learning purpose
#Going to master perl
$tty="/dev/ttyACM0"; #tty used to communicate with my N73 ^_^
#$tty="/dev/tty8"; #for debug
if($#ARGV<1) #Showing help
{
print <<EOF;
Proton's SMS Sender V0.01
Usage $0 [Phone number] [Text]
EOF
exit(0);
}
#Get info
($pn,@message) = @ARGV;
$message=join(",",@message);
die ("Incorrect phone number!\n") unless $pn =~ /^(\+86)?\d{11}$/;
$pn="+86$pn" unless $pn =~ /^\+86/;
#Begin sending message
open(TTY,$tty) || die("Unable to open $tty!\n");
open(TTYO,">$tty") || die("Unable to open write handle of $tty!\n"); ## 在这一句阻塞
do
{
$r=<TTY>;
print $r;
} while not ($r =~ /^OK$/); #wait for the OK state
print TTYO ("AT+CMGF=1\n");
sleep 0.2;
$r = <TTY>;
die('Error while sending instruction AT+CMGF=1') unless $r =~ /^OK$/;
print TTYO ("AT+CMGS=\"$pn\"\n");
sleep 0.5;
#die("Error while sending instruction AT+CMGS=\"$pn\""); #Don't how to handle it... no error recovery code for now.
print TTYO ("$message\x1A\n");
print "Message sent!\n";
sleep 0.5;
close(TTY);
close(TTYO);