You are on page 1of 7

Programming the Velleman K8055

USB Interface Card


in
Liberty Basic Gold

Notice: The software described in this document


is sample code only and not guaranteed for all
purposes. Use at your own risk!

David Deane
'Test Program for Velleman K8055 USB Interface Card by David Deane, Vidalia, GA. Jan 2, 2010
'Free for Educational Use
'The VB6 sample code works fine, but I was never able to get the program to work with
'Visual Basic Express 2008
'This code works in Liberty Basic, but you will need to the Gold edition to create executable files.
' I have tried to use most of the DLL calls available to test for channel and returned values.
'The card must have both address jumpers installed to be Connected as Addr(0)
'Tested with the K8055 card Jan 2, 2002
'Rev2 uses checkboxes and textboxes to output data and continuous input checking

[setup.main.Window]

'-----Begin code for #main

WindowWidth = 550
WindowHeight = 410
UpperLeftX=int((DisplayWidth-WindowWidth)/2)
UpperLeftY=int((DisplayHeight-WindowHeight)/2)

'-----Begin GUI objects code

statictext #main.statictext1, "Digital Input/Button Status", 25, 17, 250, 20


TextboxColor$ = "white"
textbox #main.textbox3, 25, 62, 25, 25
textbox #main.textbox4, 60, 62, 25, 25
textbox #main.textbox5, 95, 62, 25, 25
textbox #main.textbox6, 130, 62, 25, 25
textbox #main.textbox7, 165, 62, 25, 25
statictext #main.statictext8, "1 2 3 4 5", 35, 37, 250, 20
statictext #main.statictext9, "Analog Inputs 0 - 255", 35, 107, 134, 20
statictext #main.statictext10, "Ch 1", 55, 127, 28, 20
statictext #main.statictext11, "Ch2", 120, 127, 23, 20
textbox #main.textbox12, 40, 147, 50, 25
textbox #main.textbox13, 105, 147, 55, 25
statictext #main.statictext14, "Analog Outputs", 55, 187, 120, 20
textbox #main.textbox15, 40, 227, 55, 25
textbox #main.textbox16, 105, 227, 55, 25
statictext #main.statictext16, "Ch 1", 55, 207, 28, 20
statictext #main.statictext17, "Ch2", 115, 207, 23, 20
statictext #main.statictext19, "Digital Outputs", 55, 277, 100, 20
checkbox #main.checkbox21, " ", [checkbox21Set], [checkbox21Reset], 35, 297, 20, 25
checkbox #main.checkbox22, " ", [checkbox22Set], [checkbox22Reset], 60, 297, 20, 25
checkbox #main.checkbox23, " ", [checkbox23Set], [checkbox23Reset], 85, 297, 20, 25
checkbox #main.checkbox24, " ", [checkbox24Set], [checkbox24Reset], 110, 297, 20, 25
checkbox #main.checkbox25, " ", [checkbox25Set], [checkbox25Reset], 135, 297, 20, 25
checkbox #main.checkbox26, " ", [checkbox26Set], [checkbox26Reset], 160, 297, 20, 25
checkbox #main.checkbox27, " ", [checkbox27Set], [checkbox27Reset], 185, 297, 20, 25
checkbox #main.checkbox28, " ", [checkbox28Set], [checkbox28Reset], 210, 297, 20, 25
button #main.button29,"Run Again",[button29Click], UL, 255, 57, 105, 25
button #main.button30,"Close",[button30Click], UL, 255, 87, 105, 25
statictext #main.statictext31, "Opening Device", 255, 27, 105, 25

'-----End GUI objects code

open "untitled" for window as #main


print #main, "font arial 10 bold"
print #main.textbox3, "!font arial 10"
print #main.textbox4, "!font arial 10"
print #main.textbox5, "!font arial 10"
print #main.textbox6, "!font arial 10"
print #main.textbox7, "!font arial 10"
print #main.statictext8, "!font arial 10"
print #main.statictext10, "!font arial 10"
print #main.statictext11, "!font arial 10"
print #main.textbox12, "!font arial 10"
print #main.textbox13, "!font arial 10"
print #main.statictext16, "!font arial 10"
print #main.statictext17, "!font arial 10"
print #main.statictext31, "!font arial 10 bold"

