Having trouble porting an application to MS-Windows



Good morning,

The code listed below is part of a link level serial protocol that
doesn't port to Win32. A framed message with a checksum is sent and then
a single character response (ACK or NAK) is expected in return. On the
Win32 platform, this form of select is only implemented for sockets, and
alarm() is not implemented at all. How can I set up a sysread() with an
adjustable timeout on a device in MS-Windows?

$port = 'COM4' unless $port;
sysopen( PORT, "$port", O_RDWR ) or die "Can't sysopen $port: $!";
binmode(PORT);

# loop on NAK or timeout with two retries
$done = 0;
$tries = 0;
do {
syswrite PORT, $_, length;

$rin = $win = $ein = '';
vec($rin, fileno(PORT), 1) = 1;
vec($win, fileno(PORT), 1) = 1;
$ein = $rin | $win;
$timeout = 3.0;

($nfound,$timeleft) = select($rout=$rin, $wout=$win,
$eout=$ein, $timeout);

if ($nfound > 0) {
$inchar = sysread PORT, $line, 1, 0;
if (ord ($line) == 21) {
print STDOUT " NAK";
}
if (ord ($line) == 6) {
print STDOUT " ACK";
$done = 1;
}
}
else {
print STDOUT " t/o";
}
} while ($done == 0 && ++$tries < 3);
print STDOUT "\n";
if ($done == 0) {
next LINE;
}


I have ActiveState Perl 5.8.0.806 or Cygwin with Perl 5.6.1 available.
Both versions are parts of SDK's which prevent me from upgrading. I
tried to install Linux in a VM session, but I don't have a recent enough
version of VMWare to do so, and my manager has refused to allow me to
update that one either. (He said something about being too near the end
of the fiscal year.)

NOTA BENE: I don't do objects. After 30 years of procedural code, they
don't make any sense to me, on several levels. I have looked at
Win32-SerialPort-0.19 but can't make heads nor tails of it.

Thank you,

Bob McConnell
Principal Communications Programmer
The CBORD Group, Inc.
61 Brown Road
Ithaca NY, 14850
Phone 607 257-2410
FAX 607 257-1902
Email rvm@xxxxxxxxx
Web www.cbord.com
.



Relevant Pages

  • Re: VCL.NET revisited...
    ... might need to port the application back to Win32. ... app, ... VCL.NET rather than having to learn WinForms -- especially ...
    (borland.public.delphi.non-technical)
  • Killing all child processes upon parent exit
    ... Could anyone please tell me how to kill all child processes when parent exit? ... all' and redo) or die $!; ... print STDOUT "Client host: $cHostName\n"; ... print STDOUT "Client port: $cPort\n"; ...
    (comp.lang.perl.misc)
  • Re: Borland "Turbo Explorer" Developer Studio
    ... Why would anyone want to take a perfectly good native Win32 app and port it ... Porting Fish Facts as a cute little demo is one thing but porting tens of ...
    (borland.public.delphi.non-technical)
  • Registering same Singleton remoting object on two different ports on the same machine
    ... point for add-in applications to communicate with it. ... Multiple instances of the Win32 application can be started on the same ... allocating a port when the application starts up. ... at a configured port catching socket exceptions and simply incrementing ...
    (microsoft.public.dotnet.framework.remoting)
  • Re: Catastrophic Failure Trying out VCL.NET
    ... Except for those cases of fiat by ... management, I can see little or no inducement to port a perfectly good Win32 ...
    (borland.public.delphi.non-technical)