Products for USB Sensing and Control
It is currently Sat May 18, 2013 3:38 am

All times are UTC - 7 hours [ DST ]




Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: sensorchangeevents
PostPosted: Sat Jul 24, 2010 3:26 am 
Offline
Phidgetly

Joined: Tue Jul 06, 2010 7:04 am
Posts: 43
I am wondering if the is any way to fire a sensorchangeevents as my app waits for a sensorchangeevent and as I get problem with sensitivety set to 2 for ph as if its less than 2 I get one or more data packets lost and the sensorevent fires but I have to set the sensitivety to 2 to stop the data packets lost problem so if I can fire the sensorchangeevent manually that means i dont have to set sensitivety less than 2
hope you see what I mean!


Top
 Profile Send private message  
 
 Post subject: Re: sensorchangeevents
PostPosted: Mon Jul 26, 2010 8:54 am 
Offline
Phidget Mastermind

Joined: Mon Sep 28, 2009 9:04 am
Posts: 464
Is your event handler trying to do too much?


Top
 Profile Send private message  
 
 Post subject: Re: sensorchangeevents
PostPosted: Tue Jul 27, 2010 5:42 am 
Offline
Phidgetly

Joined: Tue Jul 06, 2010 7:04 am
Posts: 43
not really its ok until I say take the ph probe out of the water or the temperature probe causes the data packets lost


Top
 Profile Send private message  
 
 Post subject: Re: sensorchangeevents
PostPosted: Tue Jul 27, 2010 10:48 am 
Offline
Phidget Mastermind

Joined: Mon Sep 28, 2009 9:04 am
Posts: 464
So if I understand you correctly, if your sensor change is 2, it works fine, but if you set the sensor change to 1 or 0, you start losing packets?


Top
 Profile Send private message  
 
 Post subject: Re: sensorchangeevents
PostPosted: Tue Jul 27, 2010 11:10 am 
Offline
Phidgetly

Joined: Tue Jul 06, 2010 7:04 am
Posts: 43
yes

ph
phidgetIFK.sensors(1).Sensitivity = 2

temperature
phidgetTEMP.thermocouples(0).Sensitivity = 0.5

if I say take 1 of these out of the water I am sampling i usually get lost data packets


Top
 Profile Send private message  
 
 Post subject: Re: sensorchangeevents
PostPosted: Tue Jul 27, 2010 11:53 am 
Offline
Phidget Mastermind

Joined: Mon Sep 28, 2009 9:04 am
Posts: 464
Can you post your sensor change event handler?


Top
 Profile Send private message  
 
 Post subject: Re: sensorchangeevents
PostPosted: Wed Jul 28, 2010 2:29 am 
Offline
Phidgetly

Joined: Tue Jul 06, 2010 7:04 am
Posts: 43
Private Sub ph_sensorchange(ByVal index As Object, ByVal e As Phidgets.Events.SensorChangeEventArgs) Handles phidgetIFK.SensorChange
Dim logo As String = "WQS"
phidgetIFK.sensors(1).Sensitivity = 2
temp = phidgetTEMP.thermocouples(0).Temperature
ph = 7 - (2.5 - phidgetIFK.sensors(1).Value / 200) / (0.257179 + 0.000941468 * temp)

ph_value.Text = ph.ToString
ec_value.Text = ec.ToString
If phidgetLCD.Attached Then
phidgetLCD.rows(0).DisplayString = String.Format("ph:{0:00.00} {1:00.00}C", ph, temp)
phidgetLCD.rows(1).DisplayString = String.Format("ec:{0:00.00} {1: }", ec, logo)
End If



End Sub

Private Sub temp_change(ByVal sender As Object, ByVal e As Phidgets.Events.TemperatureChangeEventArgs) Handles phidgetTEMP.TemperatureChange
Dim temp_probe As Double
If phidgetIFK.Attached Then phidgetTEMP.thermocouples(0).Sensitivity = 0.5
temp_probe = phidgetTEMP.thermocouples(0).Temperature
temp_value.Text = temp_probe.ToString


End Sub


Top
 Profile Send private message  
 
 Post subject: Re: sensorchangeevents
PostPosted: Wed Jul 28, 2010 11:04 am 
Offline
Phidget Mastermind

Joined: Mon Sep 28, 2009 9:04 am
Posts: 464
The biggest problem I see is how you're reading in the data in the event handler. The event handler gives you back the data from the sensor input in the "e" variable, but you just ignore it, and then poll the device for data again. This is going to take some time, and is probably where your problems are coming from.

