Question...(advice requested) 
Author Message
 Question...(advice requested)

My question is...I will have two serial ports to deal with.  The serial
ports will be either /dev/tty00 (user interaction) and /dev/tty01
(spewing messages).  I would like to be able to configure both of the
serial ports based on speed (9600 or 11520), data bits (7 or 8), stop
bits (1 or 2) and parity (none, even, odd).  Below is some code that
I've written to attempt to do this.  At the bottom of the serial
subroutine, you'll see a print statement, where I'm looking at what I
would be calling if I called "stty" command.

My question is, there's got to be a quicker and easier way of doing
this.  If so, any suggestions?  Also, should I use the stty command, or
{*filter*}around with the termios settings?  If using the stty command, how
can I call it to affect both serial ports?

Thanks,

.mitch

sub serial
{
        my $view_port;
        my $speed;
        my $data_bits;
        my $stop_bits;
        my $parity;
        my $pflag;
        my $sflag;

        do {
                $view_port = &get_it("Set port to monitor input ?",
"/dev/tty00");
        } until ($view_port =~ /^\/dev\/tty0[0-1]/);
        do {
                $speed = &get_it("Set speed of serial ports:", "9600");
        } until ($speed =~ /^9600/ || $speed =~ /^11520/);

        do {
                $data_bits = &get_it("Set the data bits:", "8");
        } until ($data_bits =~ /^8/ || $data_bits =~ /^7/);

        do {
                $stop_bits = &get_it("Set the stop bits:", "1");
        } until ($stop_bits =~ /^1/ || $stop_bits =~ /^2/);

        do {
                $parity = &get_it("Set the parity:", "none");
        } until ($parity =~ /^none/i || $parity =~ /^even/i || $parity
=~ /^odd/i);

        if ($stop_bits == 1) {
                $sflag = "-cstopb";
        } else { $sflag = "cstopb"; }

        if ($parity =~ /^even/i) {
                $pflag = "-parodd";
        }
        elsif ($parity =~ /^odd/i) {
                $pflag = "parodd";
        }
        else {
                $pflag = "-parenb";
        }
        print "stty speed $speed $pflag cs$data_bits $sflag\n";

Quote:
}

Here's my "get_it" subroutine:

sub get_it {

        &show( "$wh [$def] --->");
        my($an) = &get_line;
        $an = $def if ($an =~ /^\s*$/);
        $an;

Quote:
}



Sat, 01 Dec 2001 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. usersub advice requested

2. PERL/SOCKETS/Network advice requested

3. Request Peformance Advice

4. Request Advice for Proper Case of String

5. Sys Adminy Advice Requested

6. Advice using LWP::Debug on HTML::Request::Common POST problem

7. Del/Sort Flat Text File - Advice Requested

8. General ActivePerl questions and advice needed

9. HTTP Request question

10. HTTP::Request::Form question

11. simple request/question

12. HTTP::Request question ???

 

 
Powered by phpBB® Forum Software