Jump to content

DLLCall USB Interface


Recommended Posts

Hi folks!

I'm new in the Autoit Scene and hope u can help me.

First i must say autoit is sooo cool, i love it.

But i have a problem with dllcall.

I like to use a dll named "k8055.dll" with autoit.

This control a usb board with outputs and inputs.

Here a link:

http://linuxk8055.free.fr/

i have a sample in vb.net

like this:

Public Class Form1

    Inherits System.Windows.Forms.Form
    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)

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim h As Integer
        Dim CardAddress As Integer
        ReadConfig()

        CardAddress = 0 
        h = OpenDevice(CardAddress) 'open vallemann usb interface
        WriteAllDigital(1)                   'set all output digis on usb board

        Me.WindowState = FormWindowState.Maximized
    End Sub

can u help me ??

thanks

Selnmich

Link to comment
Share on other sites

;;Private Declare Function OpenDevice Lib "k8055d.dll" (ByVal CardAddress As Integer) As Integer
Func USBOpenDevice($CardAddress)
   $result = DLLCall("k8055d.dll", "int", "OpenDevice", "int", $CardAddress)
   Return $result[0]
EndFunc

;;Private Declare Sub CloseDevice Lib "k8055d.dll" ()
Func USBCloseDevice()
   $result = DLLCall("k8055d.dll", "none", "CloseDevice")
   Return ;;$result[0]
EndFunc

;;Private Declare Function ReadAnalogChannel Lib "k8055d.dll" (ByVal Channel As Integer) As Integer
Func USBReadAnalogChannel($Channel)
   $result = DLLCall("k8055d.dll", "int", "ReadAnalogChannel", "int", $Channel)
   Return $result[0]
EndFunc

;;Private Declare Sub ReadAllAnalog Lib "k8055d.dll" (ByRef Data1 As Integer, ByRef Data2 As Integer)
;;; Cannot convert to DLLCall syntax. If i remember correctly, you cannot pass things by reference.

;;Private Declare Sub OutputAnalogChannel Lib "k8055d.dll" (ByVal Channel As Integer, ByVal Data As Integer)
Func USBOutputAnalogChannel($Channel, $Data)
   $result = DLLCall("k8055d.dll", "none", "OutputAnalogChannel", "int", $Channel, "int", $Data)
EndFunc

;;Private Declare Sub OutputAllAnalog Lib "k8055d.dll" (ByVal Data1 As Integer, ByVal Data2 As Integer)
Func USBOutputAllAnalog($Data1, $Data2)
   $result = DLLCall("k8055d.dll", "none", "OutputAllAnalog", "int", $Data1, "int", $Data2)
EndFunc

;;Private Declare Sub ClearAnalogChannel Lib "k8055d.dll" (ByVal Channel As Integer)
Func USBClearAnalogChannel()
   $result = DLLCall("k8055d.dll", "none", "ClearAnalogChannel")
EndFunc

;;Private Declare Sub SetAllAnalog Lib "k8055d.dll" ()
Func USBSetAllAnalog()
   $result = DLLCall("k8055d.dll", "none", "SetAllAnalog")
EndFunc

;;Private Declare Sub ClearAllAnalog Lib "k8055d.dll" ()
Func USBClearAllAnalog()
   $result = DLLCall("k8055d.dll", "none", "ClearAllAnalog")
EndFunc

;;Private Declare Sub SetAnalogChannel Lib "k8055d.dll" (ByVal Channel As Integer)
Func USBSetAnalogChannel($Chanel)
   $result = DLLCall("k8055d.dll", "none", "SetAnalogChannel", "int", $Channel)
EndFunc

;;Private Declare Sub WriteAllDigital Lib "k8055d.dll" (ByVal Data As Integer)
Func USBWriteAllDigita($Data)
   $result = DLLCall("k8055d.dll", "none", "WriteAllDigital", "int", $Data)
EndFunc

;;Private Declare Sub ClearDigitalChannel Lib "k8055d.dll" (ByVal Channel As Integer)
Func USBClearDigitalChannel($Channel)
   $result = DLLCall("k8055d.dll", "none", "ClearDigitalChannel", "int", $Channel)
EndFunc

;;Private Declare Sub ClearAllDigital Lib "k8055d.dll" ()
Func USBClearAllDigital()
   $result = DLLCall("k8055d.dll", "none", "ClearAllDigital")
EndFunc

;;Private Declare Sub SetDigitalChannel Lib "k8055d.dll" (ByVal Channel As Integer)
Func USBSetDigitalChannel($Channel)
   $result = DLLCall("k8055d.dll", "none", "SetDigitalChannel", "int", $Channel)