nomainwin
Open "k8055d.dll" for DLL as #user
channel=1
CardAddress=0
Calldll #user, "OpenDevice", CardAddress as Long, retrn as long

If retrn=-1 then
print "Board 0 Not Located"
print "Program Terminated"
close #user
end
Else
print "retrn=";retrn;" ";"Board 0 Connected"
End If

[Rerun]
print #main.statictext31,"Testing"

For blink=1 to 3
Calldll #user, "SetAllDigital", channel as Long
Call Pause 100
Calldll #user, "ClearAllDigital", channel as Long
Call Pause 100
Next blink

For DCount=1 to 8
CallDll #user, "SetDigitalChannel", DCount as long, retDigiSet as long
If DCount=1 then print #main.checkbox21, "set"
If DCount=2 then print #main.checkbox22, "set"
If DCount=3 then print #main.checkbox23, "set"
If DCount=4 then print #main.checkbox24, "set"
If DCount=5 then print #main.checkbox25, "set"
If DCount=6 then print #main.checkbox26, "set"
If DCount=7 then print #main.checkbox27, "set"
If DCount=8 then print #main.checkbox28, "set"
Call Pause 100
Next DCount
For DCount=8 to 0 step -1
CallDll #user, "ClearDigitalChannel", DCount as long, retDigiSet as long
If DCount=8 then print #main.checkbox28, "reset"
If DCount=7 then print #main.checkbox27, "reset"
If DCount=6 then print #main.checkbox26, "reset"
If DCount=5 then print #main.checkbox25, "reset"
If DCount=4 then print #main.checkbox24, "reset"
If DCount=3 then print #main.checkbox23, "reset"
If DCount=2 then print #main.checkbox22, "reset"
If DCount=1 then print #main.checkbox21, "reset"
Call Pause 100
Next DCount

Print "Digital Channels 1 thru 5 = ";


CallDll #user, "ReadDigitalChannel", 1 as long, retrnedval1 as long
print #main.textbox3,retrnedval1
CallDll #user, "ReadDigitalChannel", 2 as long, retrnedval2 as long
print #main.textbox4,retrnedval2
CallDll #user, "ReadDigitalChannel", 3 as long, retrnedval3 as long
print #main.textbox5,retrnedval3
CallDll #user, "ReadDigitalChannel", 4 as long, retrnedval4 as long
print #main.textbox6,retrnedval4
CallDll #user, "ReadDigitalChannel", 5 as long, retrnedval5 as long
print #main.textbox7,retrnedval5

Playwave "Beep.wav"

Print "Analog Channels 1 and 2 (Value 0-255) = ";


CallDll #user, "ReadAnalogChannel", 1 as long, retrnedAVal1 as long
print #main.textbox12,retrnedAVal1
CallDll #user, "ReadAnalogChannel", 2 as long, retrnedAVal2 as long
print #main.textbox13,retrnedAVal2
Playwave "Beep.wav"

CallDll #user, "SetAllAnalog", 2 as long, retAna as long


Call Pause 100
CallDll #user, "ClearAllAnalog", 2 as long, retAna as long
Call Pause 100
CallDll #user, "SetAnalogChannel", 1 as long, retAna as long
Call Pause 100
CallDll #user, "ClearAnalogChannel", 1 as long, retAna as long
Call Pause 100
CallDll #user, "SetAnalogChannel", 2 as long, retAna as long
Call Pause 100
CallDll #user, "ClearAnalogChannel", 2 as long, retAna as long
Call Pause 100

For A1D=0 to 255 step 5


CallDll #user, "OutputAnalogChannel", 1 as long, A1D as long, retAna as long
print #main.textbox15,A1D
Next A1D
For A1D=255 to 0 step -5
CallDll #user, "OutputAnalogChannel", 1 as long, A1D as long, retAna as long
' print ".";
print #main.textbox15,A1D
Next A1D
' print "."

For A2D=0 to 255 step 5


CallDll #user, "OutputAnalogChannel", 2 as long, A2D as long, retAna as long
' print ".";
print #main.textbox16,A2D
Next A2D
For A2D=255 to 0 step -5
CallDll #user, "OutputAnalogChannel", 2 as long, A2D as long, retAna as long
' print ".";
print #main.textbox16,A2D
Next A2D
print "."

