Arduino serial port error with communication between C and Perl

17

I have to make a language communicate with arduino and vice versa. I have the program in C and I have to modify it for this project, the language I will have to use is Perl .

Here is the code I have:

use 5.014;
use strict;
use warnings;

use Win32::SerialPort;


my $port = new Win32::SerialPort("lib/Win32/SerialPort.pm");
$port->user_msg(ON); 
$port->databits(8);
$port->baudrate(19200);
$port->parity("none");
$port->stopbits(1);
$port->dtr_active(0);

while (1) {
   print "Enter a number... ";
   my $char = ;
   chomp($char);

   # Send the character to the Arduino
   if ($char =~ /^\d+$/) {
      print "Sending $char ...\n";
      $port->write("$char");
   }

}

You are giving the following error on the serial port:

    
asked by anonymous 23.08.2016 / 20:22

1 answer

1

Follow the code that is fixed and working:

use 5.014; 
use strict; 
use warnings; 

use lib 'C:\Dwimperl\cpan\build\Win32-SerialPort-0.22-tXycqQ\lib'; 
use Win32::SerialPort; 


# porta serial
# perl+arduino
my $port = Win32::SerialPort->new("COM3");
$port->databits(8);
$port->baudrate(9600);
$port->parity("none");
$port->stopbits(1);
$port->dtr_active(0);

while (1) {
   print "Enter a number... ";
   my $char = <stdin>;
   chomp($char);

   # Send the character to the Arduino
   if ($char =~ /^\d+$/) {
      print "Sending $char ...\n";
     $port->write(chr("$char")); 

  }
}
    
04.10.2017 / 16:19