Page 1 of 1

SetReceiveCallback target method has unexpected results

PostPosted: Wed Apr 20, 2005 3:54 pm
by Dann
I wonder is anyone might be able to help me out. I'm using Delphi 6 on XP-Pro to work with the USB-UIRT:

Firmware Version = 1289
Protocol Version = 257
Firmware Revision Date = 3/26/2004
Config Value = 3

Everything seems to init OK, the LED flashes when I call UUIRTTransmitIR, and flashes when I press any buttons on my TV remote.

My callback function set by UUIRTSetReceiveCallback is called each time a button is pressed on the remote as well. The 2nd parameter (userData) is passed in correctly and contains the value I set from UUIRTSetReceiveCallback, but the 1st parameter (IREventStr) is returing the same data no matter what button is pressed. And, it doesn't seem to be an ASCIIZ string either.

I get (in decimal) 0 0 0 0 1 0 0 0 32 144 1 16 171 as the 13 characters no matter which button is pressed. I would expect that this data would be different for each button pressed and the 13th character would always be an ascii zero. I'm new to Delphi so I figure I'm doing soemthing dumb with regards to how I've declared the method's parameters. :shock:

Here's how the callback method is coded:

procedure TUIRT.Rcv(IREventStr: pchar; userData: longint);
var
myObj: TUIRT;
j: integer;
s: string;
begin
myObj := TUIRT(userData);
Form1.Memo1.Lines.Add(' udata='+IntToStr(myObj.udata));
s := '';
for j := 0 to 12 do begin
s := s +IntToStr(ord(IREventStr[j]))+' ';
end;
Form1.Memo1.Lines.Add(' IREventStr='+s);
end;

I set up for the callback with this call (at the end of the TUIRT.openUIRT method):

res := UUIRTSetReceiveCallback(FDrvHandle, integer(@TUIRT.Rcv), integer(self));

Any idea what I've done wrong?

Thank you very much,
Dann

PostPosted: Thu Apr 21, 2005 4:50 am
by jrhees
Dann,

Yes, you should expect to see a 12-digit ASCII string. You may want to try declaring your parameter as a String instead of PChar and see what happens...

-Jon

PostPosted: Thu Apr 21, 2005 3:34 pm
by Dann
jrhees wrote:Yes, you should expect to see a 12-digit ASCII string. You may want to try declaring your parameter as a String instead of PChar and see what happens...


Thanks for the reply Jon. Somehow I didn't expect a char* to be converted to a Delphi string type automatically just because I declare it that way. I'm not sure if it worked or not however.

New declaration:
procedure TUIRT.Rcv(IREventStr: string; userData: longint);

This appears to function as well, and now there is at least some variation in the data, but only the first digit of the IREventStr has actually changed. And this digit is either a 48, 50 or 65 depending on what button is pressed. However, it is still not unique between all buttons on the remote.

I'm still getting this: IREventStr=48 0 0 0 0 1 0 0 0 32 144 1
or: IREventStr=50 0 0 0 0 1 0 0 0 32 144 1
or: IREventStr=65 0 0 0 0 1 0 0 0 32 144 1

Something else must still be wrong.

Is something else supposed to be done before the callback works correctly, like calling the UUIRTLearnIR function? Am I supposed to teach the UIRT about a remote before the callback returns valid data? I sure wouldn't expect that to be the case, but I gotta ask :)

Or, perhaps I my expectations are at fault. I expect a unique string for every button on the remote. Is that what I should be expecting?

Thanks again,
Dann

PostPosted: Thu Apr 21, 2005 11:33 pm
by jrhees
Your expectations are correct, and you *dont* need to make any other calls. I still believe this is a declaration/stack problem and how parameters are passed, etc. The reason I can be sure of this is that you will *always* be passed a 12-digit ASCII hex string, and you are in fact seeing null characters and other non-ascii chars.

If you contact support@usbuirt.com I can send you a simple test app.

-Jon

PostPosted: Fri Apr 22, 2005 4:07 pm
by Dann
jrhees wrote:I still believe this is a declaration/stack problem and how parameters are passed, etc.

If you contact support@usbuirt.com I can send you a simple test app.
-Jon


I am in agreement that it's a declaration problem. I've tried dozens of variations now, typecasting it every which way, but nothing works. As far as a test app, if it's in Delphi Pascal, that would be very usefull. I have the other test apps that came with the API, but none are for Delphi :(

If there are any other registerd users who implemented this in Delphi, perhaps they could be persuaded to shed some light on this :)

Thanks again,
Dann

PostPosted: Wed Apr 27, 2005 12:47 am
by Dann
Dann wrote:
jrhees wrote:I still believe this is a declaration/stack problem and how parameters are passed, etc.
-Jon


Thanks you so much for your help Jon.

Just for this forum's record, Jon did some testing with my app and figured out that if the callback procedure is placed outside the class, then everything works ok. Apparently Delphi's stack is not compatible if the callback is a class method.

Thanks again Jon!

Dann

PostPosted: Mon Oct 10, 2005 2:45 pm
by harm
Hi,

I seem to have the same problem as described in this thread; but the solution is still unclear to me. Could you please (dann or jon) post a small snippet of code for the callback procedure?

Thanks in advance

PostPosted: Mon Oct 10, 2005 11:34 pm
by jrhees
We had to move the callback procedure outside of the Class (basically make it a 'global' procedure).

-Jon