I too am trying to get the K8055 working in Visual Basic Express 2008. The supplied Demo works fine so I know the card is fine but I want to write my own utilities. The source code supplied on the CDROM wont convert - gives numerous errors, so I tried writing my own, using the k8055d.dll calls listed. Everything works except the call to the DLL which returns a large number instead of 0-3 or -1. Building produces no error but I get a run-time error on terminating the application.
I’m running Wndows XP Home SP3 on a Pentium 4 HT. I checked that the k8055d.dll file was installed in the System32 folder. I have one form with a groupbox containing 4 radiobuttons for selecting the card address, a Connect button and a Label for displaying the result of clicking the Connect button. I also have a Label to display the output from ADC1 when clicked.
This is my code :-
[code]Option Explicit On
Public Class Form1
Public gCardAddress As Long
Private Declare Function OpenDevice Lib "k8055d.dll" (ByVal CardAddress As Long) As Long
Private Declare Sub CloseDevice Lib "k8055d.dll" ()
Private Declare Function ReadAnalogChannel Lib "k8055d.dll" (ByVal Channel As Long) As Long
Private Declare Sub ReadAllAnalog Lib "k8055d.dll" (ByVal Data1 As Long, ByVal Data2 As Long)
Private Declare Sub OutputAnalogChannel Lib "k8055d.dll" (ByVal Channel As Long, ByVal Data As Long)
Private Declare Sub OutputAllAnalog Lib "k8055d.dll" (ByVal Data1 As Long, ByVal Data2 As Long)
Private Declare Sub ClearAnalogChannel Lib "k8055d.dll" (ByVal Channel As Long)
Private Declare Sub SetAllAnalog Lib "k8055d.dll" ()
Private Declare Sub ClearAllAnalog Lib "k8055d.dll" ()
Private Declare Sub SetAnalogChannel Lib "k8055d.dll" (ByVal Channel As Long)
Private Declare Sub WriteAllDigital Lib "k8055d.dll" (ByVal Data As Long)
Private Declare Sub ClearDigitalChannel Lib "k8055d.dll" (ByVal Channel As Long)
Private Declare Sub ClearAllDigital Lib "k8055d.dll" ()
Private Declare Sub SetDigitalChannel Lib "k8055d.dll" (ByVal Channel As Long)
Private Declare Sub SetAllDigital Lib "k8055d.dll" ()
Private Declare Function ReadDigitalChannel Lib "k8055d.dll" (ByVal Channel As Long) As Boolean
Private Declare Function ReadAllDigital Lib "k8055d.dll" () As Long
Private Declare Function ReadCounter Lib "k8055d.dll" (ByVal CounterNr As Long) As Long
Private Declare Sub ResetCounter Lib "k8055d.dll" (ByVal CounterNr As Long)
Private Declare Sub SetCounterDebounceTime Lib "k8055d.dll" (ByVal CounterNr As Long, ByVal DebounceTime As Long)
Private Sub Connect_Click()
Dim h As Long
h = OpenDevice(gCardAddress)
Select Case h
Case 0, 1, 2, 3
Label1.Text = "Card " + Str(h) + " connected"
Case -1
Label1.Text = "Card " + Str(gCardAddress) + " not found"
End Select
End Sub
Private Sub Form_Terminate()
CloseDevice()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
gCardAddress = 0
GroupBox1.Text = "Card Address" + Str(gCardAddress)
End Sub
Private Sub RadioButton4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton4.CheckedChanged
gCardAddress = 3
GroupBox1.Text = "Card Address" + Str(gCardAddress)
End Sub
Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged
gCardAddress = 2
GroupBox1.Text = "Card Address" + Str(gCardAddress)
End Sub
Private Sub GroupBox1_Enter_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox1.Enter
End Sub
Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
gCardAddress = 1
GroupBox1.Text = "Card Address" + Str(gCardAddress)
End Sub
Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click
Dim v As Long
v = ReadAnalogChannel(0)
Label2.Text = Str(v)
End Sub
Private Sub Connect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Connect.Click
Dim h As Long
h = OpenDevice(gCardAddress)
Select Case h
Case 0, 1, 2, 3
Label1.Text = "Card " + Str(h) + " connected"
Case -1
Label1.Text = "Card " + Str(gCardAddress) + " not found"
Case Else
Label1.Text = "Error - OpenDevice returned " + Str(h)
End Select
End Sub
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
End Sub
Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitButton.Click
CloseDevice()
Close()
End Sub
End Class[/code]
I would much appreciate any suggestions or help in getting this working.