More info
Here is the actual code.
' - InterfaceKit full -
' In this example we display the interface kit details including the number of inputs and outputs it allows,
' and displays the values of the inputs and outputs.
' Note: This example was developed and run with an LED in digital output 0 and an LED in digital output 7 to test
' the simulated digital output.
'
' Please note that this example was designed to work with only one Phidget InterfaceKit connected.
' For an example using multiple Phidget InterfaceKits, please see a "multiple" example in the InterfaceKit Examples folder.
'
' Copyright 2007 Phidgets Inc.
' This work is licensed under the Creative Commons Attribution 2.5 Canada License.
' To view a copy of this license, visit
Creative Commons — Attribution 2.5 Canada
Public Class Form1
Dim WithEvents phidgetIFK As Phidgets.InterfaceKit
Private digiOutArray As CheckBox()
Public Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
End Sub
'initialize the device
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
makeDigiOutArray()
ratioChk.Enabled = False
ratioChk.Checked = False
'To reduce code complexity we assume that there is one PhidgetInterfacekit
'attached to the PC before the program is run.
Try
phidgetIFK = New Phidgets.InterfaceKit
phidgetIFK.open()
Catch ex As Exception
MessageBox.Show(ex.ToString())
End Try
End Sub
'attach event handler... here we'll display the interface kit details as well as determine how many output and input
'fields to display as well as determine the range of values for the output simulator slider
Private Sub phidgetIFK_Attach(ByVal sender As Object, _
ByVal e As Phidgets.Events.AttachEventArgs) _
Handles phidgetIFK.Attach
attachedTxt.Text = phidgetIFK.Attached.ToString()
nameTxt.Text = phidgetIFK.Name
serialTxt.Text = sender.SerialNumber.ToString()
versionTxt.Text = sender.Version.ToString()
digiOutNumTxt.Text = sender.outputs.Count.ToString()
Dim i As Integer
For i = 0 To phidgetIFK.outputs.Count - 1
digiOutArray(i).Visible = True
digiOutArray(i).Enabled = True
Next i
End Sub
''ifkit detach event handler... here we display the statu, which will be false as the device is not attached. We
''will also clear the display fields and hide the inputs and outputs.
Private Sub phidgetIFK_Detach(ByVal sender As Object, _
ByVal e As Phidgets.Events.DetachEventArgs) _
Handles phidgetIFK.Detach
attachedTxt.Text = phidgetIFK.Attached.ToString()
nameTxt.Text = ""
serialTxt.Text = ""
versionTxt.Text = ""
digiOutNumTxt.Text = ""
Dim i As Integer
For i = 0 To 15
digiOutArray(i).Visible = False
digiOutArray(i).Checked = False
digiOutArray(i).Enabled = False
Next
End Sub
Private Sub phidgetIFK_Error(ByVal sender As Object, _
ByVal e As Phidgets.Events.ErrorEventArgs) _
Handles phidgetIFK.Error
MessageBox.Show(e.Description)
End Sub
''digital output change event handler... here we check or uncheck the corresponding output checkbox based on the index of
''the output that generated the event
Public Sub phidgetIFK_OutputChange(ByVal sender As Object, _
ByVal e As Phidgets.Events.OutputChangeEventArgs) _
Handles phidgetIFK.OutputChange
digiOutArray(e.Index).Checked = e.Value
End Sub
'Modify the digital ouputs...Please observe the properties window in the ofrm designer for the digital output checkboxes.
'Each of the output checkboxes CheckedChanged events point to this one event handler, I use the sender object (the checkbox
'triggering the event) to get the checkbox that is changing. Also note that there is a "tag" property that is basically
'user defined data associated with the control. I used this to store the output index that the checkbox is supposed to
'represent for use in the following code to easily index the output we wanted to change. Hopefully this clarifies what
'was done in this method.
Public Sub ClickOutputs(ByVal sender As Object, ByVal e As System.EventArgs)
Dim outputIndex As Integer
Dim outputState As Boolean
outputIndex = DirectCast(sender, CheckBox).Tag
outputState = DirectCast(sender, CheckBox).CheckState
'MessageBox.Show(outputIndex.ToString() + " and " + outputState.ToString())
phidgetIFK.outputs(outputIndex) = outputState
End Sub
'Modify the sensitivity of the analog inputs. In other words, the amount that the inputs must change between
'sensorchange events.
'Note - maybe this is where should add in time constraint between valves?
Private Sub inputTrk_Scroll(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles inputTrk.Scroll
Try
Dim i As Integer
For i = 0 To phidgetIFK.sensors.Count - 1
phidgetIFK.sensors(i).Sensitivity = inputTrk.Value
Next
sensitivityTxt.Text = inputTrk.Value.ToString()
Catch ex As Exception
MessageBox.Show(ex.Message.ToString())
End Try
End Sub
Private Sub ratioChk_CheckedChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles ratioChk.CheckedChanged
If phidgetIFK.Attached Then
phidgetIFK.ratiometric = ratioChk.Checked
End If
End Sub
'When the application is terminating, close the Phidget.
Private Sub Form1_FormClosing(ByVal sender As Object, _
ByVal e As System.Windows.Forms.FormClosingEventArgs) _
Handles Me.FormClosing
RemoveHandler phidgetIFK.Attach, AddressOf phidgetIFK_Attach
RemoveHandler phidgetIFK.Detach, AddressOf phidgetIFK_Detach
RemoveHandler phidgetIFK.Error, AddressOf phidgetIFK_Error
RemoveHandler phidgetIFK.OutputChange, AddressOf phidgetIFK_OutputChange
Application.DoEvents()
phidgetIFK.close()
End Sub
'this method creates the digital output array that corresponds to the group of checkboxes
'we are using to represent the state of the digital outputs on the interface kit
Sub makeDigiOutArray()
ReDim digiOutArray(15)
digiOutArray(0) = checkBox16
digiOutArray(1) = checkBox17
digiOutArray(2) = checkBox18
digiOutArray(3) = checkBox19
digiOutArray(4) = checkBox20
digiOutArray(5) = checkBox21
digiOutArray(6) = checkBox22
digiOutArray(7) = checkBox23
digiOutArray(8) = checkBox24
digiOutArray(9) = checkBox25
digiOutArray(10) = checkBox26
digiOutArray(11) = checkBox27
digiOutArray(12) = checkBox28
digiOutArray(13) = checkBox29
digiOutArray(14) = checkBox30
digiOutArray(15) = checkBox31
Dim i As Integer
For i = 0 To 15
digiOutArray(i).Visible = False
AddHandler digiOutArray(i).Click, AddressOf ClickOutputs
Next i
End Sub
Public Shared Sub checkBox16_CheckedChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles checkBox16.CheckedChanged
End Sub
Private Sub groupBox3_Enter(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles groupBox3.Enter
End Sub
Private Sub groupBox2_Enter(ByVal sender As System.Object, _
ByVal e As System.EventArgs)
End Sub
Private Sub label1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles label1.Click
End Sub
Private Sub label8_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles label8.Click
End Sub
Private Sub groupBox1_Enter(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles groupBox1.Enter
End Sub
Private Sub label2_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles label2.Click
End Sub
Private Sub groupBox4_Enter(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles groupBox4.Enter
End Sub
Public Sub Timer1_Tick(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Timer1.Tick
ListBox1.Items.Add(ListBox1.Items.Count)
!!This is where we are trying to get it to work, basically whats happpening
now is the checkbox is being check, superficially, without sending the signal to the chip that would normally be sent if a user clicked the box!!!
If ListBox1.Items.Count > 10 Then
checkBox16.CheckState = 1
ElseIf checkBox16.CheckState = 0 Then
End If
End Sub
Public Shared Sub OnTimerEvent(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles checkBox16.CheckStateChanged
End Sub
Private Sub attachedTxt_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles attachedTxt.TextChanged
End Sub
Private Sub DateTime_TextChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs)
End Sub
Private Sub nameTxt_TextChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles nameTxt.TextChanged
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles ListBox1.SelectedIndexChanged
End Sub
Private Sub checkBox17_CheckedChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles checkBox17.CheckedChanged
End Sub
Private Sub checkBox20_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles checkBox20.CheckedChanged
End Sub
End Class