Products for USB Sensing and Control
It is currently Thu Oct 30, 2014 5:35 pm

All times are UTC - 7 hours [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Tue Sep 07, 2010 12:33 am 
Hi ,

there is a problem in OnSpatialData event . the data should be PhidgetSpatial_SpatialEventData , but it is OleVariant .

PhidgetSpatial_SpatialEventData is :

Code:
  PhidgetSpatial_SpatialEventData = packed record
    Acceleration: array[0..2] of Double;
    angularRate: array[0..2] of Double;
    magneticField: array[0..2] of Double;
    time_seconds: Integer;
    time_microseconds: Integer;
  end;


Top
  
 
PostPosted: Tue Sep 07, 2010 9:16 am 
Offline
Lead Developer
User avatar

Joined: Mon Jun 20, 2005 8:46 am
Posts: 2632
Location: Canada
it's actually an array (safearray) of PhidgetSpatial_SpatialEventData. I'm not sure how Delphi represents safearrays.

-Patrick


Top
 Profile Send private message  
 
PostPosted: Wed Sep 08, 2010 1:07 am 
Dear Patrick,

this is a part of Phidget21COM_TLB.pas :
Code:
  _IPhidgetSpatialEvents = dispinterface
    ['{50484945-4745-5453-2000-000000000017}']
    procedure OnAttach; dispid 1;
    procedure OnDetach; dispid 2;
    procedure OnError(const Description: WideString; SCODE: PhidgetCOM_Error); dispid 3;
    procedure OnServerConnect; dispid 4;
    procedure OnServerDisconnect; dispid 5;
    procedure OnSpatialData(var data: {??PSafeArray}OleVariant; dataCount: Integer); dispid 6;
  end;


Top
  
 
PostPosted: Wed Sep 08, 2010 10:16 am 
Offline
Lead Developer
User avatar

Joined: Mon Jun 20, 2005 8:46 am
Posts: 2632
Location: Canada
PSafeArray in Delphi: http://blog.virtec.org/2008/07/the-myst ... safearray/

-Patrick


Top
 Profile Send private message  
 
PostPosted: Thu Mar 17, 2011 11:30 am 
Offline
Fresh meat

Joined: Thu Mar 17, 2011 11:24 am
Posts: 3
I'm running into the exact same problem: I am not able to extract the correct values in the OnSpatialData event.
Any help would be greatly appreciated in converting from OleVariant to PhidgetSpatial_SpatialEventData. The hints mentioned here are not enough for me to understand how to do that.


Top
 Profile Send private message  
 
PostPosted: Mon Mar 21, 2011 4:17 am 
Offline
Fresh meat

Joined: Thu Mar 17, 2011 11:24 am
Posts: 3
I think I have solved my own problem here. I'll post my solution so anyhow wondering in the future about the same issue might use this.
The typelibrary as generated by Delphi on import of the COM object generates the type PhidgetSpatial_SpatialEventData which I expected to get in the OnSpatialData event. However this event has a parameter 'data' of type OleVariant. I can access the data in the OnSpatialData event by adding the line
Code:
PPhidgetSpatial_SpatialEventData = ^PhidgetSpatial_SpatialEventData;
in the generated typelibrary.

In the eventhandler I can access the data by doing this:
Code:
procedure TFormMain.PhidgetSpatialSpatialData(ASender: TObject;
  var data: OleVariant; dataCount: Integer);
var
  pData: PPhidgetSpatial_SpatialEventData;
begin
  PData := PPhidgetSpatial_SpatialEventData(VarArrayLock(data));
  try
    Label1.Caption := Format('%g', [pData^.Acceleration[0]]);
    Label2.Caption:= Format('%d', [pData^.time_seconds]);
  finally
    VarArrayUnlock(data);
  end;
end;
As far as I can see this gets me the correct values. I came up with this solution by looking at the provided VB sample and googling for OleVariant handling in Delphi.
Hope this will help others in the future.
Regards
Jaco


Top
 Profile Send private message  
 
PostPosted: Mon Mar 04, 2013 3:29 am 
Offline
Fresh meat

Joined: Mon Mar 04, 2013 3:26 am
Posts: 1
@Jaco

Thanx!
This works for me just fine!


Top
 Profile Send private message  
 
PostPosted: Mon Mar 04, 2013 6:31 am 
Offline
Fresh meat

Joined: Thu Mar 17, 2011 11:24 am
Posts: 3
seoman wrote:
@Jaco

Thanx!
This works for me just fine!


Cool! Thanks for the thank you :-)


Top
 Profile Send private message  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 7 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


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 post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group