Skip Menu |

This queue is for tickets about the Win32-SerialPort CPAN distribution.

Report information
The Basics
Id: 25539
Status: open
Priority: 0/
Queue: Win32-SerialPort

People
Owner: Nobody in particular
Requestors: rbdavison [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: 0.19
Fixed in: (no value)



Subject: Baudrate is not being set correctly.
After setting the baudrate to 19200 in a program I found that I can't ready any data. I opened another program to connect to the same device and it worked fine and then my Perl program would after that too. When I printed the stty values I found that the baud rate was still set at 1200 baud form a clean start. After I connected with the other program it was set at 19200 baud. From a clean start I set the baud rate to 19200 then printed using Data::Dumper the output of stty and then the class. See attached log file. OS is Windows 2000 + latest SPs and patches. C:\>perl -v This is perl, v5.8.8 built for MSWin32-x86-multi-thread (with 50 registered patches, see perl -V for more detail) Copyright 1987-2006, Larry Wall Binary build 820 [274739] provided by ActiveState http://www.ActiveState.com Built Jan 23 2007 15:57:46 Perl may be copied only under the terms of either the Artistic License or the GNU General Public License, which may be found in the Perl 5 source kit. Complete documentation for Perl, including FAQ lists, should be found on this system using "man perl" or "perldoc perl". If you have access to the Internet, point your browser at http://www.perl.org/, the Perl Home Page. C:\>
Subject: log.txt
Download log.txt
application/x-download 12.5k

Message body not shown because it is not plain text.

Subject: Re: [rt.cpan.org #25539] Baudrate is not being set correctly.
Date: Mon, 19 Mar 2007 19:42:14 EDT
To: bug-Win32-SerialPort [...] rt.cpan.org
From: Bbirthisel [...] aol.com
Hi, In a message dated 3/19/2007 8:41:49 AM Eastern Daylight Time, bug-Win32-SerialPort@rt.cpan.org writes: Show quoted text
> After setting the baudrate to 19200 in a program I found that I can't > ready any data. > I opened another program to connect to the same device and it worked > fine and then my Perl program would after that too. > > When I printed the stty values I found that the baud rate was still set > at 1200 baud form a clean start. After I connected with the other > program it was set at 19200 baud. >
I have not heard of a problem like this for several years. When it last happened, it was after someone had used the same port for a serial mouse (some of which still run at 1200 baud), and the Windows mouse driver was still attached to the port. Three requests: 1. Have you run the test suite (which is easier if you get the CPAN distribution rather than using a PPM install)? If so, what were the results (aside from a couple of deprecated steps in the test suite)? 2. In the "complete" distribution from CPAN, there is a program called options.plx that does much like your log output - except I know exactly what it does in what sequence. 3. Please digest the actual code you are using to open the port into something I can examine. Over one page is too much - I'm just looking for clues in the operation sequence. -bill ************************************** AOL now offers free email to everyone. Find out more about what's free from AOL at http://www.aol.com.
Subject: Re: [rt.cpan.org #25539] Baudrate is not being set correctly.
Date: Tue, 20 Mar 2007 20:07:23 +1100
To: bug-Win32-SerialPort [...] rt.cpan.org
From: R Bernard Davison <rbdavison [...] cpan.org>
G'Day Bill, Below are the answers to your Questions. Thanks very much for chasing this up so quickly. :-) Cheers, Bernie On 20/03/2007, at 10:43 AM, Bbirthisel@aol.com via RT wrote: Show quoted text
> 1. Have you run the test suite (which is easier if you get the CPAN > distribution rather than using a PPM install)? If so, what were the > results (aside from > a couple of deprecated steps in the test suite)?
I originally installed from PPM but have downloaded the module from CPAN and run the tests. A number fail but I looked further into what they are doing yet. C:\Perl\cpan\build\SerialPort-0.19>test.pl t/test1....defined(@array) is deprecated at t/test1.t line 445, <DATA> line 164. (Maybe you should just omit the defined()?) t/test1....ok t/test2....ok t/test3....defined(@array) is deprecated at t/test3.t line 444, <DATA> line 164. (Maybe you should just omit the defined()?) t/test3....ok t/test4....FAILED tests 100, 252 Failed 2/516 tests, 99.61% okay t/test5....ok t/test6....NOK 116SetCommState failed at t/test6.t line 403 t/test6....FAILED tests 74, 114, 116, 201, 233, 237 Failed 6/315 tests, 98.10% okay t/test7....ok Failed Test Stat Wstat Total Fail Failed List of Failed ------------------------------------------------------------------------ ------- t/test4.t 516 2 0.39% 100 252 t/test6.t 315 6 1.90% 74 114 116 201 233 237 Failed 2/7 test scripts, 71.43% okay. 8/1749 subtests failed, 99.54% okay. Show quoted text
> 2. In the "complete" distribution from CPAN, there is a program called > options.plx that does much like your log output - except I know > exactly what it does > in what sequence.
Here's the output from options.plx C:\Perl\cpan\build\SerialPort-0.19>perl eg\options.plx Available Options for port COM1 Data Bit Options: 8 6 7 5 Stop Bit Options: 1 1.5 2 Handshake Options: none xoff dtr rts Parity Options: mark none even odd space Baudrate Options: 115200 1200 38400 4800 56000 2400 600 57600 19200 9600 14400 110 300 Binary Capabilities: can_baud can_databits can_stopbits can_dtrdsr can_handshake can_parity_check can_parity_config can_parity_enable can_rlsd can_rtscts can_xonxoff can_interval_timeout can_total_timeout can_xon_char is_rs232 binary Current Settings: baud = 9600 parity = none data = 8 stop = 1 hshake = none Byte Capabilities: xon_char = 0x11 xoff_char = 0x13 eof_char = 0x0 event_char = 0x0 error_char = 0x0 Other Capabilities: input buffer max = 0xffffffff output buffer max = 0xffffffff input buffer = 4096 output buffer = 0 alias = COM1 xon_limit = 0x800 xoff_limit = 0x200 Timeouts: read_interval = 0x0 read_const_time = 1000 read_char_time = 0 write_const_time = 2000 write_char_time = 0 C:\Perl\cpan\build\SerialPort-0.19> Show quoted text
> 3. Please digest the actual code you are using to open the port into > something I can examine. Over one page is too much - I'm just > looking for clues in the > operation sequence.
Here are the relevant code fragments that use the Win32::SerialPort module. This is an extract from the module Device::TNC::KISS that I've been working on and is available on CPAN. Please feel free to have a look at that module and flame me for anything I'm doing wrong. :-) use strict; use Config; if ($Config{'osname'} eq "MSWin32") { require Win32::SerialPort; Win32::SerialPort->import( qw( :STAT 0.19 ) ); } else { require Device::SerialPort; } my $m_port; my $m_port_name; sub new { my $class = shift; my %port_data = @_; my $baudrate; my %data; foreach my $key (keys %port_data) { if (lc($key) eq "port") { $m_port_name = $port_data{$key}; } if (lc($key) eq "baudrate") { $baudrate = $port_data{$key}; } } if ($Config{'osname'} eq "MSWin32") { $m_port = new Win32::SerialPort($m_port_name) or warn "Error: Cannot open serial port \"$m_port_name\": $^E\n"; } else { $m_port = new Device::SerialPort($m_port_name) or warn "Error: Cannot open serial port \"$m_port_name\": $!\n"; } $m_port->baudrate($baudrate); $m_port->parity("none"); $m_port->databits(8); $m_port->stopbits(1); $m_port->handshake("none"); $m_port->read_interval(100) if $Config{'osname'} eq "MSWin32"; $m_port->read_char_time(0); $m_port->read_const_time(1000); $data{'PORT'} = $m_port; my $self = bless \%data, $class; return $self; } # When we close try and close the port too. DESTROY { # Close the serial port $m_port->close() or warn "Error: Failed to the serial port \"$m_port_name\": $!\n"; } sub read_data { my $self = shift; my ($count,$saw) = $self->{'PORT'}->read(1); if ($count > 0) { # process the byte } # more processing and return }