Visual Basic Programming Interface

Software

 

 

Visual Basic Programming Interface

The Spectrum boards can be used together with Microsoft Visual Basic as well as with Microsoft Visual Basic for Applications. This allows per example the direct access of the hardware from within Microsoft Excel. The interface between the programming language and the driver is the same for both.

Include Driver

To include the driver functions into Basic it is necessary to first add them to the module definition section of the program file. There the name of the function and the location in the dll is defined:

Module definition:

Public Declare Function SpcInitPCIBoards Lib "SpcStdNT.dll" Alias "_SpcInitPCIBoards@8" (ByRef Count As Integer, ByRef PCIVersion As Integer) As Integer

Public Declare Function SpcInitBoard Lib "SpcStdNT.dll" Alias "_SpcInitBoard@8" (ByVal Nr As Integer, ByVal Typ As Integer) As Integer

Public Declare Function SpcGetParam Lib "SpcStdNT.dll" Alias "_SpcGetParam@12" (ByVal BrdNr As Integer, ByVal RegNr As Long, ByRef Value As Long) As Integer

Public Declare Function SpcSetParam Lib "SpcStdNT.dll" Alias "_SpcSetParam@12" (ByVal BrdNr As Integer, ByVal RegNr As Long, ByVal Value As Long) As Integer

Public Declare Function SpcGetData8 Lib "SpcStdNT.dll" Alias "_SpcGetData@20" (ByVal BrdNr As Integer, ByVal Channel As Integer, ByVal Start As Long, ByVal Length As Long, ByRef data As Byte) As Integer

Public Declare Function SpcSetData8 Lib "SpcStdNT.dll" Alias "_SpcSetData@20" (ByVal BrdNr As Integer, ByVal Channel As Integer, ByVal Start As Long, ByVal Length As Long, ByRef data As Byte) As Integer

Public Declare Function SpcGetData16 Lib "SpcStdNT.dll" Alias "_SpcGetData@20" (ByVal BrdNr As Integer, ByVal Channel As Integer, ByVal Start As Long, ByVal Length As Long, ByRef data As Integer) As Integer

Public Declare Function SpcSetData16 Lib "SpcStdNT.dll" Alias "_SpcSetData@20" (ByVal BrdNr As Integer, ByVal Channel As Integer, ByVal Start As Long, ByVal Length As Long, ByRef data As Integer) As Integer

The module definition is already done for the examples and can be found in the Visual Basic examples directory. Please simply use the file declnt.bas.

Visual Basic Examples

Examples for Visual Basic can be found on CD in the directory /Examples/vb. There is one subdirectory for each board family. You’ll find board specific examples for that family there. The examples are bus type independent. As a result that means that the MI30xx directory con- tains examples for the MI.30xx, the MC.30xx and the MX.30xx families. The example directories contain a running project file for Visual Basic that can be directly loaded.

VBA for Excel Examples

Examples for VBA for Excel can be found on CD in the directory /Examples/excel. The example here simply show the access of the driver and make a very small demo acquisition. It is necessary to combine these examples with the Visual Basic examples to have full board func- tionality.

Driver functions

The driver contains five functions to access the hardware.

Function SpcInitPCIBoard

This function initializes all installed PCI, PXI and CompactPCI boards. The boards are recognized automatically. All installation parameters are read out from the hardware and stored in the driver. The number of PCI boards will be given back in the value Count and the version of the PCI bus itself will be given back in the value PCIVersion.

Function SpcInitPCIBoard:

Function SpcInitPCIBoards (ByRef Count As Integer, ByRef PCIVersion As Integer) As Integer

Function SpcSetParam

All hardware settings are based on software registers that can be set by the function SpcSetParam. This function sets a register to a defined value or executes a command. The board must first be initialized. The available software registers for the driver are listed in the board specific part of the documentation below.

The value „nr“ contains the index of the board that you want to access, the value „reg“ is the register that has to be changed and the value „value“ is the new value that should be set to this software register. The function will return an error value in case of malfunction.

Function SpcSetParam:

Function SpcSetParam (ByVal BrdNr As Integer, ByVal RegNr As Long, ByVal Value As Long) As Integer

34

MC.31xx Manual

Page 34
Image 34
Spectrum Brands MC.31XX manual Visual Basic Programming Interface, Visual Basic Examples, VBA for Excel Examples