USB-UIRT Forum Forum Index USB-UIRT Forum
Plug-n-Play IR Solution
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

SetReceiveCallback target method has unexpected results

 
Post new topic   Reply to topic    USB-UIRT Forum Forum Index -> Developers
View previous topic :: View next topic  
Author Message
Dann



Joined: 14 Apr 2005
Posts: 6
Location: Camarillo, CA

PostPosted: Wed Apr 20, 2005 3:54 pm    Post subject: SetReceiveCallback target method has unexpected results Reply with quote

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. Shocked

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
Back to top
View user's profile Send private message
jrhees
Site Admin


Joined: 28 Jan 2003
Posts: 1652

PostPosted: Thu Apr 21, 2005 4:50 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Send e-mail
Dann



Joined: 14 Apr 2005
Posts: 6
Location: Camarillo, CA

PostPosted: Thu Apr 21, 2005 3:34 pm    Post subject: Reply with quote

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 Smile

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
Back to top
View user's profile Send private message
jrhees
Site Admin


Joined: 28 Jan 2003
Posts: 1652

PostPosted: Thu Apr 21, 2005 11:33 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Send e-mail
Dann



Joined: 14 Apr 2005
Posts: 6
Location: Camarillo, CA

PostPosted: Fri Apr 22, 2005 4:07 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Dann



Joined: 14 Apr 2005
Posts: 6
Location: Camarillo, CA

PostPosted: Wed Apr 27, 2005 12:47 am    Post subject: Reply with quote

[quote="Dann"]
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
Back to top
View user's profile Send private message
harm



Joined: 10 Oct 2005
Posts: 1

PostPosted: Mon Oct 10, 2005 2:45 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
jrhees
Site Admin


Joined: 28 Jan 2003
Posts: 1652

PostPosted: Mon Oct 10, 2005 11:34 pm    Post subject: Reply with quote

We had to move the callback procedure outside of the Class (basically make it a 'global' procedure).

-Jon
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    USB-UIRT Forum Forum Index -> Developers All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group