Visual Basic VB6

I managed to get many calls to the Opal Kelly DLL implemented in VB6. This was difficult mostly for the pipe read, since this required pointers, and VB is not really pointer friendly…
Since my application is rather large, here are just the relevant parts that I used:

Declarations:
Declare Function okPLL22150_Construct Lib “okFrontPanel” () As Long
Declare Sub okPLL22150_Destruct Lib “okFrontPanel” (ByVal pll As Long)
Declare Function okPLL22150_SetVCOParameters Lib “okFrontPanel” _
(ByVal pll As Long, ByVal p As Integer, ByVal q As Integer) As Boolean
Declare Sub okPLL22150_SetOutputSource Lib “okFrontPanel” _
(ByVal pll As Long, ByVal output As Integer, ByVal clksrc As Long)
Declare Sub okPLL22150_SetOutputEnable Lib “okFrontPanel” _
(ByVal pll As Long, ByVal output As Integer, ByVal enable As Boolean)
Declare Sub okPLL22150_SetDiv1 Lib “okFrontPanel” _
(ByVal pll As Long, ByVal divsrc As Long, ByVal n As Integer)

Declare Function LoadLibrary Lib “kernel32” Alias “LoadLibraryA” (ByVal
lpLibFileName As String) As Long
Declare Function FreeLibrary Lib “kernel32” (ByVal hLibModule As Long)
As Long
Declare Function okUsbFrontPanel_Construct Lib “okFrontPanel” () As Long
Declare Function okUsbFrontPanel_OpenBySerial Lib “okFrontPanel” (ByVal xem As Long, ByVal serial As String) As Long
Declare Sub okUsbFrontPanel_Destruct Lib “okFrontPanel” (ByVal xem As Long)
Declare Function okUsbFrontPanel_IsFrontPanelEnabled Lib “okFrontPanel”
(ByVal xem As Long) As Boolean
Declare Function okUsbFrontPanel_IsFrontPanel3Supported Lib
“okFrontPanel” (ByVal xem As Long) As Boolean
Declare Function okUsbFrontPanel_IsHighSpeed Lib “okFrontPanel” (ByVal
xem As Long) As Boolean
Declare Function okUsbFrontPanel_GetBoardModel Lib “okFrontPanel”
(ByVal xem As Long) As Long
Declare Function okUsbFrontPanel_ConfigureFPGA Lib “okFrontPanel”
(ByVal xem As Long, ByVal name As String) As Long
Declare Function okUsbFrontPanel_SetPLL22150Configuration Lib
“okFrontPanel” (ByVal xem As Long, ByVal pll As Long) As Long
Declare Function okUsbFrontPanel_ResetFPGA Lib “okFrontPanel” (ByVal
xem As Long) As Long
Declare Sub okUsbFrontPanel_UpdateWireIns Lib “okFrontPanel” (ByVal xem
As Long)
Declare Sub okUsbFrontPanel_UpdateWireOuts Lib “okFrontPanel” (ByVal
xem As Long)
Declare Function okUsbFrontPanel_SetWireInValue Lib “okFrontPanel”
(ByVal xem As Long, ByVal ep As Integer, ByVal myval As Integer, ByVal
mask As Integer) As Long
Declare Function okUsbFrontPanel_GetWireOutValue Lib “okFrontPanel”
(ByVal xem As Long, ByVal ep As Integer) As Integer
Declare Function okUsbFrontPanel_ActivateTriggerIn Lib “okFrontPanel”
(ByVal xem As Long, ByVal ep As Integer, ByVal bit As Integer) As Long
Declare Function okUsbFrontPanel_ReadFromBlockPipeOut Lib “okFrontPanel” _
(ByVal xem As Long, ByVal ep As Integer, ByVal blockSize As Integer,
ByVal length As Long, ByRef DATA_ARRAY As Any) As Long

Usage:
Connect to XEM
hOK = LoadLibrary(“c:\windows\system32\okFrontPanel.dll”)
If hOK <> 0 Then
xem = okUsbFrontPanel_Construct ‘# Get a handle to the XEM:
err = okUsbFrontPanel_OpenBySerial(xem, “”)’ hope only one is
connected, otherwise hardcode serial#
pll = okPLL22150_Construct '# Get a handle to the PLL:
If err < 0 Then
MsgBox “Couldn’t open Front Panel Err:” + str(err), vbOKOnly
End If
Call FreeLibrary(hOK)
Else
MsgBox “Problem loading okFrontPanel.dll”, vbOKOnly
End If

Configuring PLL and FPGA

Dim okConfig As Boolean
Dim brd As Long
Dim err As Long

okConfig = okPLL22150_SetVCOParameters(pll, 400, 48)
Call okPLL22150_SetDiv1(pll, 1, 16) ’ source VCO, divide by 16
Call okPLL22150_SetOutputSource(pll, 0, 1) ’ output = 0, source = div1byN
Call okPLL22150_SetOutputEnable(pll, 0, True)

brd = okUsbFrontPanel_GetBoardModel(xem) 'just checking that
I have the right board
If brd = 2 Then 'XEM3001v2
okConfig = okUsbFrontPanel_IsFrontPanelEnabled(xem) 'Interface is
working
okConfig = okUsbFrontPanel_IsHighSpeed(xem) 'USB is working
properly
okConfig = okUsbFrontPanel_IsFrontPanel3Supported(xem) ’ I have
buffered pipes
err = okUsbFrontPanel_ConfigureFPGA(xem, “C:\Main.bit”)
If err < 0 Then
MsgBox “Couldn’t configure FPGA Err:” + str(err), vbOKOnly
End If
Else
MsgBox “Wrong board type:” + str(brd), vbOKOnly
End If

Wires and triggers:
Dim err As Long
err = okUsbFrontPanel_SetWireInValue(xem, &H4, i, &HFFFF)
okUsbFrontPanel_UpdateWireIns (xem)
err = err + okUsbFrontPanel_ActivateTriggerIn(xem, &H40, &H1)
okUsbFrontPanel_UpdateWireOuts (xem)

Pipe:
ReDim rawdata(0 To dlen) As Byte 'make sure buffer size is sufficient

   err =  okUsbFrontPanel_ActivateTriggerIn(xem, &H40, 1)
   err = err + okUsbFrontPanel_ReadFromBlockPipeOut(xem, &HA0, 128,

dlen, ByVal VarPtr(rawdata(0)))