print #main.statictext31,"Test Complete"

[ReadDigs]
Print "Digital Channels 1 thru 5 = ";
CallDll #user, "ReadDigitalChannel", 1 as long, retrnedval1 as long
print #main.textbox3,retrnedval1
CallDll #user, "ReadDigitalChannel", 2 as long, retrnedval2 as long
print #main.textbox4,retrnedval2
CallDll #user, "ReadDigitalChannel", 3 as long, retrnedval3 as long
print #main.textbox5,retrnedval3
CallDll #user, "ReadDigitalChannel", 4 as long, retrnedval4 as long
print #main.textbox6,retrnedval4
CallDll #user, "ReadDigitalChannel", 5 as long, retrnedval5 as long
print #main.textbox7,retrnedval5
[ReadAnalogs]
Print "Analog Channels 1 and 2 (Value 0-255) = ";
CallDll #user, "ReadAnalogChannel", 1 as long, retrnedAVal1 as long
print #main.textbox12,retrnedAVal1
CallDll #user, "ReadAnalogChannel", 2 as long, retrnedAVal2 as long
print #main.textbox13,retrnedAVal2

[SetAnalogs]
print #main.textbox15, "!contents? SetAna1$"
ADataOut1=VAL(SetAna1$)
CallDll #user, "OutputAnalogChannel", 1 as long, ADataOut1 as long, retAna as long

print #main.textbox16, "!contents? SetAna2$"


ADataOut2=VAL(SetAna2$)
CallDll #user, "OutputAnalogChannel", 2 as long, ADataOut2 as long, retAna as long

scan
goto [ReadDigs]

[loop]
wait

[button29Click]
goto [Rerun]

[button30Click]
Close #user
Close #main
End

[checkbox21Set]
CallDll #user, "SetDigitalChannel", 1 as long, retDigiSet as long
goto [ReadDigs]
[checkbox22Set]
CallDll #user, "SetDigitalChannel", 2 as long, retDigiSet as long
goto [ReadDigs]
[checkbox23Set]
CallDll #user, "SetDigitalChannel", 3 as long, retDigiSet as long
goto [ReadDigs]
[checkbox24Set]
CallDll #user, "SetDigitalChannel", 4 as long, retDigiSet as long
goto [ReadDigs]
[checkbox25Set]
CallDll #user, "SetDigitalChannel", 5 as long, retDigiSet as long
goto [ReadDigs]
[checkbox26Set]
CallDll #user, "SetDigitalChannel", 6 as long, retDigiSet as long
goto [ReadDigs]
[checkbox27Set]
CallDll #user, "SetDigitalChannel", 7 as long, retDigiSet as long
goto [ReadDigs]
[checkbox28Set]
CallDll #user, "SetDigitalChannel", 8 as long, retDigiSet as long
goto [ReadDigs]

[checkbox21Reset]
CallDll #user, "ClearDigitalChannel", 1 as long, retDigiSet as long
goto [ReadDigs]
[checkbox22Reset]
CallDll #user, "ClearDigitalChannel", 2 as long, retDigiSet as long
goto [ReadDigs]
[checkbox23Reset]
CallDll #user, "ClearDigitalChannel", 3 as long, retDigiSet as long
goto [ReadDigs]
[checkbox24Reset]
CallDll #user, "ClearDigitalChannel", 4 as long, retDigiSet as long
goto [ReadDigs]
[checkbox25Reset]
CallDll #user, "ClearDigitalChannel", 5 as long, retDigiSet as long
goto [ReadDigs]
[checkbox26Reset]
CallDll #user, "ClearDigitalChannel", 6 as long, retDigiSet as long
goto [ReadDigs]
[checkbox27Reset]
CallDll #user, "ClearDigitalChannel", 7 as long, retDigiSet as long
goto [ReadDigs]
[checkbox28Reset]
CallDll #user, "ClearDigitalChannel", 8 as long, retDigiSet as long
goto [ReadDigs]

End

sub Pause mil


t=time$("milliseconds")
while time$("milliseconds")<t+mil
wend
end sub

You might also like