hydrodog has asked for the wisdom of the Perl Monks concerning the following question:
the code that works on Linux opens a file handle and uses stty to set the baud rate:ppm install Win32::SerialPoint ppm install Win32::API
Elegant and simple, right? On windows, there is no stty, so barring installing cygwin, which I would rather not have to do, I had to use the Win32::Serial package. It works fine for a GPS, but for this device, inexplicably no. Perhaps its one of many parameters of the serial port, so I will paste in the output to stty -a -F/dev/ttyUSB0 on linux:use strict; my $deckbox = "/dev/ttyUSB0"; open(DECK, "+<$deckbox") || die('Couldn\'t open GPS'); system("stty -F $deckbox 19200"); while (my $line = <DECK>) { print $line; print DECK "\$CCPDT,1,4,0,0,3000,1,0,0,0\r\n"; }
The windows code that gives back gibberish:stty -a -F /dev/ttyUSB0 speed 19200 baud; rows 0; columns 0; line = 0; intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; +eol2 = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; + min = 1; time = 0; -parenb -parodd cs8 hupcl -cstopb cread clocal -crtscts -ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixo +n -ixoff -iuclc -ixany -imaxbel opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs +0 vt0 ff0 isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -ec +hoprt echoctl echoke
Can anyone tell me what I'm missing?require 5.003; use Win32::SerialPort qw( :STAT 0.19 ); use strict; my $line; my $deck = openSerial("com3:", 19200, 'none', 8, 1); # $deck->handshake("xon"); # $deck->buffers(4096,4096); do { my $bytesWritten = $deck->write('$CCPDT,1,4,0,0,3000,1,0,0,0' . "\r\n"); $line = rawReadSerial($deck); } while (1); sub readLineSerial { my ($ser) = @_; my ($numChars, $c); my $line = ''; do { do { ($numChars, $c) = $ser->read(1); } while ($numChars < 1); $line .= $c; } while ($c ne "\n"); return $line; } sub rawReadSerial { my ($ser) = @_; my ($numChars, $c); my $line = ''; do { do { ($numChars, $c) = $ser->read(1); #print "$numChars read=$c\n"; } while ($numChars < 1); print $c; $line .= $c; } while ($c ne "\n"); return $line; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: serial port control on Windows
by BrowserUk (Patriarch) on Apr 23, 2008 at 18:22 UTC | |
by hydrodog (Novice) on Apr 23, 2008 at 18:58 UTC | |
by BrowserUk (Patriarch) on Apr 23, 2008 at 19:18 UTC | |
|
Re: serial port control on Windows
by sgifford (Prior) on Apr 23, 2008 at 19:33 UTC |