Serial read

Posted by jan019 on 2018-10-22 00:22


I am new to perl programming, but not to programming in general. Currently I am working on a project, where I need to read data from a serial port. A perl script was provided for this, and because of the nature and requirements of the project, I must use this specific perl script. The script was written probably in the early 2000's.

I am running ActiveState Perl v5.24.3. on 64-bit Windows 10. Here is the code:

$ComPort = "COM7:38400,n,8,1";
open COM,$ComPort or die "Cannot open COMport\n";
open OUT,">" . $Package . ".log" or die "Cannot open logfile\n";
while (not $L =~ m/.*\x1a.*/ )
$L = <$COM>;
print $L;
print OUT $L;
close COM;
close OUT;

The serial port is opened and the program runs until reaching the line "$L = <$COM>;", where it hangs for eternity. I tried sending various data for reading, but the script always hangs on that line.

The data is being sent correctly, this was checked with putty and also a python script, the while condition is satisfied, but I never get any output in the console nor in the output file.

I've been searching the internet up and down and didn't find any answer to why the script is not working. Please bear in mind, that using any modules is out of question. Thank you for any advice.

Jan Grossmann

PS: the line $L = <$COM>; is without the dollar sign before COM, I had to write it here with the dollar sign, becuase without it, nothing was shown. Also, the variable $Package is defined in an earlier part of the code, which has nothing to do with the serial read. The problem is only with the serial read.