Is that correct from the K8055.DLL from velleman
Posted: Sat Sep 19, 2015 10:35 am
I 'm only a beginner with PureBasic .
I would like to apply the libarary K8055 from Velleman .
I tried to declare all functions with the syntax of PureBasic .
Can someone look at once if everything is correct according to the syntax and semantic.
This my code (trial)
============
I would like to apply the libarary K8055 from Velleman .
I tried to declare all functions with the syntax of PureBasic .
Can someone look at once if everything is correct according to the syntax and semantic.
This my code (trial)
============
Code: Select all
Module k8055_library
'----------------------------------------------------------------------------------
' K8055 VELLEMAN-kit USB EXPERIMENT INTERFACE BOARD
' HEADER INLCUDE FILE FOR K8055D.DLL LIBRARY
' FILE NAME: K8055D.INC
' TRANSLATION BY JULES MARCHILDON, STEPHANE TO POWERBASIC FOR WINDOWS PBWIN9 v9.03
'----------------------------------------------------------------------------------
'=================================================================================='
'General Functions for Open and Close Library '
'=================================================================================='
'Declare FUNCTION OpenDevice LIB "K8055D.DLL" ALIAS "OpenDevice" (BYVAL CardAddress As LONG) As LONG
'Declare SUB CloseDevice LIB "K8055D.DLL" ALIAS "CloseDevice" ()
[b]DeclareDLL OpenDevice.l(cardaddress.l)
DeclareDLL CloseDevice()[/b]
'=================================================================================='
'ADC Functions (Analog / Digital omzettingsprocedures (Analog Input) '
'=================================================================================='
'Declare FUNCTION ReadAnalogChannel LIB "K8055D.DLL" ALIAS "ReadAnalogChannel"(BYVAL Channel As LONG) As LONG
'Declare SUB ReadAllAnalog LIB "K8055D.DLL" ALIAS "ReadAllAnalog" (BYVAL Data1 As LONG, BYVAL Data2 As LONG)
[b]DeclareDLL ReadAnalogChannel.a(channel.a)
DeclareDLL ReadAllAnalog(aData1.a,aData2.a)[/b]
'=================================================================================='
'DAC Functions (Digital / Analog omzettingsprocedures (Analog Output) '
'=================================================================================='
'Declare SUB OutputAnalogChannel LIB "K8055D.DLL" ALIAS "OutputAnalogChannel" (BYVAL Channel As LONG, BYVAL oData As LONG)
'Declare SUB OutputAllAnalog LIB "K8055D.DLL" ALIAS "OutputAllAnalog" (BYVAL Data1 As LONG, BYVAL Data2 As LONG)
'Declare SUB ClearAnalogChannel LIB "K8055D.DLL" ALIAS "ClearAnalogChannel" (BYVAL Channel As LONG)
'Declare SUB ClearAllAnalog LIB "K8055D.DLL" ALIAS "ClearAllAnalog" ()
'Declare SUB setAnalogChannel LIB "K8055D.DLL" ALIAS "SetAnalogChannel" (BYVAL Channel As LONG )
'Declare SUB SetAllAnalog LIB "K8055D.DLL" ALIAS "SetAllAnalog" ()
[b]DeclareDLL OutputAnalogChannel(aChannel.a,aData.a)
DeclareDLL OutputAllAnalog(aData1.a, aData2.a)
DeclareDLL ClearAnalogChannel(aChannel.a)
DeclareDLL ClearAllAnalog()
DeclareDLL setAnalogChannel(aChannel.a)
DeclareDLL SetAllAnalog()
[/b]
'=================================================================================='
'Digital Output Functions (DO) '
'=================================================================================='
'Declare SUB WriteAllDigital LIB "K8055D.DLL" ALIAS "WriteAllDigital" (BYVAL aData As LONG)
'Declare SUB ClearDigitalChannel LIB "K8055D.DLL" ALIAS "ClearDigitalChannel" (BYVAL Channel As LONG)
'Declare SUB ClearAllDigital LIB "K8055D.DLL" ALIAS "ClearAllDigital" ()
'Declare SUB setDigitalChannel LIB "K8055D.DLL" ALIAS "SetDigitalChannel" (BYVAL Channel As LONG)
'Declare SUB SetAllDigital LIB "K8055D.DLL" ALIAS "SetAllDigital" ()
[b]DeclareDLL WriteAllDigital(aData.a)
DeclareDLL ClearDigitalChannel(aChannel.a)
DeclareDLL ClearAllDigital()
DeclareDLL setDigitalChannel(aChannel.a)
DeclareDLL SetAllDigital()
[/b]
'=================================================================================='
'Digital Input Functions (DI) '
'=================================================================================='
'Declare FUNCTION ReadDigitalChannel LIB "K8055D.DLL" ALIAS "ReadDigitalChannel" (BYVAL Channel As LONG) As LONG
'Declare FUNCTION ReadAllDigital LIB "K8055D.DLL" ALIAS "ReadAllDigital" () As LONG
[b]DeclareDLL ReadDigitalChannel.a(aChannel.a)
DeclareDLL ReadAllDigital.a()
[/b]
'=================================================================================='
'Functions for Counters '
'=================================================================================='
'Declare FUNCTION ReadCounter LIB "K8055D.DLL" ALIAS "ReadCounter" (BYVAL CounterNr As LONG) As LONG
'Declare SUB ResetCounter LIB "K8055D.DLL" ALIAS "ResetCounter" (BYVAL CounterNr As LONG)
'Declare SUB SetCounterDebounceTime LIB "K8055D.DLL" ALIAS "SetCounterDebounceTime" (BYVAL CounterNr As LONG, BYVAL DebounceTime As LONG)
[b]DeclareDLL ReadCounter.l(iCounter.l)
DeclareDLL ResetCounter(iCounter.l)
DeclareDLL SetCounterDebounceTime(iCounter.l, iDebounceTime.l)[/b]
[b] Global isConnected.l[/b]
[b]Procedure Init_k8055(card_address.l)
Protected h.l
h = OpenDevice(card_address)
Select h
Case 0, 1, 2, 3
ProcedureReturn(1)
Case -1
ProcedureReturn(0)
EndSelect
EndProcedure[/b]
'SUB Init_K8055(BYVAL card_address As LONG)
' LOCAL h As LONG
'
' h = OpenDevice(card_address)
' Select Case h
' Case 0,1,2,3
' isConnected = 1
' Case -1
' isConnected = 0
' End Select
'End SUB
[b]Procedure processDigitalOutput.l(channel.l, state.s)
If(channel < 0 Or channel > 8)
ProcedureReturn(-1)
Else
Select state
Case "ON"
setDigitalChannel(channel)
ProcedureReturn(1)
Case "OFF"
setDigitalChannel(channel)
ProcedureReturn(0)
EndSelect
EndIf
EndProcedure[/b]
'FUNCTION processDigitalOutput(BYVAL channel As LONG, BYVAL state As STRING) As LONG
' If(channel < 0 Or channel > 8) THEN '[1..8]
' FUNCTION = -1
' Else
' Select Case state
' Case "ON"
' setDigitalChannel(channel)
' FUNCTION = 1
' Case "OFF"
' setDigitalChannel(channel)
' FUNCTION = 0
' End Select
' End If
'End FUNCTION
[b] Procedure processAnalogOutput.l(channel.l, value.a)
If(channel < 0 Or channel > 2)
ProcedureReturn(-1)
Else
OutputAnalogChannel(channel, value)
ProcedureReturn(value)
EndIf
EndProcedure[/b]
'FUNCTION processAnalogOutput(BYVAL channel As LONG, BYREF value As LONG) As LONG
' If(channel < 0 Or channel > 2) THEN '[1..2]
' ' Invalid channel number
' FUNCTION -1
' Else
' ' Valid channel number. Set the channel
' OutputAnalogChannel(channel, value)
' FUNCTION = value
' End If
'End FUNCTION
[b] Procedure readDigitalInput.s(channel.l)
If(channel < 0 Or channel > 5)
ProcedureReturn(-1)
Else
If(ReadAnalogChannel(channel)) = "1"
ProcedureReturn("ON")
Else
ProcedureReturn("OFF")
EndIf
EndIf
EndProcedure[/b]
'FUNCTION readDigitalInput(BYVAL channel As LONG) As STRING
' If(channel < 0 Or channel > 5) THEN '[1..5]
' ' invalid channel number
' FUNCTION = -1
' Else
' ' valid channel number. Read the channel
' FUNCTION = IIF$(ReadDigitalChannel(channel), "ON", "OFF")
' End If
'End FUNCTION
[b]Procedure readAnalogInput.l(channel.l)
If(channel < 0 Or channel > 2)
ProcedureReturn(-1)
Else
ProcedureReturn(ReadAnalogChannel(channel))
EndIf
EndProcedure[/b]
'FUNCTION readAnalogInput(BYVAL channel As LONG) As LONG
' If(channel < 0 Or channel > 2) THEN '[1..2]
' ' invalid channel number
' FUNCTION = -1
' Else
' ' valid channel number. Read the channel
' FUNCTION = ReadAnalogChannel(channel)
' End If
'End FUNCTION
EndModule