8055 VS2008 Problems

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.

You are using DLL function declarations for Visual Basic 6.0.
In the declarations for the Visual Basic 2008 the “As Long” has to be replaced with “As Integer”. Do this modification everywhere in your code.
There are also many other differences between VB6 and VB2008.
See: Visual Basic Concepts
What’s New for Visual Basic 6.0 Users:
msdn2.microsoft.com/en-us/library/ms172617(VS.80.aspx
(Copy and paste this link to your browser.)

On CD there is a VB.NET project in the folder: d:\K8055 & VM110 USB board\Demo PC soft VB_NET
This project you can convert to VB2008 express.

If not yet done - it may be good idea to download latest DLL for the K8055.

You’ll find the latest DLL from Velleman downloads page: velleman.be/be/en/download/files/

[quote]k8055dll_rev3_0_2.zip
New DLL (rev 3.0.2) file for K8055 & VM110, with Windows Vista support.
Also special Microsoft VC++ version and executable examples.
k8055_dll_2_001.zip
DLL rev 2 with examples and soure code (this source can be uses also with DLL Rev 3.)[/quote]

Please see also these threads:

Thanks very much :slight_smile: I can now connect to the card. I replaced all “As Long” with “As Integer” and downloaded the latest DLL and replaced the one in System32 with the new one.

It was easy, wasn’t it? :slight_smile: