in reply to Serial communication between perl and arduino

Not sure if this is related to your error message, but you're probably not connecting to the device.

According to your code, you're trying to connect to COM22. Using COMX pattern will only work for COM ports 1-9. If you want to use a COM port above 9, you have to change your port name syntax to be \\.\COM22 instead of using COM22. You can use the alternate syntax for ports 1-9 also. Because of that, it might be a good idea to switch to that syntax regardless of which port number is used. And with the backslashes, you'll need to take care that to ensure that Perl doesn't try to interpolate them.

For more details about using ports 10 and up, see https://support.microsoft.com/en-us/kb/115831.

Replies are listed 'Best First'.
Re^2: Serial communication between perl and arduino
by perl_sck_58 (Novice) on Jun 01, 2015 at 16:39 UTC

    I tried your suggestion,I am getting an error "The system cannot find the file specified. can't open device: \.\COM22 at config.pl line 4. Died at config.pl line 4."

      ... can't open device: \.\COM22 ...

      Notice the leading single backslash in the error message where a double backslash was advised. Even in single quoted strings, backslash interpolation is tricky:

      c:\@Work\Perl\monks>perl -wMstrict -le "my $s = 'A: \\.\COM22'; print qq{'$s'}; ;; $s = 'B: \\\.\COM22'; print qq{'$s'}; " 'A: \.\COM22' 'B: \\.\COM22'


      Give a man a fish:  <%-(-(-(-<

      Are you sure that you handled the backslashes properly? The port name for COM22 is \\.\COM22, but your error message complains about \.\COM22. If you used double-quotes, then you would need to have it like this "\\\\.\\COM22".

        I have corrected it by using "\\\\.\\COM22" but still getting the error as "Second Write attempted before First is done at Simple_serial_com.pl line 11. Use of uninitialized value $written in numeric ne (!=) at C:/Perl64/site/lib/Win 32/SerialPort.pm line 1580.."