Products for USB Sensing and Control
It is currently Wed Jun 19, 2013 8:26 am

All times are UTC - 7 hours [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Wed Aug 15, 2012 12:48 pm 
Offline
Fresh meat

Joined: Thu Sep 30, 2010 9:58 am
Posts: 4
Howdy,

I had no problem getting acceleration values from a 1059 in VB.net using a timer:
Public Class Form1
'note added /Project/add reference to C:\Program Files\Phidgets\Phidget21.NET.dll
Dim WithEvents acc1 As Phidgets.Accelerometer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
acc1 = New Phidgets.Accelerometer
acc1.open(158410)
Timer1.Start()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Label1.Text = acc1.axes(0).Acceleration.ToString()
Label2.Text = acc1.axes(1).Acceleration.ToString()
Label3.Text = acc1.axes(2).Acceleration.ToString()
End Sub
End Class

Easy! But I'm trying to get accelerations from a 1049 using a timer control, and trying to adapt the sample code from the "spatial" accelerometer and it's not happening. I'm trying to psych out the "e As Phidgets.Events.SpatialDataEventArgs" and can't seem to get it into a function without VB yelling at me about bad arguments... I just want to grab current acceleration values on a timer tick. Don't need to collect multiple data packets...

Any suggestions? Thanks!

Chris Allen


Top
 Profile Send private message  
 
PostPosted: Thu Aug 16, 2012 8:20 am 
Offline
Engineering

Joined: Thu Nov 19, 2009 4:41 pm
Posts: 188
you can just use a similar method as for the 1059, just using a Phidgets.Spatial object instead of Phidgets.Accelerometer

and when grabbing the values from the device use

Code:
Label1.Text = acc1.accelerometerAxes(0).Acceleration;


keep in mind to change the other parts that arent Accelerometer as well


Top
 Profile Send private message  
 
PostPosted: Thu Aug 16, 2012 8:57 am 
Offline
Fresh meat

Joined: Thu Sep 30, 2010 9:58 am
Posts: 4
Hey, Thanks Fraser!

Not as complicated as I was trying to make it.

When I try it, my VB program says the phidget is not physically attached - tho your sample application finds it and the Phidgets control panel sees it - both your sample app and the control panel show data... Baffling.

Thanks!

Chris Allen


Top
 Profile Send private message  
 
PostPosted: Thu Aug 16, 2012 11:52 am 
Offline
Fresh meat

Joined: Thu Sep 30, 2010 9:58 am
Posts: 4
Howdy,

Thanks for your excellent assistance! The code below works OK now and I have real-time display of my accelerations from both acc1 - type 1059 accelerometer and acc2 - type 1049 spatial.

2 questions:
1) when the line "acc2.DataRate = 30" is un-commented, so the line is executed, I get an error:
PhidgetException 5 (Phidget not physically attached.)
when I comment it out, the program runs OK. I guess if I'm polling for accelerations, which now seems to work (thanks!), I don't really care about setting the data rate, but the "not attached" error has had me confounded as I tried to work thru this...

2) why am I getting acceleration values displayed perfectly from acc2 as label text when I'm pulling the accelerations (as double-precision reals, right?) and not ".tostring"

Code:
Public Class Form1
'note added /Project/add reference to C:\Program Files\Phidgets\Phidget21.NET.dll
Dim WithEvents acc1 As Phidgets.Accelerometer
Dim WithEvents acc2 As Phidgets.Spatial
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
acc1 = New Phidgets.Accelerometer
acc1.open(158410)
Timer1.Start()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Label1.Text = acc1.axes(0).Acceleration.ToString()
Label2.Text = acc1.axes(1).Acceleration.ToString()
Label3.Text = acc1.axes(2).Acceleration.ToString()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
acc2 = New Phidgets.Spatial
acc2.open(123335)
' Not sure why the next line doesn't work
' acc2.DataRate = 30
Timer2.Start()
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
Label4.Text = acc2.accelerometerAxes(0).Acceleration
Label5.Text = acc2.accelerometerAxes(1).Acceleration
Label6.Text = acc2.accelerometerAxes(2).Acceleration
End Sub
End Class

Thanks again for your help!

Chris Allen


Top
 Profile Send private message  
 
PostPosted: Thu Aug 16, 2012 2:12 pm 
Offline
Engineering

Joined: Thu Nov 19, 2009 4:41 pm
Posts: 188
the reason why the program throws an exception on DataRate is because calling .open() on your accelerometer does not guarantee it is attached at that point. So you need to wait for the device to become attached before sending it commands. you can do this by putting this instead:
Code:
acc2 = New Phidgets.Spatial
acc2.open(123335)
acc2.waitForAttachment()
acc2.DataRate = 30



in regards to your second question, i am actually unsure why you do not need to use the tostring() method on the accelerations, my guess is that VB.Net preprocessors are smart enough to perform the operation automatically if it knows it is being applied to a text field - hence why VB.Net forces you to use or assign properties in any situation


Top
 Profile Send private message  
 
PostPosted: Thu Aug 16, 2012 3:44 pm 
Offline
Fresh meat

Joined: Thu Sep 30, 2010 9:58 am
Posts: 4
Thanks, Fraser,

Makes sense...

I appreciate your help!

Chris Allen


Top
 Profile Send private message  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 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