For example, the response
OFST -0.75
####
810100000000000c4f465354202d302e3037350a
####
VDIV 0.05
810100000000000
####
#!perl -w
use strict;
use IO::Socket;
my $verbose = 1;
print "===\n";
my $host = "127.0.0.1"; # or whatever
my $port = 1861;
my $remote = IO::Socket::INET->new( Proto => "tcp",
PeerAddr => $host,
PeerPort => $port)
or die "Couldn't connect to $host:$port\n$!\n$@\n";
my $msg = 'ofst?';
# send query
$remote->send(wrap($msg))
or die "Couldn't send: $!\n$@\n";
# read the remote answer
my $answer = <$remote> || '---';
print "answer: =$answer=\n";
my $response = unwrap($answer);
print "response: =$response=\n";
close $remote;
exit;
sub wrap {
my ($data) = @_;
my $header = pack "C4N", hex '0x81', hex '0x1', 0, 0, length($data);
return $header . $data;
}
sub unwrap {
my ($packet) = @_;
my ($op, $hvers, $count, $data);
($op, $hvers, undef, undef, $count, $data) = unpack "C4NA*", $packet;
{
my $warn = '';
my $length = length($packet);
if ($count != $length) {
$warn .= "warn: $count != $length: \n";
}
$warn .= unpack "H*", $packet;
print STDERR "$warn\n" if $verbose;
}
return $data;
}
__END__