K8055 & VB script control

I recently purchased the k8055 to try to learn how to utilize it to control various components. The k8055 works great with the demo software. I studied the source a little to try to learn how to connect to the board. I think I’m close but not getting the intended results. Any advice on the code below would be appreciated…

[code]Public Class Form1

Private Declare Function OpenDevice Lib "k8055d.dll" (ByVal CardAddress As Integer) As Integer
Private Declare Sub CloseDevice Lib "k8055d.dll" ()
Private Declare Function ReadAnalogChannel Lib "k8055d.dll" (ByVal Channel As Integer) As Integer
Private Declare Sub ReadAllAnalog Lib "k8055d.dll" (ByRef Data1 As Integer, ByRef Data2 As Integer)
Private Declare Sub OutputAnalogChannel Lib "k8055d.dll" (ByVal Channel As Integer, ByVal Data As Integer)
Private Declare Sub OutputAllAnalog Lib "k8055d.dll" (ByVal Data1 As Integer, ByVal Data2 As Integer)
Private Declare Sub ClearAnalogChannel Lib "k8055d.dll" (ByVal Channel As Integer)
Private Declare Sub SetAllAnalog Lib "k8055d.dll" ()
Private Declare Sub ClearAllAnalog Lib "k8055d.dll" ()
Private Declare Sub SetAnalogChannel Lib "k8055d.dll" (ByVal Channel As Integer)
Private Declare Sub WriteAllDigital Lib "k8055d.dll" (ByVal Data As Integer)
Private Declare Sub ClearDigitalChannel Lib "k8055d.dll" (ByVal Channel As Integer)
Private Declare Sub ClearAllDigital Lib "k8055d.dll" ()
Private Declare Sub SetDigitalChannel Lib "k8055d.dll" (ByVal Channel As Integer)
Private Declare Sub SetAllDigital Lib "k8055d.dll" ()
Private Declare Function ReadDigitalChannel Lib "k8055d.dll" (ByVal Channel As Integer) As Boolean
Private Declare Function ReadAllDigital Lib "k8055d.dll" () As Integer
Private Declare Function ReadCounter Lib "k8055d.dll" (ByVal CounterNr As Integer) As Integer
Private Declare Sub ResetCounter Lib "k8055d.dll" (ByVal CounterNr As Integer)
Private Declare Sub SetCounterDebounceTime Lib "k8055d.dll" (ByVal CounterNr As Integer, ByVal DebounceTime As Integer)
'Public up, down, lleft, rright As Boolean 'to keep track of which buttons are already pressed 

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim CardAddress As Integer
    Dim h As Integer
    CardAddress = 3
    h = OpenDevice(CardAddress)
    Label1.Text = "Card " + Str(h) + "connected"
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    SetAllDigital()
End Sub
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
    Select Case e.KeyCode
        Case Keys.A : SetDigitalChannel(8) : Label5.ForeColor = Color.Red
        Case Keys.L : SetDigitalChannel(4) : Label4.ForeColor = Color.Red
        Case Keys.Z : SetDigitalChannel(6) : Label2.ForeColor = Color.Red
        Case Keys.K : SetDigitalChannel(2) : Label3.ForeColor = Color.Red

    End Select
End Sub

Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
    Select Case e.KeyCode
        Case Keys.A : ClearDigitalChannel(8) : Label5.ForeColor = Color.Black
        Case Keys.L : ClearDigitalChannel(4) : Label4.ForeColor = Color.Black
        Case Keys.Z : ClearDigitalChannel(6) : Label2.ForeColor = Color.Black
        Case Keys.K : ClearDigitalChannel(2) : Label3.ForeColor = Color.Black

    End Select
End Sub

End Class[/code]

To get the code work on Form1 you have to set the form’s KeyPreview property to True.

Adding a TextBox on the form makes this also to work:
Just enter the characters ‘a’, ‘l’, ‘z’, ‘k’ to the TextBox and the card works as expected:

[code] Private Sub TextBox3_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox3.KeyDown
Select Case e.KeyCode
Case Keys.A : SetDigitalChannel(8) : Label5.ForeColor = Color.Red
Case Keys.L : SetDigitalChannel(4) : Label4.ForeColor = Color.Red
Case Keys.Z : SetDigitalChannel(6) : Label2.ForeColor = Color.Red
Case Keys.K : SetDigitalChannel(2) : Label3.ForeColor = Color.Red
End Select
End Sub

Private Sub TextBox3_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox3.KeyUp
    Select Case e.KeyCode
        Case Keys.A : ClearDigitalChannel(8) : Label5.ForeColor = Color.Black
        Case Keys.L : ClearDigitalChannel(4) : Label4.ForeColor = Color.Black
        Case Keys.Z : ClearDigitalChannel(6) : Label2.ForeColor = Color.Black
        Case Keys.K : ClearDigitalChannel(2) : Label3.ForeColor = Color.Black
    End Select
End Sub [/code]

Awesome! It worked great!
I can see I need to learn more about VB. :smiley:

jlv

Hello,

I’m new to this forum.

I have a question about the usb k8055 and i used the radio automation Mairlist for making radio.

Is there a script mls. to switch the outputs on.
I’m not a script writer so maybe anybody can help thanks in a million.

Only the outputs!, Inputs work like a charme!..

Cheers, Frank