Selecting a channel on a 1048_2B

Supporting Visual Studio on Windows
Post Reply
vaporware
Fresh meat
Posts: 2
Joined: Mon Feb 12, 2024 8:35 am
Contact:

Selecting a channel on a 1048_2B

Post by vaporware »

I am trying to get a Phidget 1048_2B to select another channel however after I change the channel 0 to channel 1 I still get channel 0 values.
If I start at Channel 1 then change to Channel 0 I then get Channel 1 values for Channel 0. I even put in a delay routine thinking it needed more time. Even after 15 seconds it still does not change to a new channel reading.
Obviously I do not understand how to correctly change channels.
I am attaching my simple main code here.
Is there a command I need to call to force it to change channels ?

-----------------------------------------------------------

Private Sub ShowPhidget()

Dim StartTime As Double
StartTime = Microsoft.VisualBasic.DateAndTime.Timer
TimerOut = StartTime + 2000

Doit = True
CurrentOperation1.Text = "Attach a PhidgetTemperatureSensor 1"

Application.DoEvents()
AdvTemp0 = New Phidget22.TemperatureSensor

AdvTemp0.Open()
While AdvTemp0.Attached = False And (TimerOut < Microsoft.VisualBasic.DateAndTime.Timer)
If TimerOut >= TimerOut < Microsoft.VisualBasic.DateAndTime.Timer Then
CurrentOperation1.Text = "Attach Timeout"
Application.DoEvents()
End
End If
End While
CurrentOperation1.Text = "Attached"
Application.DoEvents()

AdvTemp0.Channel = 0
AdvTemp0.IsLocal = True
AdvTemp0.ThermocoupleType = ThermocoupleType.K

CurrentOperation2.Text = "Attach a PhidgetTemperatureSensor 2"
Application.DoEvents()
Call Delay(0.15)

While Doit = True
AdvTemp0.Channel = 0
Call Delay(0.15)
Channel0 = AdvTemp0.Temperature
Call Delay(0.15)
Label1.Text = "Current Temperature 0 : " + Str(Channel0)
Application.DoEvents()

CurrentOperation2.Text = "Attached"
Application.DoEvents()
AdvTemp0.Channel = 1
Call Delay(0.15)

Channel1 = AdvTemp0.Temperature
Call Delay(0.15)
Application.DoEvents()

Label2.Text = "Current Temperature 1 : " + Str(Channel1)
End While

End Sub
User avatar
mparadis
Site Admin
Posts: 660
Joined: Fri Oct 28, 2011 12:17 pm
Contact:

Re: Selecting a channel on a 1048_2B

Post by mparadis »

Channel is only checked when Open() is called, so changing the channel number while the channel is still open won't have any effect unless you close and reopen. But if you want to use both channels, it's usually easier to simply open both channels at the start of the program using different variable names (e.g. AdvTemp0 and AdvTemp1) and then use them as you need them.
vaporware
Fresh meat
Posts: 2
Joined: Mon Feb 12, 2024 8:35 am
Contact:

Re: Selecting a channel on a 1048_2B

Post by vaporware »

I had tried this before and it would hang in the "while loop" of the second open.
That is why I tried just changing channels..

-------------------------------------
AdvTemp0 = New Phidget22.TemperatureSensor
AdvTemp1 = New Phidget22.TemperatureSensor

AdvTemp0.Channel = 0
AdvTemp0.IsLocal = True
AdvTemp0.ThermocoupleType = ThermocoupleType.K

AdvTemp0.Open()
While AdvTemp0.Attached = False
End While
Channel0 = AdvTemp0.Temperature

AdvTemp1.Channel = 1
AdvTemp1.IsLocal = True
AdvTemp1.ThermocoupleType = ThermocoupleType.K

AdvTemp1.Open()
While AdvTemp1.Attached = False '<--- hangs here
End While
'--Go do other stuff
-------------------------------------------------
If I do not perform the second "While AdvTemp1.Attached = False "
check then it works as desired.
Otherwise it just hangs in the second loop which was why I tried to implement a "time out" (and royally failed if you look at the code).
The code that works is this
-------------------------------------
AdvTemp0 = New Phidget22.TemperatureSensor
AdvTemp1 = New Phidget22.TemperatureSensor

AdvTemp0.Channel = 0
AdvTemp0.IsLocal = True
AdvTemp0.ThermocoupleType = ThermocoupleType.K

AdvTemp0.Open()
While AdvTemp0.Attached = False
End While

Channel0 = AdvTemp0.Temperature

AdvTemp1.Channel = 1
AdvTemp1.IsLocal = True
AdvTemp1.ThermocoupleType = ThermocoupleType.K

AdvTemp1.Open()
Channel1 = AdvTemp1.Temperature
'--Go do other stuff
-------------------------------------

So basically it appears that once the device is open the first time then any additional channel opens do not have to be checked for attachment.
Essential the first "while Loop" is to check to see if there is a device attached.

Thanks for the help.
Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests