Here's a little script to get you up and running. Note that I used a tty rather than a ttyUSB---you can use any tty, stty, or ttyUSB. On my system, the ttyUSB is usbdev.
#!/usr/bin/perl -l use strict; use warnings; use Device::SerialPort qw( :PARAM :STAT 0.07 ); $| = 1; my $port = '/dev/tty24'; my $conf = '~/.conf'; my $ob = Device::SerialPort->new($port, 1) || die "Can't open $port: $!"; my $STALL_DEFAULT = 10; my $timeout = $STALL_DEFAULT; my $arb = $ob->can_arbitrary_baud; my $data = $ob->databits(8); my $baud = $ob->baudrate(115200); my $parity = $ob->parity("even"); my $hshake = $ob->handshake("rts"); my $stop = $ob->can_stopbits; my $rs = $ob->is_rs232; my $total = $ob->can_total_timeout; $ob->stopbits(1); $ob->buffers( 4096, 4096 ); $ob->can_baud; $ob->can_databits; $ob->can_dtrdsr; $ob->can_handshake; $ob->can_parity_check; $ob->can_parity_config; $ob->can_parity_enable; $ob->can_rtscts; $ob->can_xonxoff; $ob->can_xon_char; $ob->can_spec_char; $ob->can_interval_timeout; $ob->can_ioctl; $ob->can_status; $ob->can_write_done; $ob->can_modemlines; $ob->can_wait_modemlines; $ob->can_intr_count; $ob->write_settings; print "A = $arb\n", "B = $baud\n", "D = $data\n", "S = $stop\n", "P = $parity\n", "H = $hshake\n", "R = $rs\n", "T = $total"; $ob->write_drain; $ob->close; undef $ob;

In reply to Re: Best way to read/write to a serial port by Khen1950fx
in thread Best way to read/write to a serial port by garlinto

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.