The following script demonstrates USB IO. The connected device is an MCA (AXAS, FastComTec interface).
#!/usr/bin/perl
#
# [root@haso111m temp]# stty -F /dev/ttyUSB0 -a
# speed 921600 baud; rows 0; columns 0; line = 0;
# intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>;
# eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;
# werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;
# -parenb -parodd cs8 hupcl -cstopb cread clocal -crtscts
# ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl -ixon -ixoff
# -iuclc -ixany -imaxbel -iutf8
# -opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
# -isig -icanon -iexten -echo echoe -echok -echonl -noflsh -xcase -tostop -echoprt
# -echoctl -echoke
#
use strict;
use Fcntl;
use POSIX qw(:termios_h);
sysopen(USB, "/dev/ttyUSB0", O_RDWR) || die "failed to open \n";
my $term = POSIX::Termios->new();
$term->getattr( fileno(USB)) || die("Failed getattr: $!");
my $echo = $term->getlflag();
$echo &= ~ECHO;
$echo &= ~ECHOK;
$echo |= ECHOE;
$term->setlflag( $echo);
$term->setcflag( &POSIX::CS8 |
&POSIX::CREAD |
&POSIX::CLOCAL |
&POSIX::HUPCL);
$term->setiflag( &POSIX::IGNBRK);
$term->getattr( fileno(USB)) || die("Failed getattr: $!");
$term->setospeed( 4103);
$term->setispeed( 4103);
$term->setattr( fileno(USB), TCSANOW) || die "Failed setattr: $!";
my $com = "?\015\012"; # help
my $buffer = "";
my $cuffer = "";
syswrite(USB, $com, length( $com)) or die " write failed \n";
my $rin = my $win = my $ein = "";
vec( $rin, fileno( USB), 1) = 1;
$ein = $rin | $win;
my $nfd = select( $rin, $win, $ein, 0.1);
while( $nfd)
{
sysread(USB, $buffer, 1000);
$cuffer .= $buffer;
$nfd = select( $rin, $win, $ein, 0.1);
}
print " $cuffer \n";
close( USB);
Normally the function $term->setospeed() is invoked this
way: $term->setospeed( &POSIX::B9600).
However, the higher baud rates are not defined in the
POSIX module yet. Still these speeds can be selected by
supplying some code, e.g. 921600 bits per second
is specified by $term->setospeed( 4103).
The table 12.1 displays all codes.