Micheal Erskine sent this example of using the ActiveX interface from Perl.
Contents |
I'm very interested in RealTerm for the collection of serial data into files on unattended NT 4 boxes. The data collection has to run whilst there is no logged-in user, no desktop etc. Generally I write applications as either NT Services or Scheduled Tasks. I started with the command line and found that my version (1.14.1.4 - the latest) still shows the window although visible is set to zero...
realterm.exe visible=0 port=1 baud=9600 flow=0 capfile=junk.txt capsecs=10 capture
...what have I done wrong? I also would like the application to quit after the capture. (Ed: this will work. "CAPQUIT" parameter will quit after capture)
I failed to get this to work so I started playing with the OLE interface with Perl and came up with a sweet solution that may be of interest to other users. Once again, well done and thanks for making my job easy!
Here's the Perl to capture some data for an hour...
#! perl
=for docs
Here we are controlling RealTerm as an out-of-process
OLE server to capture serial data into a file for a
particular duration.
=cut
use strict;
use warnings;
use Win32;
use Win32::OLE;
use Win32::OLE::Const 'Realterm Library';
# Die on OLE errors...
$Win32::OLE::Warn = 3;
use Log::TraceMessages qw(t d);
$Log::TraceMessages::On = 1;
# Hot file handle magic...
select( ( select(STDERR), $| = 1 )[0] );
select( ( select(STDOUT), $| = 1 )[0] );
#
my ( $exedir, $exefile ) = Win32::GetFullPathName($0);
my $capfile = $exedir . 'realterm_data.txt';
my $duration = 3600;
t "Capture file is '$capfile'";
t "Starting OLE server...";
my $thing = Win32::OLE->new('realterm.realtermintf');
$thing->{Visible} = 0;
$thing->{TrayIconActive} = 0;
$thing->{baud} = 9600;
$thing->{caption} = 'Automated serial data capture - do not
touch';
$thing->{CaptureFile} = $capfile;
#~ $thing->{CaptureEnd} = 20;
#~ $thing->{CaptureEndUnits} = Secs;
$thing->{PortOpen} = 1;
t "Starting capture for $duration seconds...";
$thing->StartCapture();
sleep $duration;
$thing->StopCapture();
t "Finished capture.";
$thing->{PortOpen} = 0;
undef $thing;
# OK, we should now have some results in the capfile...
if ( not open CF, "< $capfile" ) {
die "Failed to open '$capfile': $!";
}
while (<CF>) {
chomp;
t "$.:'$_'";
}
close CF;
__END__