EndFunc

;;Private Declare Sub SetAllDigital Lib "k8055d.dll" ()
Func USBSetAllDigital()
   $result = DLLCall("k8055d.dll", "none", "SetAllDigital")
EndFunc

;;Private Declare Function ReadDigitalChannel Lib "k8055d.dll" (ByVal Channel As Integer) As Boolean
Func USBReadDigitalChannel($Channel)
   $result = DLLCall("k8055d.dll", "bool", "ReadDigitalChannel", "int", $Channel)
   Return $result[0]
EndFunc

;;Private Declare Function ReadAllDigital Lib "k8055d.dll" () As Integer
Func USBReadAllDigital()
   $result = DLLCall("k8055d.dll", "int", "ReadAllDigital")
   Return $result[0]
EndFunc

;;Private Declare Function ReadCounter Lib "k8055d.dll" (ByVal CounterNr As Integer) As Integer
Func USBReadCounter()
   $result = DLLCall("k8055d.dll", "int", "ReadCounter")
   Return $result[0]
EndFunc

;;Private Declare Sub ResetCounter Lib "k8055d.dll" (ByVal CounterNr As Integer)
Func USBResetCounter($count)
   $result = DLLCall("k8055d.dll", "none", "ResetCounter", "int", $count)
EndFunc

;;Private Declare Sub SetCounterDebounceTime Lib "k8055d.dll" (ByVal CounterNr As Integer, ByVal   DebounceTime As Integer)
Func USBSetCounterDebounceTime($count, $detime)
   $result = DLLCall("k8055d.dll", "none", "SetCounterDebounceTime", "int", $count,"int", $detime)
EndFunc

#)

Edited by nfwu
Link to comment
Share on other sites

;;Private Declare Function OpenDevice Lib "k8055d.dll" (ByVal CardAddress As Integer) As Integer
Func USBOpenDevice($CardAddress)
   $result = DLLCall("k8055d.dll", "int", "OpenDevice", "int", $CardAddress)
   Return $result[0]
EndFunc

;;Private Declare Sub CloseDevice Lib "k8055d.dll" ()
Func USBCloseDevice()
   $result = DLLCall("k8055d.dll", "none", "CloseDevice")
   Return ;;$result[0]
EndFunc

;;Private Declare Function ReadAnalogChannel Lib "k8055d.dll" (ByVal Channel As Integer) As Integer
Func USBReadAnalogChannel($Channel)
   $result = DLLCall("k8055d.dll", "int", "ReadAnalogChannel", "int", $Channel)
   Return $result[0]
EndFunc

;;Private Declare Sub ReadAllAnalog Lib "k8055d.dll" (ByRef Data1 As Integer, ByRef Data2 As Integer)
;;; Cannot convert to DLLCall syntax. If i remember correctly, you cannot pass things by reference.

;;Private Declare Sub OutputAnalogChannel Lib "k8055d.dll" (ByVal Channel As Integer, ByVal Data As Integer)
Func USBOutputAnalogChannel($Channel, $Data)
   $result = DLLCall("k8055d.dll", "none", "OutputAnalogChannel", "int", $Channel, "int", $Data)
EndFunc

;;Private Declare Sub OutputAllAnalog Lib "k8055d.dll" (ByVal Data1 As Integer, ByVal Data2 As Integer)
Func USBOutputAllAnalog($Data1, $Data2)
   $result = DLLCall("k8055d.dll", "none", "OutputAllAnalog", "int", $Data1, "int", $Data2)
EndFunc

;;Private Declare Sub ClearAnalogChannel Lib "k8055d.dll" (ByVal Channel As Integer)
Func USBClearAnalogChannel()
   $result = DLLCall("k8055d.dll", "none", "ClearAnalogChannel")
EndFunc

;;Private Declare Sub SetAllAnalog Lib "k8055d.dll" ()
Func USBSetAllAnalog()
   $result = DLLCall("k8055d.dll", "none", "SetAllAnalog")
EndFunc

;;Private Declare Sub ClearAllAnalog Lib "k8055d.dll" ()
Func USBClearAllAnalog()
   $result = DLLCall("k8055d.dll", "none", "ClearAllAnalog")
EndFunc

;;Private Declare Sub SetAnalogChannel Lib "k8055d.dll" (ByVal Channel As Integer)
Func USBSetAnalogChannel($Chanel)
   $result = DLLCall("k8055d.dll", "none", "SetAnalogChannel", "int", $Channel)
