5 use Device::SerialPort;
6 use Data::Dump qw(dump);
8 my $device = $ENV{DEVICE} || '/dev/ttyUSB0';
10 my $port = Device::SerialPort->new( $device ) || die "$device: $!";
11 $port->baudrate(115200) || die "fail $device baudrate";
12 $port->parity("none") || die "fail $device parity";
13 $port->databits(8) || die "fail $device databits";
14 $port->stopbits(1) || die "fail $device stopbits";
15 $port->handshake("rts") || die "fail $device handshake";
17 $port->write_settings || die "no $device settings";
23 $port->read_char_time(3000); # 5 s char timeout
24 $port->read_const_time(3000); # 1 s read timeout
26 while ( my $drain = $port->input ) {
27 warn "# drain $drain\n# /drain\n";
31 warn "## using $device\n";
34 my ($cmd,$message) = @_;
35 print STDERR ">>> $cmd >>> $message\n";
36 $port->write("$cmd\r");
37 # $port->write_done(1); # flush
39 my $ret = $port->read(1);
41 while ( my $c = $port->input ) {
42 print STDERR "<<< ",dump($ret . $c), $/;
44 # last if $c =~ m/^OK\r/;
46 goto again unless $ret =~ s/\r\n(OK|ERROR)\r\n$//s || warn "ERROR: can't find OK or ERROR status!\n";
48 print "$cmd [$message] = $ret\n";
52 c 'ATE0' => 'echo off';
57 c 'AT+CGMI' => 'manufacturer';
59 c 'AT+CGMM' => 'model';
61 c 'AT+CGMR' => 'revision';
63 c 'AT+CGSN' => 'serial';
65 c 'AT+GCAP' => 'capabilities';
67 c 'AT+CIMI' => 'IMSI';
69 c 'AT+CNUM' => 'MSISDN';
71 #c 'AT+COPS=?' => 'operators'; # times out
73 c 'AT+CLCK=?' => 'facility lock';
75 c 'AT^HWVER' => 'hardware version';
77 c 'AT^CVOICE?' => 'is voice enabled?';
79 c 'AT^DDSETEX=?' => 'voice output';
81 c 'AT^SYSINFO' => 'sys info';
84 $port->close || die "can't close port $!";
86 warn "## $device closed\n";