perl and UUIRTSetReceiveCallback

Interested in integrating USB-UIRT support into an application? Look here!

Moderator: jrhees

perl and UUIRTSetReceiveCallback

Postby caseybragg » Mon Aug 29, 2005 11:28 pm

Does anyone out there know how to use the UUIRTSetReceiveCallback with perl? I think I'm close, but all I can do so far is crash perl when usb-uirt gets an ir signal.

I'm using activeperl 5.8.6 on win xp.

Here's what I have so far. I've tried several approaches, so some of the code is commented out to illustrate that.

Any help is appreciated.

use strict;
use Win32::API;
use Win32::API::Callback;

use Callback;

my ($DrvHandle);

Win32::API::Type->typedef('HUUHANDLE', 'PHANDLE');

Win32::API->Import('uuirtdrv', 'HUUHANDLE UUIRTOpen()');
Win32::API->Import('uuirtdrv', 'BOOL UUIRTClose(HUUHANDLE hHandle)');

Win32::API::Type->typedef( 'PUUCALLBACKPROC', qw(
UCHAR IREventStr;
UVOID userData;
));

Win32::API->Import('uuirtdrv',
'BOOL UUIRTSetReceiveCallback(HUUHANDLE hHandle, PUUCALLBACKPROC receiveProc, PVOID userData)');

sub testReceive () {
#my $ireventstr = shift;
#my $userdata = shift;
#print ("UIRT CALLBACK!!!!\n" . "ireventstr : " . $ireventstr . "\n" . "userdata : " . $userdata . "\n");
print ("UIRT CALLBACK!!!!\n");
}

my $userData;
my @myargs;

my $callback = Win32::API::Callback->new( sub { print ("UIRT CALLBACK B!!!!\n"); return 1; }, "userData" );
#my $callback = new Callback(\&testReceive, @myargs);

$DrvHandle = UUIRTOpen();

print "USB_UIRT : Registering callback\n";
#UUIRTSetReceiveCallback($DrvHandle, \&testReceive, $userData);
UUIRTSetReceiveCallback($DrvHandle, $callback, $userData);

print "USB_UIRT : Registering callback : done\n";

while (1>0) {
print "Press a remote button... I dare you...\n";
sleep 1;
}
caseybragg
 
Posts: 3
Joined: Sun Jul 17, 2005 4:09 am

Postby jrhees » Tue Aug 30, 2005 4:22 pm

I cannot help you regarding Perl, but here are a few things which come to mind:

1. If the stack parameters of the callback are not being added/torn down correctly, this could cause a crash (i.e., what stack convention is the Perl callback expecting).

2. Some programming languages require special handling for callbacks which originate from a different thread. The ReceiveCallback callback in the USB-UIRT API does just that -- it originates from a different thread than the main process thread (although it is still spawned from the same process).

-Jon
jrhees
Site Admin
 
Posts: 1652
Joined: Tue Jan 28, 2003 11:49 pm


Return to Developers

Who is online

Users browsing this forum: No registered users and 4 guests

cron