|
| Hi,
I'm trying to move a perl program from a Linux machine to Windows and
I'm having problems with the serial port and I know next to nothing
about perl. The program remote controls an electron microscope and has
some useful routines that didn't come with the original software.
The electron microscope is controlled by a Windows machine, I connect
from it to the Linux box with SSH and start the perl program. The
Linux machine is connected to the Windows machine with a serial cable
thru which the program sends its commands. This works fine.
I've now tried to get it working on the Windows machine by connecting
the serial cable from COM3 to COM4, installing ActivePerl and
transfering the program. I then changed the following line:
open LEO,"+<","/dev/ttyS1" or die("Failed to open /dev/ttyS1: $!"); to
open LEO,"+<","COM3" or die("Failed to open COM3: $!");
This works somewhat... sending commands seem to be working most of the
time but I can see in the terminal that now and then the reply from
the microscope seems to be echoed back as a new command and this gives
an error from the microscope as it doesn't match any command it knows.
This error will be read by the program next times it sends a command
and will of course scr*w up the program.I've also noticed that I have
to insert a sleep 1; before every read on Windows, otherwise it won't
work, it just gets stuck.
This is the what is used to get (part) of the reply
read(LEO,$comm_ackn,1,0);
I've tried to use the Win32::SerialPort but reading the replys doesn't
work and you have to add a /r to every command.
my $PortObj = Win32::SerialPort->new ('com3') || die;
$PortObj->user_msg(ON);
$PortObj->databits(8);
$PortObj->baudrate(9600);
$PortObj->parity("none");
$PortObj->stopbits(1);
$PortObj->handshake("none");
$PortObj->buffers(4096, 4096);
$PortObj->write_settings;
$PortObj->save("test.cfg");
undef $PortObj;
$PortObj = tie (*LEO, 'Win32::SerialPort', "test.cfg") || die "Can't
tie: $^E\n";
I could rewrite the program in Visual Studio.NET but I would prefer to
get it to function as it is.
Any help would be greatly appreciated,
Regards,
Linus
|
|