My perl code works great, unless the board gets reset.
After a reset, then the first time I use "putty" or the Arduino serial monitor to open the port and connect I can see the board resets again. But If I run my perl code first (which tries to open the serial port), then the board does not reset and my code gets no data.
What "magic" is putty and the serial port monitor doing to initialize serial comms that my perl code is not? Right now I have to use one of them to get things rolling. After that, the code works great.
I don't know that the problem is here, but this is the perl code I'm running:
Code: Select all
#!/perl64/bin/perl
use strict;
use warnings;
use Win32::SerialPort;
my $port = Win32::SerialPort->new("COM3")
or die "New port failed. $!\n";
# 19200, 81N on the USB ftdi driver
$port->baudrate(9600);
$port->databits(8);
$port->parity("none");
$port->stopbits(1);
print "Sending newline\n";
$port->write("\012\015");
my $byte;
my $maxlines = 0;
my $newlines=0;
while(1)
{
$byte = $port->read(80);
print $byte;
$newlines += ($byte =~ tr/\n//);
if ($newlines > $maxlines) { last; }
}
print "done.\n";
Thanks!