Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Unusual error in Win32::SerialPort (Missing REQUIRED setting for BAUD)

by BronzeWing (Monk)
on May 20, 2003 at 15:33 UTC ( #259489=perlquestion: print w/replies, xml ) Need Help??

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

Greetings, fellow monks.
I'm having an unusual (judging by the google results) problem with the Win32::SerialPort module. Following is the error, and the relevant code.

The error:

Missing REQUIRED setting for BAUD at Foo.pm line 35 write_settings failed, closing port at Foo.pm line 35 Failed to write settings at Foo.pm line 35.

The code: (Foo.pm lines 26-35)

my $Serial = new Win32::SerialPort('COM1') or die "Serial port died"; $Serial->baudrate(115200); $Serial->parity('none'); $Serial->databits(8); $Serial->stopbits(1); $Serial->handshake('none'); $Serial->buffers(4096, 4096); $Serial->error_msg(1); $Serial->user_msg(1); $Serial->write_settings || die "Failed to write settings";

The error shows up after booting the computer, and after using any program that communicates with the serial port at a different baud rate. I can only seem to resolve it by running something that opens the serial port at my preferred baud rate (115200), such as setting it in HyperTerminal.

Have any of you had any experience with this error? Can I do whatever HyperTerminal and the other programs do to make the baud rate valid? Am I just missing a line somewhere? Thanks.

-BronzeWing

Replies are listed 'Best First'.
Re: Unusual error in Win32::SerialPort (Missing REQUIRED setting for BAUD)
by Thelonius (Priest) on May 20, 2003 at 16:14 UTC
    Reading the code, I notice several things. (1) You can $Serial->user_msg(1), $Serial->error_msg(1), $Serial->debug(1) to get more error output.

    The most likely cause of your problem is that the CommProperties is not giving 115200 as an available baudrate. To see this, try print "baud rate: ", join(" ", $Serial->baudrate), "\n"; just after the new() and see what it says.

    You can override this after the new and before the baudrate by giving it some new ones:

    $Serial->{"_L_BAUD"}{115200} = 115200;
    Let us know if that helps.

      Perfect, it worked exactly as you said. Printing the available baud rates showed that 115200 was missing, and adding it to $Serial->{"_L_BAUD"} made everything work right. Thanks very much for your help!

      -BronzeWing

        Hi! I am also working on the Win32::SerialPort. I tried the debug method mentioned above and got this response back, baud rate: 115200 1200 38400 4800 2400 600 57600 19200 9600 300. What does that mean? Does that mean I can only use those baudrates in my perl script? Please let me know. Thanks.
      I experienced the same error but it seems not related to what you discussed. I tried all your suggestions, but it did not work. Or at least partially did not work. The suggestion works if you have an unlisted baudrate. But the problem persists if you try to pass the baudrate by a variable and not by a code literal constant. That is: $Serial->baudrate(38400); # works $Serial->baudrate($baud_rate); # with $baud_rate containing 38400, does not work

        Can you post minimal code needed to reproduce the error? Also, what version of Win32::SerialPort and Perl are you using?

        Looking at some old code of mine that used Win32::SerialPort, my code did do something along the lines of $serial->baudrate($baudrate); and it did work.

        Out of curiosity, did you happen set the value of $baudrate like $baudrate = "38400";? If so, try changing that to be $baudrate = 38400; instead.

        Try $Serial->baudrate(0+$baud_rate).

        - tye        

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://259489]
Approved by Thelonius
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2023-01-30 07:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?