in reply to Win32 Serial Communication

The tried and tested serial communications module for Windows-based systems is Win32::SerialPort - This module, despite its 0.19 versioning, is fairly widely used and quite robust in nature, making direct use of Win32 System API calls. The documentation for this module is quite complete and there is very little that I suspect that you cannot do with this module - If you find this module insufficient, you may want to try a little Google searching before you commit yourself too heavily to this project to find other examples of Win32::SerialPort usage.

The *NIX equivalent of this module is Device::SerialPort which makes use of the termios library and is exceptionally good for serial communications.

 

perl -e 's&&rob@cowsnet.com.au&&&split/[@.]/&&s&.com.&_&&&print'

Replies are listed 'Best First'.
Re: Re: Win32 Serial Communication
by Anonymous Monk on Jan 04, 2002 at 01:52 UTC
    I decided to try out this module. The following is pretty much the code from the examples
    use strict; use Win32::SerialPort qw( :STAT 0.19 ); my $PortName = 'COM1'; my $ob = new Win32::SerialPort($PortName) || die "Can't open $PortName +: $^E\n"; Win32::SerialPort->set_test_mode_active(1); $ob->handshake("none"); $ob->baudrate(57600); #may need to be 56000 $ob->parity("none"); $ob->databits(8); $ob->stopbits(1); $ob->binary(1); $ob->parity_enable(0); $ob->read_const_time(5000); $ob->read_interval(0); $ob->write_const_time(3000); $ob->debug(1); $ob->error_msg(1); # prints hardware messages like "Framing Error" $ob->user_msg(1); # prints function messages like "Waiting for CTS +" $ob->buffers(16,16); # read, write $ob->write_settings || die "Cannot write settings"; $ob->status; print "Starting 1 character background read\n"; my $in = $ob->read_bg(1); my $done = 0; my $blk; my $err; my $out; my $result; for (;;) { ($done, $in, $result) = $ob->read_done(0); $ob->status; sleep(1); last if $done; } print "got = $in\nresult = ",ord($result),"\n"; undef $ob;
    The output says I receive a character, but it's ascii value is 0 which is wrong. I know that my hardware works because I have tried talking to it with HyperTerm. Where is my flaw?
      I've done a lot of work with Device::SerialPort, which is the unix implementation of Win32::SerialPort. I get just a single "0" value when I have something in my settings wrong. Usually it's a baud rate. (My hardware at the other end doesn't always honour it's DIP settings for the baud rate) The other condition that I've had generate that was an error in flow control settings.

      Maybe try a test at 2400 or something.

      In any case, do please x 1000 use Win32::SerialPort, because it is what is normally used, it works _very_ well, and people expect to see it. Also, it's interface is portable to other platforms. (for example, the native platform of Perl...)
      --
      Snazzy tagline here