Getting K8047 to work with MS-Visual Studio 2010

Hello, i’m trying to get data out of K8047 into my older application for K8055. With K8055 it worked well. With K8047 I can’t get data out of it.
I’m not succesfull writing “ReadData” into the program as in the visual basic example from the documentation.

Your help will be appreciated

My code is:

    Private Declare Sub StartDevice Lib "k8047d.dll" ()
    Private Declare Sub StopDevice Lib "k8047d.dll" ()
    Private Declare Sub LEDon Lib "k8047d.dll" ()
    Private Declare Sub LEDoff Lib "k8047d.dll" ()

    'INPUT PROCEDURE
    Private Declare Sub ReadData Lib "k8047d.dll" (Array_Pointer As Long)

    'OUTPUT PROCEDURE
    Private Declare Sub SetGain Lib "k8047d.dll" (ByVal Channel_no As Long, ByVal Gain As Long)

    'Declare variables
    Dim DataBuffer(0 To 7) As Long


    'Dim CardAddress As Integer
    Dim Channel As Integer
    Dim a, b, c, d, e, f, g, h, i, j, k, l, m, q, aoud, boud, coud, doud, hysa, hysb, hysc, hysd, Uur, Minuut, Tijd, Dag As Integer
    Dim Data00, Data01, Data02, Data03, Data04, Data05, Data06, Data07 As Integer

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Disposed, Timer1.Tick
        Select Case j
            Case Is < 8

                ReadData(DataBuffer(0))

                Data00 = DataBuffer(0)
                Data01 = DataBuffer(1)
                Data02 = DataBuffer(2)
                Data03 = DataBuffer(3)


                a = Data00
                b = Data01
                c = Data02
                d = Data03


                hysa = 0

                Tijdklok.Text = TimeOfDay()
                If j = 0 Then
                    Db1DataSet.db1.Rows.Add(Now(), Data00, Data01, Data02, Data03)
                    j = 1
                End If
                If Second(TimeOfDay) > 50 And Second(TimeOfDay) < 55 Then
                    l = 0
                    m = 0
                End If

                If (((Second(TimeOfDay) = 0) And ((a - aoud >= hysa) Or (aoud - a > hysa) Or (b - boud > hysb) Or (boud - b > hysb)))) Then
                    l = l + 1
                    Db1DataSet.db1.Rows.Add(Now(), Data00, Data01, Data02, Data03)
                    k = 0
                    aoud = a
                    boud = b
                    coud = c
                    doud = d
                    'TextBox1.Text = k
                    Me.Db1TableAdapter.Update(Me.Db1DataSet.db1)
                End If

                If (Minute(TimeOfDay) = 0 And Second(TimeOfDay) = 5 And m = 0) Then
                    m = m + 1
                    instance = Now()
                    returnDate = instance.ToShortDateString
                    Tijd = 100 * Hour(TimeOfDay) + Minute(TimeOfDay)
                    FilenameSave = ("C:\Meetwaarden\A" & returnDate & "_" & Tijd & ".mdb")

                    My.Computer.FileSystem.CopyFile("db1.mdb", FilenameSave, True)
                    TextBox1.Text = FilenameSave
                End If

            Case 8
                'ClearDigitalChannel(8)
                'SetDigitalChannek(1)
                j = 1
        End Select
    End Sub

End Class

You should also use the StartDevice() to “open” the USB link to the K8047.

The original example code was written for Visual Basic 6.
It is not compatible with Visual Studio 2010.
You have to change every ‘As Long’ to ‘As Integer’ etc.
For more info please see “Integer Data Type for Visual Basic 6.0 Users”: http://msdn.microsoft.com/en-us/library/7f5ztkz3(v=vs.90).aspx

Change:[code]'INPUT PROCEDURE
Private Declare Sub ReadData Lib “k8047d.dll” (Array_Pointer As Long)

'OUTPUT PROCEDURE
Private Declare Sub SetGain Lib “k8047d.dll” (ByVal Channel_no As Long, ByVal Gain As Long)

'Declare variables
Dim DataBuffer(0 To 7) As Long[/code]

to: [code] 'INPUT PROCEDURE
Private Declare Sub ReadData Lib “k8047d.dll” (ByRef ArrayPointer As Integer)

'OUTPUT PROCEDURE
Private Declare Sub SetGain Lib "k8047d.dll" (ByVal ChannelNo As Integer, ByVal Gain As Integer)

'Declare variables
Dim DataBuffer(0 To 7) As Integer[/code]

Here is a simple working demo with just two buttons, some labels and the timer:

[code]Public Class Form1
'Declare use of the DLL
'K8047D.DLL interface

'GENERAL PROCEDURES
Private Declare Sub StartDevice Lib "k8047d.dll" ()
Private Declare Sub StopDevice Lib "k8047d.dll" ()

'INPUT PROCEDURE
Private Declare Sub ReadData Lib "k8047d.dll" (ByRef ArrayPointer As Integer)

'OUTPUT PROCEDURE
Private Declare Sub SetGain Lib "k8047d.dll" (ByVal ChannelNo As Integer, ByVal Gain As Integer)
Private Declare Sub LEDon Lib "k8047d.dll" ()
Private Declare Sub LEDoff Lib "k8047d.dll" ()

Dim DataBuffer(0 To 7) As Integer

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    StartDevice()
    LEDon()
    SetGain(1, 10)
    SetGain(2, 10)
    SetGain(3, 10)
    SetGain(4, 10)
    Timer1.Enabled = True
End Sub

Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
    ReadData(DataBuffer(0))
    Label1.Text = Str(DataBuffer(0))
    Label2.Text = Str(DataBuffer(1))
    Label3.Text = Str(DataBuffer(2))
    Label4.Text = Str(DataBuffer(3))
    Label5.Text = Str(DataBuffer(4))
    Label6.Text = Str(DataBuffer(5))
End Sub

Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
    Timer1.Enabled = False
    LEDoff()
    StopDevice()
End Sub

End Class[/code]

Here is the link to download the whole project written in Visual Studio 2010:
app.box.com/s/3tvwzely4uqfdlrikbru

thnx for fast reply and instructions!!

Hey can you help me with MS Visual C++? i can’t include the dll.
it doesn’t work. do you have a compatible .lib ?

I’m sorry, there is no .LIB file for the Microsoft C++.
You may use run-time dynamic linking: http://msdn.microsoft.com/en-us/library/windows/desktop/ms686944(v=vs.85).aspx
You can also use the Platform Invocation Services, PInvoke, that enables to call C-style functions in DLLs.
Please see K8055DemoVC_2008 how to use the DllImport Attribute. For more info: “Calling Native Functions from Managed Code”: http://msdn.microsoft.com/en-us/library/ms235282(v=vs.110).aspx
Alternatively you can use the GetProcAddress function to retrieve the address of an exported function from the DLL.