[ Oops! I somehow thought you were using Win32::API and not XS. Ignore this. ]
use feature qw( say state );
use Win32::API qw( );
use constant {
_MAX_PROTOCOL_LEN => 25,
_MAX_MODEL_LEN => 25,
};
use constant {
TELLSTICK_SUCCESS => '~~~',
};
sub tdSensor {
state $tdSensor = Win32::API->new(
'~~~.dll',
'tdSensor',
'PIPIPP',
'I',
);
my $protocol_buf = "\0" x (_MAX_PROTOCOL_LEN + 1);
my $model_buf = "\0" x (_MAX_MODEL_LEN + 1);
my $id_buf = pack('i', 0);
my $dataTypes_buf = pack('i', 0);
my $rv = $tdSensor->Call(
$protocol_buf, length($protocol_buf),
$model_buf, length($model_buf),
$id_buf,
$dataTypes_buf,
);
if ($rv != TELLSTICK_SUCCESS) {
return undef;
}
return {
protocol = unpack('Z*', $protocol_buf),
model = unpack('Z*', $model_buf),
id = unpack('i', $id_buf),
dataTypes = unpack('i', $dataTypes_buf),
};
}
while (my $rec = tdSensor()) {
say join ', ',
"protocol: $rec->{protocol}",
"model: $rec->{model}",
"sensorId: $rec->{id}",
"dataTypes: $rec->{dataTypes}";
}
Untested. Assumes a 32-bit build of Perl.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.