For example, this:
Code:
ph = 7 - (2.5 - phidgetIFK.sensors(1).Value / 200) / (0.257179 + 0.000941468 * temp)


Should be more like this:
Code:
if (e.index == 1) ph = 7 - (2.5 - e.Value / 200) / (0.257179 + 0.000941468 * temp)

This code simply checks to make sure that it was sensor 1 that triggered the event, and then reads the data that the event handler was given. Make sense?

You also shouldn't be setting the sensitivity of your input every time your event handler is run. Set it once in your attach event, and you will be good.

It may also be a good idea not to poll the thermocouple for a temperature every time your sensor change event runs.


Top
 Profile Send private message  
 
 Post subject: Re: sensorchangeevents
PostPosted: Wed Jul 28, 2010 11:18 am 
Offline
Phidgetly

Joined: Tue Jul 06, 2010 7:04 am
Posts: 43
Hi Robert

Thanks for that but as I only have 1 textlcd display update thats why I am doing the temp sensor in phsensorchange as the ph value is dependent on the temp isn't it. I will have a go at your suggestion

Do you have any suggestions regarding a textlcd.display update method when the values change, i have been thinking about using textchanged events on the ph, temp text boxes

Private Sub ec_value_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles
If phidgetLCD.Attached Then phidgetLCD.rows(1).DisplayString = ph_value.Text
End Sub


Top
 Profile Send private message  
 
 Post subject: Re: sensorchangeevents
PostPosted: Fri Jul 30, 2010 3:35 am 
Offline
Phidgetly

Joined: Tue Jul 06, 2010 7:04 am
Posts: 43
HI

getting on
if (e.index == 1) ph = 7 - (2.5 - e.Value / 200) / (0.257179 + 0.000941468 * temp)

epression expected on the second =


Top
 Profile Send private message  
 
 Post subject: Re: sensorchangeevents
PostPosted: Fri Jul 30, 2010 9:25 am 
Offline
Phidget Mastermind

Joined: Mon Sep 28, 2009 9:04 am
Posts: 464
Oops, my mistake, you only need one equal sign. The double equal sign is a C thing, I'm just not thinking.


Top
 Profile Send private message  
 
 Post subject: Re: sensorchangeevents
PostPosted: Fri Jul 30, 2010 9:37 am 
Offline
Phidgetly

Joined: Tue Jul 06, 2010 7:04 am
Posts: 43
and I had to put

If (e.Index = 1) Then ph = 7 - (2.5 - e.Value / 200) / (0.257179 + 0.000941468 * temp)


Top
 Profile Send private message  
 
 Post subject: Re: sensorchangeevents
PostPosted: Fri Jul 30, 2010 2:57 pm 
Offline
Phidgetly

Joined: Tue Jul 06, 2010 7:04 am
Posts: 43
got my ph value working but I have a prolem with tempchangedevents

Private Sub temp_change(ByVal index As Object, ByVal e As Phidgets.Events.TemperatureChangeEventArgs) Handles phidgetTEMP.TemperatureChange
Dim temp_probe As Double
If (e.Index = 1) Then temp_value.Text = phidgetTEMP.thermocouples(0).Temperature.ToString
End If

causes my text box called temp_value to not work any idea


Top
 Profile Send private message  
 
 Post subject: Re: sensorchangeevents
PostPosted: Fri Jul 30, 2010 4:11 pm 
Offline
Phidgetly

Joined: Tue Jul 06, 2010 7:04 am
Posts: 43
its ok got it working

Private Sub temp_change(ByVal index As Object, ByVal e As Phidgets.Events.TemperatureChangeEventArgs) Handles phidgetTEMP.TemperatureChange
If (e.Index = 1) Then temp = phidgetTEMP.thermocouples(0).Temperature
temp_value.Text = temp.ToString
end sub


Top
 Profile Send private message  
 
 Post subject: Re: sensorchangeevents
PostPosted: Sat Jul 31, 2010 3:43 am 
Offline
Phidget Mastermind

Joined: Mon Sep 28, 2009 9:04 am
Posts: 464
Again, I'm not thinking VB with the If....Then. Silly me.


Anyways, did it help with your lost packet problem?


Top
 Profile Send private message  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next

All times are UTC - 7 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


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