EndFunc

;;Private Declare Sub WriteAllDigital Lib "k8055d.dll" (ByVal Data As Integer)
Func USBWriteAllDigita($Data)
   $result = DLLCall("k8055d.dll", "none", "WriteAllDigital", "int", $Data)
EndFunc

;;Private Declare Sub ClearDigitalChannel Lib "k8055d.dll" (ByVal Channel As Integer)
Func USBClearDigitalChannel($Channel)
   $result = DLLCall("k8055d.dll", "none", "ClearDigitalChannel", "int", $Channel)
EndFunc

;;Private Declare Sub ClearAllDigital Lib "k8055d.dll" ()
Func USBClearAllDigital()
   $result = DLLCall("k8055d.dll", "none", "ClearAllDigital")
EndFunc

;;Private Declare Sub SetDigitalChannel Lib "k8055d.dll" (ByVal Channel As Integer)
Func USBSetDigitalChannel($Channel)
   $result = DLLCall("k8055d.dll", "none", "SetDigitalChannel", "int", $Channel)
EndFunc

;;Private Declare Sub SetAllDigital Lib "k8055d.dll" ()
Func USBSetAllDigital()
   $result = DLLCall("k8055d.dll", "none", "SetAllDigital")
EndFunc

;;Private Declare Function ReadDigitalChannel Lib "k8055d.dll" (ByVal Channel As Integer) As Boolean
Func USBReadDigitalChannel($Channel)
   $result = DLLCall("k8055d.dll", "bool", "ReadDigitalChannel", "int", $Channel)
   Return $result[0]
EndFunc

;;Private Declare Function ReadAllDigital Lib "k8055d.dll" () As Integer
Func USBReadAllDigital()
   $result = DLLCall("k8055d.dll", "int", "ReadAllDigital")
   Return $result[0]
EndFunc

;;Private Declare Function ReadCounter Lib "k8055d.dll" (ByVal CounterNr As Integer) As Integer
Func USBReadCounter()
   $result = DLLCall("k8055d.dll", "int", "ReadCounter")
   Return $result[0]
EndFunc

;;Private Declare Sub ResetCounter Lib "k8055d.dll" (ByVal CounterNr As Integer)
Func USBResetCounter($count)
   $result = DLLCall("k8055d.dll", "none", "ResetCounter", "int", $count)
EndFunc

;;Private Declare Sub SetCounterDebounceTime Lib "k8055d.dll" (ByVal CounterNr As Integer, ByVal   DebounceTime As Integer)
Func USBSetCounterDebounceTime($count, $detime)
   $result = DLLCall("k8055d.dll", "none", "SetCounterDebounceTime", "int", $count,"int", $detime)
EndFunc

#)

wow cool, it's work s for me, many many thanks !!!

cya

SelnMich

Link to comment
Share on other sites

HI,

I can set outputs, Inputs and works good.

Only one problem i had.

I must set an output while left mouse button down on "Button Control" and cleared wenn mouse button up.

So if you have an idea please tell me.

selnmich

Link to comment
Share on other sites

That board looks cool, I was thinking of buying it from www.electronickits.com

how do you like it? does it work with autoit though, did you get it to work.

Another link you may find interesting http://www.rev-ed.co.uk/picaxe/ I recently bought one to build a custom timer, very easy to program!

2015 - Still no flying cars, instead blankets with sleeves.

Link to comment
Share on other sites

  • 3 months later...

just to say cheers for posting the dll call

im having a little trouble getting this to work .

i cant get get this work when usin autoit .

im new to auto it

please could someone give me a sample of a very simple script just to turn on one output say .

this would provide a start so i can see hows its done.

any help would be great.

thanks

Link to comment
Share on other sites

  • 10 months later...

Hi guys,

I have one of these cards, but haven't done much yet.

just bought is today to test its qualities... tried te recreate the demo inlcuded on the CD you get with the interface.

It'll show you teh possibilities, it's just a quick post.

CODE
;===========================================

; inlcudes

;===========================================

#include <k8055.au3>

#include <GUIConstants.au3>

;===========================================

; gui

;===========================================

Opt("GUIOnEventMode", 1)

$Form_1 = GUICreate("Velleman 8055-1 kit demo", 467, 246, 326, 253)

GUISetOnEvent($GUI_EVENT_CLOSE, "FormClose")

$do8 = GUICtrlCreateCheckbox("do8", 416, 144, 17, 17)

GUICtrlSetOnEvent(-1, "do8Click")

