Error in serial port of Arduin with communication between C and Perl

Asked

Viewed 270 times

17

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

Follow 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");
   }

}

The following serial port error is occurring:

Erro

  • What are your doubts and what difficulties are you facing? You could be more specific?

  • how to make the Cod for sensors on the Arduino send information to LP and the PL send it back to the Arduino, exchange information between them

  • at a glance here and see if it helps you.

  • @Mirelavieira You need to install the package Win32::SerialPort.

  • I downloaded and executed but I could

  • @Mirelavieira The same error? if yes, maybe the module has not been installed correctly. Which command did you use to install this module?

  • 1

    I think now your question is legal and I voted to reopen. There is one more vote to reopen as well. 5 votes are required for the reopening (3 are missing).

  • @Mirelavieira Which command you used to install the module?

  • @Mirelavieira OK. Which command did you use to install the module? something else, according to documentation, it is necessary to specify the door name (ex.: COM4) or a configuration file (ex.: COM2.cfg) of Win32::SerialPort.

  • tried some q find on the network but it may be q i n got installed, port com3

  • @Victorstafusa, I agree with you: the subject is interesting. How do I vote to reopen? (maybe I don’t have a reputation to vote...). However: (1) install perl (suggest Strawberry perl); (2) install the module (cpan Win32::Serialport); (3) try again...

  • @Jjoao The question has been reopened. If you have an answer, go ahead and post it. D

  • already posted, this already corrected! =)

  • @Mirelavieira managed to solve the problem?

  • @Mirelavieira vc nn should put the correct code in the question, but make an answer by answering it

  • 2

    @stderr Can you post your solution here as an answer? (and give a rollback on the question?) Pretty Please!

Show 11 more comments

1 answer

1

Follow the corrected and working code:

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")); 

  }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.