Trouble attaching first input on 16/16/0 board using VB

Technical Discussions on any InterfaceKits
Post Reply
robertAtQuestacon
Fresh meat
Posts: 3
Joined: Mon Dec 17, 2018 11:33 pm
Contact:

Trouble attaching first input on 16/16/0 board using VB

Post by robertAtQuestacon »

Have just installed latest Phidgets software and have converted visual basic software for Phidget22 API. Our application uses two 16/16/0 boards and the new Phidget Control panel shows both are working.
But when I run our code, the first input on both boards does not attach. All other inputs are fine. Any ideas?

Below is the code where I open the inputs:

Code: Select all

    Private Sub attachEvent(ByVal sender As Object, ByVal e As Phidget22.Events.AttachEventArgs) Handles kit.Attach
        'When the Phidget Stepper# attaches update the form text boxes
        ' Try
        Dim attachedDevice As Phidget22.DigitalInput = CType(sender, Phidget22.DigitalInput)
        numInputs = kit.GetDeviceChannelCount(ChannelClass.DigitalInput)
        For i As Integer = 0 To numInputs - 1
            Dim input As New DigitalInput
            input.Channel = i
            input.Open()
            inputs.Add(input)
        Next
        numOutputs = kit.GetDeviceChannelCount(ChannelClass.DigitalInput)
        For i As Integer = 0 To numOutputs - 1
            Dim output As New DigitalOutput
            output.Channel = i
            output.Open()
            outputs.Add(output)
        Next
        connected = True
        txtStatus = "Connected"  ' must be last
        ' Catch ex As Exception
        ' End Try
    End Sub
User avatar
mparadis
Site Admin
Posts: 959
Joined: Fri Oct 28, 2011 12:17 pm
Contact:

Re: Trouble attaching first input on 16/16/0 board using VB

Post by mparadis »

I'm not sure what could be causing this behaviour, but there are some things you can try:

- If you switch the order of your two loops, is it the first output that fails to attach instead of the first input?

- Have you tried putting a timeout in the open call (e.g. input.Open(500))?
robertAtQuestacon
Fresh meat
Posts: 3
Joined: Mon Dec 17, 2018 11:33 pm
Contact:

Re: Trouble attaching first input on 16/16/0 board using VB

Post by robertAtQuestacon »

Thanks for the quick reply.


I've tried your suggestions without success. The first input on both cards does not attach. I tried again with just one Phidget, but this had no effect.

Code: Select all

Public Class phidgetInterfaceClass
    Dim WithEvents kit As Phidget22.DigitalInput
    'WithEvents kit As Phidgets.InterfaceKit
    Dim serialNumber As Integer
    'Public inputs As Phidgets.InterfaceKitDigitalInputCollection
    'Public outputs As Phidgets.InterfaceKitDigitalOutputCollection
    Public numInputs As Integer
    Public numOutputs As Integer
    Public inputs As New List(Of DigitalInput)
    Public outputs As New List(Of DigitalOutput)

    Public connected As Boolean = False
    Public txtStatus As String = ""
    Public changes As New Queue(Of Integer)

    Public Sub New()
        open(0)
    End Sub

    Public Sub New(ByVal SN As Integer)
        open(SN)
    End Sub
    Private Sub open(ByVal SN As Integer)
        Phidget22.Phidget.InvokeEventCallbacks = True
        kit = New Phidget22.DigitalInput()
        'kit = New Phidgets.InterfaceKit
        If SN <> 0 Then
            serialNumber = SN
            kit.open(serialNumber)
        Else
            kit.open()
        End If
        connected = False
        txtStatus = "Not Connected"
    End Sub
    
       Private Sub attachEvent(ByVal sender As Object, ByVal e As Phidget22.Events.AttachEventArgs) Handles kit.Attach
        'When the Phidget attaches 
        Dim retries As Integer = 10
        'While retries > 0
        ' Try
        'Dim attachedDevice As Phidget22.DigitalInput = CType(sender, Phidget22.DigitalInput)
        Thread.Sleep(3000)
        numOutputs = kit.GetDeviceChannelCount(ChannelClass.DigitalInput)
        For i As Integer = 0 To numOutputs - 1
            Dim output As New DigitalOutput
            output.Channel = i
            output.Open(500)
            outputs.Add(output)
        Next
        numInputs = kit.GetDeviceChannelCount(ChannelClass.DigitalInput)
        For i As Integer = 0 To numInputs - 1
            Dim input As New DigitalInput()
            input.Channel = i
            Try
                input.Open(500)
            Catch ex As Exception
                Console.WriteLine("Error for phidgetSN:" + kit.DeviceSerialNumber.ToString() + " input #" + i.ToString() + ":" + ex.Message)
            End Try
            inputs.Add(input)
        Next
        connected = True
        txtStatus = "Connected"  ' must be last
        retries = 0
        ' Catch ex As Exception
        'retries -= 1
        ' Trace.WriteLine("Error - Retires to go " & retries.ToString())
        ' End Try
        'End While
    End Sub




I'd think it was a base zero issue except the outputs all attach correctly.

I've included the initialisation code this time, so hopefully someone can see what I am doing wrong.

Thanks in advance.

P.S. Could the administrator extend the timeout on the POST A REPLY page. I got called away for half an hour and lost my previous message. :)
robertAtQuestacon
Fresh meat
Posts: 3
Joined: Mon Dec 17, 2018 11:33 pm
Contact:

Re: Trouble attaching first input on 16/16/0 board using VB

Post by robertAtQuestacon »

I think I have discovered the problem. Even though I had closed the Phidget Management software, it had left a Phidget process running that was attached to input 0.

I can't repeat the problem to test as I installed the Phidget21 driver (which works with my older code on Windows 10) and this seems to have over written the Phidget22 control panel. I much prefer the older control panel anyhow as it lets me see all the inputs at once.

Thanks for your help.
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests