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

I'm trying to use a perl script to communicate with external hardware (Arduino). I'm using Win32::SerialPort to drive things. Works well for the most part.

In some cases though, I wasn't able to communicate. After a board reset, the script didn't get any data. In this state, it appears the board is seeing my script, but it never responds. I found that running a "real" serial program (like PuTTY) makes it start working.

With the help of a serial sniffer, I see that my program does exactly what I asked it to (port, bps, stop bits), while PuTTY is also putting the port into DSR handshake mode. Presumably when I get no data the external board thinks that it shouldn't be sending me data.

I've tried several things in the code ($port->dtr_active(1), $port->rts_active(1)), but nothing I've tried has made my serial sniffer say anything new about the port settings when the script runs.

Is there some command or series of commands in this module (or others) that would facilitate this?

The insufficient code is:

use Win32::SerialPort; my $port = Win32::SerialPort->new("COM8") or die "New port failed. $!\n"; $port->baudrate(9600); # you may change this value $port->databits(8); # but not this and the two following $port->parity("none"); $port->stopbits(1); #$port->rts_active(1); # has no (useful) effect #$port->dtr_active(1); # has no (useful) effect ...

Replies are listed 'Best First'.
Re: Put a serial port in handshake mode?
by zentara (Cardinal) on Mar 28, 2012 at 11:57 UTC