Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,
I am working on Win32::SerialPort.
How can we automatically detect and set the baudrate to match the incoming baudrate?
We can obtain all the baudrate using the following code but i am unable to set it automatically:
use strict; use Win32::SerialPort; my $ob = Win32::SerialPort->new ('COM1') || die "Can't Open Port"; my @baud_array = $ob->baudrate; print "Baud Array contains @baud_array \n"; undef $ob;

Replies are listed 'Best First'.
Re: Setting baudrate automatically?
by dHarry (Abbot) on Jan 22, 2009 at 08:34 UTC
Re: Setting baudrate automatically?
by ig (Vicar) on Jan 22, 2009 at 16:52 UTC

    Detecting the incoming baudrate is difficult. There are RS232 analyzers that can do this but the RS232 interfaces in most PCs don't support automatic baud rate detection.

    You might be able to cycle through the baud rates until valid data is received. This assumes there is some way to validate the received data.

    The "getty" program that provides for login to *nix systems from serial ports typically supports a configurable selection of baud rates and switches the baud rate every time an RS232 "break" is received. The remote equipment (a dumb terminal with a human operator was common) must send the "break" to cause a baud rate switch. This depended on the human operator validating the data sent to the terminal (i.e. recognizing a login prompt) and pressing the "break" key until the login prompt appeared.