$do7 = GUICtrlCreateCheckbox("do7", 392, 144, 17, 17)

GUICtrlSetOnEvent(-1, "do7Click")

$do6 = GUICtrlCreateCheckbox("do6", 368, 144, 17, 17)

GUICtrlSetOnEvent(-1, "do6Click")

$do5 = GUICtrlCreateCheckbox("do5", 344, 144, 17, 17)

GUICtrlSetOnEvent(-1, "do5Click")

$do4 = GUICtrlCreateCheckbox("do4", 320, 144, 17, 17)

GUICtrlSetOnEvent(-1, "do4Click")

$do3 = GUICtrlCreateCheckbox("do3", 296, 144, 17, 17)

GUICtrlSetOnEvent(-1, "do3Click")

$do2 = GUICtrlCreateCheckbox("do2", 272, 144, 17, 17)

GUICtrlSetOnEvent(-1, "do2Click")

$do1 = GUICtrlCreateCheckbox("do1", 248, 144, 17, 17)

GUICtrlSetOnEvent(-1, "do1Click")

$ao1 = GUICtrlCreateSlider(280, 32, 153, 25)

GUICtrlSetOnEvent(-1, "ao1Change")

$ao2 = GUICtrlCreateSlider(280, 64, 153, 25)

GUICtrlSetOnEvent(-1, "ao2Change")

$Group1 = GUICtrlCreateGroup("Analog out", 232, 16, 217, 81)

$Label3 = GUICtrlCreateLabel("Out 1", 248, 40, 30, 17)

$Label4 = GUICtrlCreateLabel("Out 2", 248, 64, 30, 17)

GUICtrlCreateGroup("", -99, -99, 1, 1)

$Group3 = GUICtrlCreateGroup("Digital out", 232, 104, 217, 97)

$Label2 = GUICtrlCreateLabel("1 2 3 4 5 6 7 8", 248, 128, 181, 17)

GUICtrlCreateGroup("", -99, -99, 1, 1)

$Group4 = GUICtrlCreateGroup("Analog in", 16, 16, 201, 81)

GUICtrlCreateGroup("", -99, -99, 1, 1)

$Group5 = GUICtrlCreateGroup("Digital in", 16, 104, 201, 65)

$Label5 = GUICtrlCreateLabel("In 1", 32, 132, 22, 17)

$Label6 = GUICtrlCreateLabel("In 2", 128, 132, 22, 17)

$ai1 = GUICtrlCreateInput("", 56, 128, 57, 21, BitOR($ES_AUTOHSCROLL, $ES_READONLY))

$ai2 = GUICtrlCreateInput("", 152, 128, 57, 21, BitOR($ES_AUTOHSCROLL, $ES_READONLY))

GUICtrlCreateGroup("", -99, -99, 1, 1)

$di1 = GUICtrlCreateCheckbox("di1", 32, 64, 17, 17)

$di2 = GUICtrlCreateCheckbox("di2", 70, 64, 17, 17)

$di3 = GUICtrlCreateCheckbox("di3", 108, 64, 17, 17)

$di4 = GUICtrlCreateCheckbox("di4", 146, 64, 17, 17)

$di5 = GUICtrlCreateCheckbox("di5", 184, 64, 17, 17)

$Label1 = GUICtrlCreateLabel(" 1 2 3 4 5", 32, 48, 163, 17)

$btn_loop = GUICtrlCreateButton("Loop", 248, 176, 81, 17, 0)

GUICtrlSetOnEvent(-1, "btn_loopClick")

$btn_random = GUICtrlCreateButton("Random", 352, 176, 81, 17, 0)

GUICtrlSetOnEvent(-1, "btn_randomClick")

GUISetState(@SW_SHOW)

;===========================================

; vars

;===========================================

Dim $dostate = "none"

Dim $ailevel1 = 0

Dim $ailevel2 = 255

Dim $ledloop = 0

;===========================================

; main program

;===========================================

DllOpen("k8055d.dll")

USBOpenDevice (0)

While 1

$msg = GUIGetMsg()

ReadDI()

ReadAI()

digiout($dostate)

If $msg = $GUI_EVENT_CLOSE Then

Exit

EndIf

WEnd

USBCloseDevice ()

;===========================================

; functions

;===========================================

Func btn_loopClick()

If GUICtrlRead($btn_loop) = "loop" Then

$dostate = "loop"

$ledloop = 1

GUICtrlSetData($btn_loop, "stop")

GUICtrlSetStyle($btn_random, $WS_DISABLED)

Else

$dostate = "none"

GUICtrlSetData($btn_loop, "loop")

GUICtrlSetStyle($btn_random, $WS_VISIBLE)

EndIf

EndFunc ;==>btn_loopClick

Func btn_randomClick()

If GUICtrlRead($btn_random) = "random" Then

$dostate = "random"

GUICtrlSetData($btn_random, "stop")

GUICtrlSetStyle($btn_loop, $WS_DISABLED)

Else

$dostate = "none"

GUICtrlSetData($btn_random, "random")

GUICtrlSetStyle($btn_loop, $WS_VISIBLE)

EndIf

EndFunc ;==>btn_randomClick

Func ReadDI()

$di = USBReadAllDigital ()

; couldn't think of another way to parse the input bits...

If $di >= 16 Then

$di = $di - 16

GUICtrlSetState($di5, 1)

Else

GUICtrlSetState($di5, $GUI_UNCHECKED)

EndIf

If $di >= 8 Then

$di = $di - 8

GUICtrlSetState($di4, 1)

Else

GUICtrlSetState($di4, $GUI_UNCHECKED)

EndIf

If $di >= 4 Then

$di = $di - 4

GUICtrlSetState($di3, 1)

Else

GUICtrlSetState($di3, $GUI_UNCHECKED)

EndIf

If $di >= 2 Then

$di = $di - 2

GUICtrlSetState($di2, 1)

Else

GUICtrlSetState($di2, $GUI_UNCHECKED)

EndIf

If $di = 1 Then

GUICtrlSetState($di1, 1)

Else

GUICtrlSetState($di1, $GUI_UNCHECKED)

EndIf

EndFunc ;==>ReadDI

Func ReadAI()

$ailevel1 = USBReadAnalogChannel (1)

$ailevel2 = USBReadAnalogChannel (2)

GUICtrlSetData($ai1, $ailevel1)

GUICtrlSetData($ai2, $ailevel2)

EndFunc ;==>ReadAI

Func digiout($state)

Switch $state

Case "random"

USBWriteAllDigital (Random(0, 255))

Case "loop"

USBClearDigitalChannel ($ledloop)

$ledloop = $ledloop + 1

If $ledloop > 8 Then $ledloop = 1

USBSetDigitalChannel ($ledloop)

Case Else

EndSwitch

EndFunc ;==>digiout

;===========================================

; msg handlers

;===========================================

Func FormClose()

Exit

EndFunc ;==>FormClose

Func ao1Change()

USBOutputAnalogChannel (1, GUICtrlRead($ao1))

EndFunc ;==>ao1Change

Func ao2Change()

USBOutputAnalogChannel (2, GUICtrlRead($ao2))

EndFunc ;==>ao2Change

Func do1Click()

If GUICtrlRead($do1) = 1 Then

USBSetDigitalChannel (1)

Else

USBClearDigitalChannel (1)

EndIf

EndFunc ;==>do1Click

Func do2Click()

If GUICtrlRead($do2) = 1 Then

USBSetDigitalChannel (2)

Else

USBClearDigitalChannel (2)

EndIf

EndFunc ;==>do2Click

Func do3Click()

If GUICtrlRead($do3) = 1 Then

USBSetDigitalChannel (3)

Else

USBClearDigitalChannel (3)

EndIf

EndFunc ;==>do3Click

Func do4Click()

If GUICtrlRead($do4) = 1 Then

USBSetDigitalChannel (4)

Else

USBClearDigitalChannel (4)

EndIf

EndFunc ;==>do4Click

Func do5Click()

If GUICtrlRead($do5) = 1 Then

USBSetDigitalChannel (5)

Else

USBClearDigitalChannel (5)

EndIf

EndFunc ;==>do5Click

Func do6Click()

If GUICtrlRead($do6) = 1 Then

USBSetDigitalChannel (6)

Else

USBClearDigitalChannel (6)

EndIf

EndFunc ;==>do6Click

Func do7Click()

If GUICtrlRead($do7) = 1 Then

USBSetDigitalChannel (7)

Else

USBClearDigitalChannel (7)

EndIf

EndFunc ;==>do7Click

Func do8Click()

If GUICtrlRead($do8) = 1 Then

USBSetDigitalChannel (8)

Else

USBClearDigitalChannel (8)

EndIf

EndFunc ;==>do8Click

Where you'll have to include the code earlier in this thread ( k8055.au3 ) in your script if you need it...

Works nicely!

thanks.

Hartger

Link to comment
Share on other sites

  • 1 year later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...