![]() |
9323 Hamilton Mentor, Ohio 44060 USA Tel:+1-440-357-1400 Fax:+1-440-357-1416 |
Copyright 1981-2005 Scientific
Solutions Inc
Version 2005.11.28
This document was written to aid in installing and programming of the Scientific Solutions products. Scientific Solutions designs and manufacturers Data Acquisition and Control products. Many of these products can be used with cost effective computers. These products include the popular LabMaster series (LabMaster DMA, LabMaster AD, LabMaster ADEX, LabMaster Pro), LabTender,DADIO and BaseBoard.
This document describes the LabPac32 API (Application Programming Interface). This API consists of a set of functions that can be used in programs written for Windows 95/98 /NT/2000. These functions use the Standard Calling Convention (STD) and can be used by programs written in C, C++, C#, Java, VB, Delphi, Pascal, and many others.
To have a secure operating system, access to hardware is restricted and can only be accessed through Device Drivers. A Device Driver is software that is loaded and becomes part of the operating system. It is also known as a Kernel Mode Device Driver. Each hardware device requires a unique device driver. And each operating system requires a different Device Driver. This means each device must have a device driver for Windows 95 and a different driver for Windows NT and yet another driver for Windows98 and Win2000.
The LabPac32 API supplies a consistent method to access the different hardware between different Windows operating systems. The LabPac32 DLL accesses the hardware by using the Device Driver.
Refer to Software Installation for file location details.
Note: Always remove power from the computer before adding or removing hardware devices.
Computer hardware requires hardware resources such as I/O address space, memory address space, Dma channels and Interrupts. Some of these resources must be unique for each device otherwise a Resource Conflict will be present and the device may not function properly.
For ISA products, many of these resources settings are performed using switches or jumpers on the hardware. For these products, it is best to install the software first and check for Resource Conflicts. Then set the switches on the hardware, power down the computer and install the hardware. Power up the system and the hardware should work well.
For PCI products, the resources are allocated by the computer pci bios. For these products, install the hardware first, then install the software. After rebooting, all should work well.
The following ISA devices require switch or jumper settings. Use the list corresponding to the hardware you are using to select the hardware resource desired. For information on the location of these switches and jumpers, refer to the corresponding hardware manual.
The following is a list of jumpers and switches settings for the LabMaster Dma board that is installed inside the computer system.
The following are the settings
for the external daughter board
The Pro series are PCI devices and do not have any switches or jumpers.
To use the LabPac32 API, the LabPac32 DLL file must be loaded on the system, along with the device driver for the hardware. The drivers for Windows 95/98 have the .VXD extension and drivers for Windows NT/2000 have the .SYS extension. The Windows 95/98 drivers should be located in the System Directory, usually C:\Windows\System. For Windows NT/2000, the drivers should be located in the Drivers Directory, which is usually C:\Windows\System32\Drivers.
The LabPac32 API provides a consistent method to program data acquisition hardware. Each function described in this document will have a function prototype and description.
The LabPac32 API functions are contained in the file LabPac32.dll. Programming languages differ on the method required to access a Dynamic Link Library. For Visual C++, use the Projects \ Settings option and select the Link tab. Set the Category to 'General' and insert "LabPac32.lib"
For C and C++, you will need to include LabPac32.h and RCode.h in your source code. These files contain the function prototypes and return codes for each function.
Every program must call the function LabPac_AddDev before calling any other LabPac function. This function 'opens' the specified hardware device and will return a Device Number. The Device Number is associated with the hardware device and is used by all other calls to access the correct hardware. Before your application terminates, you should release the device by calling LabPac_DelDev
There hardware is initialized when the device driver is opened or when the LabPac_Reset function is called. Use the LabPac_Version function to determine the device driver and dll version that is loaded on the system. Some hardware will have a unique serial number. This number can be determined by calling LabPac_GetSN.
Most functions will return a status code. The LabPac_GetLastError can also be used to determine if any errors have occurred.
Prototype:
SHORT _stdcall LabPac_AddDev (PSTR DeviceName, PULONG DevNum)
This function must be called before calling other LabPac32 functions. It 'opens' the device and returns a unique device number that is associated with the specified hardware. This device number is used by all other LabPac functions to communicate with this hardware.
This function will reset the hardware and driver to the default state.
A pointer to a string containing the name of the device to open.
The device number (passed by reference) using a pointer to the device number variable. It is used by all other LabPac functions.
The table below shows the hardware device description and the associated DeviceName. The last character in the device name is a number. In the table below the default number is zero, however if multiple devices of the same hardware type are being used then the number at the end of the name would be incremented. For example, if two LabMaster Pros were to be used in a program, there would be two calls to the LabPac_AddDev function as shown below.
LabPac_AddDev("LMPro0",
DevNum0);
LabPac_AddDev("LMPro1", DevNum1);
| Device Type | Device Name |
| BaseBoard | Bbd0 |
| Lab Tender | Tender0 |
| DADIO | Dadio0 |
| LabMaster DMA | lmdma0 |
| LabMaster AD | LMAd0 |
| LabMaster Pro | LMPro0 |
| LabMaster DPCI | lmdma0 |
| BaseBoard PCI | pbbd0 |
All hardware supports this function.
Possible Return Codes:
RC_NoErr
RC_DeviceOpenError
If an error is detected, then use the LabPac_GetLastError function to determine what cause the error. The following are the error codes associated with the LabPac_AddDev function.
HKEY_LOCAL_MACHINE\\Software\\Scientific-Solutions
HKEY_LOCAL_MACHINE\\Software\\Scientific-Solutions\\'ProductName'
Where ProductName is the name of the hardware.
Under the key of the 'ProductName' should be a string value name Device
The Device string should be set to the device driver base name, such as lmpro
For Windows95,98,Me- The drivers are typically located in the C:\Windows\System directory
For WindowsNt,2K,Xp- The drivers are typically located in the C:\Windows\System32\Drivers directory
Drivers will not load if there is a hardware resource conflict. Use the Windows Device Manager (Win95,98,Me,2K,XP) or the Administrative diagnostic tools (WinNT) to check conflicts.
If the Microsoft tools do not detect resource conflicts, then check your system BIOS. This BIOS is usually accessed by pressing the 'DEL' key during the system boot. Make sure the resources (interrupt & dma) are set to the proper bus (ISA or PCI) for the associated hardware.
Prototype:
SHORT _stdcall LabPac_DelDev (ULONG DevNum)
This function should be called before the application terminates, to release the hardware device.
All hardware supports this function.
This variable is the device number returned by the function LabPac_AddDev
Possible Return Codes:
RC_NoErr
RC_DeviceCloseError
LabPac_Reset (ULONG DevNum)
Prototype:
SHORT _stdcall LabPac_RESET (ULONG DevNum)
This function will reset the hardware and driver to the default state.
All hardware supports this function.
This variable is the device number returned by the function LabPac_AddDev
Return Codes:
The current version level will be returned.
or RC_BadParameter1
Prototype:
SHORT _stdcall LabPac_Version (ULONG DevNum, PLONG DllVer, PLONG DrvVer)
This function will return the LabPac DLL and Driver version loaded on the system.
All hardware supports this function
This variable is the device number returned by the function LabPac_AddDev
This variable will return the LabPac dll version
This variable will return the hardware device driver version
Possible Return Codes:
RC_NoErr
RC_BadParameter1
Prototype:
SHORT _stdcall LabPac_GetSN (ULONG DevNum, PCHAR SN)
This function will return a Null terminated string containing a 10 character serial number.
All hardware supports this function.
This variable is the device number returned by the function LabPac_AddDev
This string should be at least 11 characters long, 10 character serial number + string termination (NULL)
Possible Return Codes:
RC_NoErr
RC_FunctionNotSupported
Prototype:
SHORT _stdcall LabPac_GetLastError(ULONG DevNum)
This function will return the last error that occurred. After calling this function, the 'Last Error' will be RC_NoErr.
All hardware supports this function.
This variable is the device number returned by the function LabPac_AddDev
Possible Return Codes:
Any Error code is possible
LbPac_HwCheck
(ULONG DevNum, LONG DesktopUnit, PLONG Ver)
Prototype:
SHORT
__stdcall LabPac_HwCheck(ULONG DevNum, LONG DeskTopUnit, PLONG Ver);
This function will return the version of the hardware for the specified Desk Top Unit in the Ver variable. If the Desk Top Unit is not found, the function will return RC_HwNotFound and Ver will be zero.
DeskTopUint(1-4), This
is the Desk Top Unit to query.
Ver, This variable will contain the hardware version number after the
function call.
The BaseBoard PCI and LabMaster DPCI support this function
Possible
Return Codes:
Any Error code is possible
| Module Description | ModuleType (HEX code) |
| DAC1612 | 0x14 |
| DUAL_DAC | 0x18 |
| DAC32XX | 0x1C |
| ADC1614_PGL | 0x20 |
| ADC1614_PGH | 0x24 |
| ADC1614_PGE | 0x28 |
| ADC32XX | 0x2C |
| RELAY_OUTPUT | 0x30 |
| OPTO_OUT | 0x34 |
| OPTO_IN | 0x38 |
| DEFAULT, BUFFERED 8255 | 0xFC |
| PWR, POWER + BUFFERED 8255 | 0x3C |
The Desk Top Unit must be
Version 2 or
greater (see LabPac_HwCheck).
The BaseBoard PCI supports this function.
Any Error code is possible
[GoTo Table of Contents]/* Initialization 'C' Example
Code Segment */
int main (argc, argv)
{
ULONG DevNum;
LONG DllVer, DrvVer;
CHAR DeviceName[9] = "LMPro0";
CHAR SN[11];
LabPac_AddDev (DeviceName,
DevNum); /* This Function Must be called
*/
LabPac_Version(Dev, &DllVer, &DrvVer); /* Determine Dll
and
Driver
Version */
LabPac_Reset (DevNum); /* Reset hardware to default conditions */
LabPac_GetSN(DevNum,SN); /* Get the serial number for the hardware */
return(0);
}
/* Example End */
Digital signals have two states, either logic '0' or logic '1'.
In general, these signals are TTL compatible and have a voltage range from zero to five volts. A logic '0' is defined as any voltage between 0.0 volts and 0.8 volts and a logic '1' would be 2.4 volts to 5.0 volts.
The digital output can be used to control (switch on and off ) other equipment or appliances. Digital inputs can be connected to flow switches, buttons and interlocks. Some equipment can be turned on and off using TTL compatible signals, while some equipment will require a relay. A relay is a device that accepts TTL inputs voltages and can switch on and off higher voltages. Relays are rated by the output voltage they can switch and the amount of current that can handle. Digital outputs can be used to turn on and off items such as lights, pumps, motors.
This section describes many of the terms used in the Digital input and output functions.
Some hardware documentation will refer to Ports A,B and C , these will correspond to Ports 0, 1 and 2. Port references A0, B0, C0, A1, B1, C1, A2, B2, C2, A3, B3, C3 ...., will correspond to ports 0,1,2,3,4,5,6,7,8.9,10,11
Information written or read from a digital port that does not correspond to a digital channel will be ignored. If the hardware only supports 8 digital channels per port, then bits 8-15 will be ignored.
Note: The LabMaster DMA can use hardware buffers for the digital channels. Buffers are used to sink and source more current from external devices and help protect other circuitry. The direction of the digital channels are determined by these buffers. Digital Port 2, bits1 and 5 are not buffered. If inverting buffers are installed on this board, bits 1 and 5 will be non-inverting.
| Hardware Device | Valid Port Numbers |
|---|---|
| BaseBoard | 0 - 11 |
| DADIO | 0-2 |
| Lab Tender | 0-2 |
| LabMaster DMA | 0-2 |
| LabMaster AD/ADEX | 0 |
| LabMaster Pro | 0 |
Digital input can be used to determine if a device or equipment is on or off. The digital input can be connected to flow indicators, inter-locks, buttons, switches or any other digital device.
Scientific Solutions provides many options for connecting the digital inputs and outputs to relay racks and opto isolator. Contact Scientific Solutions if you require any assistance.
Digital Channels are grouped together to form a Digital Port. There are 8 channels per port and the channel numbers correspond to the bit position in the port. That is, Port0 will contain 8 channels, Channel0 - Channel7.
The digital channels are usually accessed by reading or writing a Port, 8 channels at one time. The function LabPac_DoRAW and LabPac_DiRAW are used in this way.
Some hardware has dedicated Digital channels, that is the Digital channels cannot change direction, while some hardware has software configurable digital ports. The functions LabPac_DioSetConfig and LabPac_DioGetConfig can be used to set and check the direction settings for the digital channels. The digital hardware may also have different operating modes. In the default mode, Mode 0, the digital ports can be inputs or outputs, however in other modes the ports can be bidirectional or split half in and half out. Use the function LabPac_DioSetMode to change the digital I/O mode.
Some Digital I/O modes can generate interrupts. You can use a callback function can be used to service these interrupts. Use the LabPac_DiCallback or LabPac_DoCallback function to pass the callback function pointer to the device driver.
Prototype:
SHORT _stdcall LabPac_DioSetMode(ULONG DevNum, UCHAR Port, UCHAR
DioMode)
This function can be used to set mode for the digital I/O. Mode0 is the default mode. Port 0, Port1 can be set to either input or output ports and Port 2 can be split in to two nibbles, High and Low. These two nibbles can be set to be inputs or outputs. The table below describes the settings for Mode0. Inputs are not latched, but Outputs are latched.
| DioMode Value Hex |
Port0 | Port1 | Port2 Lower Nibble |
Port2 High Nibble |
|---|---|---|---|---|
| 80 | Out | Out | Out | Out |
| 81 | Out | Out | In | Out |
| 82 | Out | In | Out | Out |
| 83 | Out | In | In | Out |
| 88 | Out | Out | Out | In |
| 89 | Out | Out | In | In |
| 8A | Out | In | Out | In |
| 8B | Out | In | In | In |
| 90 | In | Out | Out | Out |
| 91 | In | Out | In | Out |
| 92 | In | In | Out | Out |
| 93 | In | In | In | Out |
| 98 | In | Out | Out | In |
| 99 | In | Out | In | In |
| 9A | In | In | Out | In |
| 9B | In | In | In | In |
Mode1 - Strobed I/O
This configuration provides a means for transferring data with strobes
or
'handshaking' signals. In Mode 1, there are two 12 bit communication
channels. These two channels are Port0 (8bits) + 3 bits from Port2 and
Port1(8bits) + 3 bits from Port2. Port0 and Port1 are used for 8bit
data,
while Port2 provides the handshaking lines. Both Inputs and Outputs are
latched
Mode2 - Strobed Bidirectional
The eight lines of Port0 are used to produce a bidirectional bus and
five
lines of Port2 are used for handshaking. Port1 can be programmed for
Mode0 or
Mode1. The remaining bits of Port2 are available for Mode0 input or
output
only if Port1 is in Mode0. The table below describes these mode
settings.
| Set / Reset Mode | Bit7 = 0 |
| Port0 Direction | Bit4 = 1, Input
Bit4 = 0, Output |
| Port2 - High Nibble
Direction |
Bit3 = 1, Input
Bit3 = 0, Output |
| Port1 Mode | Bit2 = 1, Mode1
Bit2 = 0, Mode0 |
| Port1 Direction | Bit1 = 1, Input
Bit1 = 0, Output |
| Port2 - Low Nibble
Direction |
Bit0 = 1, Input
Bit0 = 0, Output |
Hardware Supported: BaseBoard
Possible Return Codes:
RC_NoErr
RC_BadParameter1
RC_BadParameter2
RC_BadParameter3
RC_FunctionNotSupported
Prototype:
SHORT _stdcall LabPac_DioSetConfig (ULONG DevNum, UCHAR Port, UCHAR
PortDir)
This function can be used to set the direction of the digital channels. This function is only valid when the Digital I/O is in Mode 0, the default mode.
Hardware Supported: LabMaster DMA, BaseBoard, Lab Tender, DADIO
Possible Return Codes:
RC_NoErr
RC_BadParameter1
RC_BadParameter2
RC_BadParameter3
RC_FunctionNotSupported
Prototype:
SHORT _stdcall LabPac_DioGetConfig (ULONG DevNum, UCHAR Port, PUCHAR
PortDir
)
This function can be used to determine the direction of the digital channels. This functions only valid when the Digital I/O is in Mode 0, the default mode.
Hardware Supported: LabMaster DMA, BaseBoard, Lab Tender, DADIO
Possible Return Codes:
RC_NoErr
RC_BadParameter1
RC_BadParameter2
RC_BadParameter3
RC_FunctionNotSupported
Prototype:
USHORT _stdcall LabPac_DoRAW (ULONG DevNum, SHORT Port, SHORT Data)
Write to the selected Digital Port. Each bit in the Data corresponds to a digital output channel. That is bit0 corresponds to digital channel0, bit1 corresponds to digital channel1.
Hardware Supported: BaseBoard, Lab Tender, DADIO, All LabMaster products.
Possible Return Codes:
RC_NoErr
RC_BadParameter1
RC_BadParameter2
RC_BadParameter3
RC_FunctionNotSupported
Prototype:
USHORT _stdcall LabPac_DiRAW (ULONG DevNum, SHORT Port)
Read from the selected Digital Port. Each bit in the returned data corresponds to a digital output channel. That is bit0 corresponds to digital channel0, bit1 corresponds to digital channel1.
Hardware Supported: BaseBoard, Lab Tender, DADIO, All LabMaster products.
Possible Return Codes:
RC_NoErr
RC_BadParameter1
RC_BadParameter2
RC_FunctionNotSupported
Prototype:
SHORT _stdcall LabPac_DiCallback ( ULONG DevNum, PHANDLE CallbackEvent)
This function registers the Event with the device driver and associates it with digital input interrupts. When the digital input interrupt requested is received by the device driver, the associated Event will be SET.
This function should be used in conjunction with the LabPac_DioSetMode function.
Hardware Supported: BaseBoard.
Possible Return Codes:
RC_NoErr
RC_BadParameter1
RC_BadParameter2
RC_FunctionNotSupported
Prototype:
SHORT _stdcall LabPac_DiCallback ( ULONG DevNum, PHANDLE CallbackEvent)
This
function will register the Event with the device driver
and
associate it with Digital Output Interrupts. When the device driver
receives a Digital Output interrupt request, the Event will be SET.
This function should be used in conjunction with the LabPac_DioSetMode
function.
Hardware Supported: BaseBoard.
Possible Return Codes:
RC_NoErr
RC_BadParameter1
RC_BadParameter2
RC_FunctionNotSupported
/*
C Example Code Segment */
/* The initialization functions must be call first */
int
main( )
{
UCHAR
PortDir;
USHORT DigData;
/*
Call to the Initialization function LabPac_AddDev */
/* Configure Port 0 to be an input and Port1 to be an output */
LabPac_DioSetConfig (DevNum, 0, 3);
LabPac_DioSetConfig (DevNum, 1, 0);
/* Determine if Port0 channels are input or outputs */
LabPac_DioGetConfig (DevNum, 0, &PortDir);
if (PortDir)
printf("Port0 is configured for Input\n")
else
printf("Port0 is configured for Output\n");
/* Write to Digital Port 0, Turn on digital channels 0 and 5, all other
channels will be zero */
LabPac_DoRAW (DevNum, 0, 0x21);
/*
Read Digital Port 0 ( Digital Channel 0-7) */
DigData = LabPac_DiRAW (DevNum, 0);
return(0);
/* End Example */
The world is full of analog signals. These are continuous waves such as sound, light, temperature, voltage and many others. These signals must be converted to a digital representation to be analyzed using a digital computer. Analog signals must first be converted to a voltage by using a sensor. This voltage is then applied to the Analog Input channel where it can be converted to a digital number.
There are many different kinds of sensors, temperature, flow, accelerometers. Different sensors will have different output voltage ranges. The Analog Input Channel voltage range must not be exceeded. Refer to the hardware manual for details. If the voltage from the sensor is too large, it can be scaled down using a voltage divider.
The resolution of the ADC (Analog to Digital Convert) will determine how close the digital representation matches the original signal. A converter with more bits will have more codes or levels than a converter with fewer bits. In general, more codes result in a better representation of the analog signal. The LabPac driver will default to use the highest resolution available for the hardware.
| ADC Bits | Number of Codes |
| 8 | 256 |
| 12 | 4096 |
| 16 | 65536 |
Refer to the hardware manual for specific converter details.
To produce the best digital representation possible, the analog input signal should span as many codes as possible. If the sensor output voltage is very small, it may need to be amplified before it is applied to the Analog Input Channel. Some data acquisition products have gain control to increase the input signal level. These devices can use the LabPac_AiGain function to set the gain value. When the gain is changed, the Analog Input voltage range also changes. See the hardware documentation for details.
Most sensors are Single Ended and use two wires for their output. One wire has the analog signal and the other is a reference (ground) signal. There are some sensors that have a differential output. Differential outputs will have three wires, two signal wires and one reference (ground) wire. Differential signals are less susceptible to common mode noise. The function LabPac_AiSetMode can be used to change from Single Ended to Differential mode.
The Analog Input at any Channel can be read using the function LabPac_AiRAW, and the Analog Output of any channel can be written using LabPac_AoRAW function. These functions requires the 16 bit data. The MSB of the data will be aligned to the MSB of the hardware converter.
To create waveforms, it is best to use hardware that has an analog output FIFO. This is special memory that holds the data to be sent to the analog output channels. The amount of samples the FIFOs can hold can be determined by calling the LabPac_AoFifoSize function. The FIFO can be loaded with data using LabPac_AoLoadFifo function and the update rate of the DAC can be specified using the LabPac_AoClkSrc function. This clock can be enabled and disabled with software using the LabPac_AoClkEnable function. Once the FIFO has been loaded and the clock enabled, the analog wave will repeat.
Review the hardware documentation to determine the number of analog channels available.
Prototype:
SHORT __stdcall LabPac_AiGain(ULONG DevNum, SHORT Channel, SHORT Gain);
Select the gain for the specified analog input channel.
Hardware Supported: LabMaster Dma, LabMaster AD/ADEX, LabMaster Pro
| Gain Value (decimal) | PGL Gain | PGH Gain |
|---|---|---|
| 0 | 1 | 1 |
| 1 | 10 | 2 |
| 2 | 100 | 4 |
| 3 | 500 | 8 |
| Gain Value (decimal) | PGL Gain | PGH Gain |
|---|---|---|
| 0 | 1 | 1 |
| 1 | 10 | 2 |
| 2 | 100 | 4 |
| 3 | 1000 | 8 |
| Gain Value (decimal) | Gain |
|---|---|
| 0 | 1 |
| 1 | 2 |
| 2 | 4 |
| 3 | 8 |
| Gain Value (decimal) | Gain |
|---|---|
| 0 | 1 |
| 1 | 2 |
| 5 | 4 |
| 2 | 5 |
| 3 | 10 |
| 7 | 20 |
| 10 | 25 |
| 11 | 50 |
| 15 | 100 |
Possible Return Codes:
RC_NoErr
RC_BadParameter1
RC_BadParameter2
RC_BadParameter3
RC_FunctionNotSupported
Prototype:
SHORT __stdcall LabPac_AiMap(ULONG DevNum, UCHAR ucVChan, UCHAR
ucPChan,
UCHAR ucGain);
The LabMaster AD/ADEX and LabMaster Pro can sample the analog input channels in any order and can use different gain factors for each channel. The order of sampling and the gain applied to each channel is stored in a Channel/Gain table. This table's memory is located on the hardware, and allows the hardware to quickly select the proper gain stage for each channel, even during DMA transfers.
The index into the table is called the Virtual Channel. This table has two columns, the Physical Channel and the Gain. The driver initializes this table so that the Physical Channel is equal to the Virtual Channel with unity Gain (Gain=1). During DMA operations, the hardware always starts sampling at the beginning of the table (Virtual Channel 0) and increments sequentially thru the table for number of analog channel specified. After the specified number of channels has been sampled, the hardware starts again at Virtual Channel 0.
The function LabPac_AiGain allows the changing of the gain for each channel, but does change the order of sampling. The LabPac_AiMap function does allows changing the order of sampling and the gain for each channel.
Hardware Supported: LabMaster AD/ADEX, LabMaster Pro
Possible Return Codes:
RC_NoErr
RC_BadParameter1
RC_BadParameter2
RC_BadParameter3
RC_FunctionNotSupported
Prototype:
SHORT __stdcall LabPac_AiSetMode(ULONG DevNum, SHORT mode);
This function is used to select either Single Ended or Differential mode for analog input channels.
Hardware Supported: LabMaster AD/ADEX, LabMaster Pro
Possible Return Codes:
RC_NoErr
RC_BadParameter1
RC_BadParameter2
RC_FunctionNotSupported
Prototype:
SHORT __stdcall LabPac_AiSetNoC(ULONG DevNum, SHORT NoC);
Set the number of analog input channels to scan. This will set the last entry to use in the channel gain array before retuning to the beginning of the table.
NoC:
Number of Channels
Hardware Supported: LabMaster AD/ADEX, LabMaster Pro
Possible Return Codes:
RC_NoErr
RC_BadParameter1
RC_FunctionNotSupported
Prototype:
SHORT __stdcall LabPac_AiBufInit(ULONG DevNum);
Hardware Supported: LabMaster AD/ADEX, LabMaster Pro
Possible Return
Codes:
RC_NoErr
RC_FunctionNotSupported
LabPac_AiGetBuf (ULONG DevNum, PSHORT data, PLONG len)
Prototype:
SHORT __stdcall LabPac_AiGetBuf(ULONG DevNum, PSHORT data, PLONG len);
Hardware Supported: LabMaster AD/ADEX, LabMaster Pro
Possible
Return Codes:
RC_NoErr
RC_FunctionNotSupported
Prototype:
SHORT __stdcall LabPac_AiRAW(ULONG DevNum, SHORT Channel);
This function will return one sample from the specified analog input channel.
The data will be a 2's complement, 16 bit value with the MSB of the data aligned to bit 15.
Hardware Supported: LabTender, LabMaster DMA, LabMaster AD/ADEX, LabMaster Pro
Possible
Return Codes:
RC_NoErr
RC_BadParameter1
RC_BadParameter2
RC_FunctionNotSupported
Prototype:
SHORT __stdcall LabPac_AoRAW(ULONG DevNum, SHORT nChn, SHORT nData);
This function will write one sample to the specified analog output channel.
The data must be a 2's complement, 16 bit value with the MSB of the data aligned to bit 15.
Hardware Supported: LabTender, LabMaster DMA, LabMaster AD/ADEX, LabMaster Pro
Possible Return Codes:
RC_NoErr
RC_BadParameter1
RC_BadParameter2
RC_BadParameter3
RC_FunctionNotSupported
Prototype:
ULONG __stdcall LabPac_AoFifoSize(ULONG DevNum);
This function will return the analog output FIFO size. This is the number of samples the FIFO can hold at one time.
Hardware Supported: LabMaster AD/ADEX, LabMaster Pro
Possible Return Codes:
RC_NoErr
RC_BadParameter1
RC_FunctionNotSupported
Prototype:
SHORT __stdcall LabPac_AoLoadFifo(ULONG DevNum, ULONG Length,PULONG pAoBuf);
This function can be used to load the analog output FIFO with a repeating pattern.
This
function will load the analog output FIFO with the data
in the
buffer
pointed to by the variable AoBuffer. The variable Length is the number
of
samples to be sent to the analog output FIFO. This number should be not
be
greater than the analog output FIFO size.
The size of the analog FIFO can be determined using the
LabPac_AoFifoSize
function.
The
data should be treated as a 32 bit value. The MSB of the
data
aligned
with the MSB of the buffer. The lower 8 bits are reserved to indicate
the
destination. The table below shows the data format. Capital 'D' means
Data
bit and small 'd' are destination bits.
| Bit-> | 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 16 bit Data | D15 | D14 | D13 | D12 | D11 | D10 | D9 | D8 | D7 | D6 | D5 | D4 | D3 | D2 | D1 | D0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | d7 | d6 | d5 | d4 | d3 | d2 | d1 | d0 |
| 12 bit Data | D11 | D10 | D9 | D8 | D7 | D6 | D5 | D4 | D3 | D2 | D1 | D0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | d7 | d6 | d5 | d4 | d3 | d2 | d1 | d0 |
The destination bits are defined below.
| Destination | Bit7 | Bit6 | Bit5 | Bit4 | Bit3 | Bit2 | Bit1 | Bit0 |
| DAC0, Analog Output Channel0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| DAC1, Analog Output Channel1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |
| Digital Exp Output | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 |
Use LabPac_AoClkSrc function to select the output rate. This function will disable the analog output clock before loading the FIFO, so the function LabPac_AoClkEnable will need to be called after this function. This function will enable the analog output FIFO recycle mode and LabPac_AoRAW will disable the FIFO recycle mode.
Hardware Supported: LabMaster AD/ADEX, LabMaster Pro
Possible Return Codes:
RC_NoErr
RC_BadParameter1
RC_BadParameter2
RC_BadParameter3
RC_FunctionNotSupported
Prototype:
SHORT __stdcall LabPac_AoClkSrc(ULONG DevNum, UCHAR ClkSrc,USHORT ClkDiv, UCHAR GateCntl);
This function selects the clock source, gating option and clock divider used to determine the analog output clock rate. The clock rate is the rate at which the DAC is updated with new data.
The Clock source variable (ClkSrc) is used to select one of the five internal clock sources as described in the table below. The analog clock source can be enabled and disabled via software using the LabPac_AoClkEnable function.
The LabPac_AoClkEnable function must be called to enable the analog output clock regardless of the GateCntl option selected. This command cannot be used simultaneously with the LabPac Sweep functions.
| Clock Source Values | Clock Rate |
|---|---|
| 6 | Gate 1 |
| 7 | Gate 2 |
| 8 | Gate 3 |
| 9 | Gate 4 |
| 10 | Gate 5 |
| Clock Source Values | Clock Rate |
|---|---|
| 11 | 4 MHz |
| 12 | 400 KHz |
| 13 | 40 KHz |
| 14 | 4 KHz |
| 15 | 400 Hz |
The clock divider variable ClkDiv is used to scale the clock source. The clock rate for the analog output is equal to the clock source rate divided by the ClkDiv value. If GateCntl is equal to zero, ie no gating, then ClkDiv can have a value from 1 to 16. If gating is used, the ClkDiv variable can be any value from 1 to 65535.
The Gate Control variable, GateCntl is used to select the gating option. This allows the gating, i.e. turning on and off the analog output clock using hardware. Using this option, a logic signal applied to Gate1 connection will gate the analog output clock.
| Gate Control Values | Gating Option |
|---|---|
| 0 | No Gating |
| 4 | Enable Clock when Gate1 is High |
| 5 | Enable Clock when Gate1 is Low |
Hardware Supported: LabMaster AD/ADEX, LabMaster Pro
Possible Return Codes:
RC_NoErr
RC_BadParameter1
RC_BadParameter2
RC_BadParameter3
RC_BadParameter4
RC_FunctionNotSupported
Prototype:
SHORT __stdcall LabPac_AoClkEnable(ULONG DevNum, UCHAR State);
This function can be used to enable and disable the analog output clock.
Hardware Supported: LabMaster AD/ADEX, LabMaster Pro
Possible Return Codes:
RC_NoErr
RC_BadParameter1
RC_BadParameter2
RC_FunctionNotSupported
/*
Analog I/O Example Code Segment Begin */
/* The Initialization functions must be call before these functions. */
/** Read one analog sample **/
/* Select Single Ended Mode for analog input conversions */
LabPac_AiSetMode (DevNum, 0);
/*
For the LabMaster Pro, Set the gain of analog input
channel 3 to
10
*/
LabPac_AiGain (DevNum, 3, 10);
/*
Read the sample from analog input channel 3 */
SHORT Data;
Data = LabPac_AiRAW(DevNum, 3);
/** Write one analog sample **/
/*
Write data 1024 to the analog channel 0 */
LabPac_AoRAW(DevNum, 0, 1024);
/** Create a repeating analog wave **/
/*
Determine the length of the analog output FIFO */
ULONG AoFifoSize;
AoFifoSize = LabPac_AoFifoSize (DevNum);
/*
Create some random data for Ao channel 0*/
LONG AoBuffer[256];
for
(i=0; i<256; i++)
AoBuffer[i] = (rand()*0x7FF)<<4;
/* Loading the Analog output FIFO with data */
LabPac_AoLoadFifo (DevNum, 256, AoBuffer);
/*
The analog output update rate will still be 20 KHz */
/* Create a 20 KHz (4 MHz/200) analog output clock with no gating */
LabPac_AoClkSrc (DevNum, 1,200, 0);
/*
Enable the analog output clock */
LabPac_AoClkEnable (DevNum, 1);
/* Example End */
Event counting is used to count transitions on some input signal. This can be useful for counting the number of times an event occurs or to determine the time intervals between events.
The Event Counter is a 16 bit down counter that can have values from 0 to 65535. The value on the Event counter can be determined by using the LabPac_EventGetCount function.
The
Event Counter input clock source can be one of the five
internal
clocks or an external signal applied to the Source2 connection. This
selection is made using the LabPac_EventClkSrc
function. The Event Clock source can be enabled and disabled using the LabPac_EventClkEnable
function.
Many applications require reading and writing analog and or digital data at regular time intervals. The Event Counter can be used to perform this task. When the Event Counter decrements from 0, It's output will pulse High. The Event Counter Output is on the external OUT2 connector. If the LabPac_EventCallback function is used, an interrupt will occur. The Interrupt Service Routine in the driver will call the Application callback function specified. Windows is not a real-time operating system. The latency associated with callbacks is non-deterministic. Depending on the resources and tasks priorities, It may be necessary to loop on the LabPac_EvebtCallbackStatus function to obtain "real-time" results.
Prototype:
USHORT _stdcall LabPac_EventGetCount (ULONG DevNum, UCHAR Cntr, UCHAR
State)
This function will return the data from the Event Counter. If the State variable is zero, then the counter is cleared after reading it's contents, otherwise the count is not modified.
Hardware Supported: LabMaster DMA, LabMaster AD/ADEX, LabMaster Pro
Return Codes:
The count on the Event Counter.
[GoTo
Table of Contents]
Prototype:
SHORT __stdcall LabPac_EventClkSrc(ULONG DevNum, UCHAR ucCntr, UCHAR ucClkSrc,UCHAR ucClkEdge, UCHAR ucGateCntl,USHORT usLoad);
This function selects the Event Counter input clock source, clock edge, Gate Control and preloaded counter value. The Event Counter is used for counting events generated by the specified clock source. The Event Counter clock source can be one of the five internal clocks or from an external signal applied to the Source2 connection. The table below shows the valid clock source values.
| Clock Source
Values |
Clock Rate |
|---|---|
| 11 | 4 MHz |
| 12 | 400 KHz |
| 13 | 40 KHz |
| 14 | 4 KHz |
| 15 | 400 Hz |
| 2 | External Source2 |
The ClkEdge variable determines which clock edge to use for counting. A value of 0 will cause the counter to count on the rising edge, while a 1 will cause the counter to count on the falling edge.
The Gate Control variable (GateCntl) is used to select the gating option. This allows the gating, i.e. turning on and off, the event clock using hardware. Using this option, a logic signal applied to the Gate2 connection will gate the Event Clock. See the table below for gating option values.
| Gate control Value | No Gating |
|---|---|
| 0 | No Gating |
| 4 | Enable Clock when Gate2 is High |
| 5 | Enable Clock when Gate2 is Low |
The contents of the Period variable are preloaded into the Event Counter. When the Event Counter reaches zero the Period value is again reloaded into the Event Counter. The Period value can be any number from 1 to 65535. In general, for counting events use a load value of zero. The Period variable can be used to scale down the Event Counter Input Source Clock.
Hardware Supported: LabMaster DMA, LabMaster AD/ADEX, LabMaster Pro
Possible Return Codes:
RC_NoErr
RC_BadParameter1
RC_BadParameter2
RC_BadParameter3
RC_BadParameter4
RC_BadParameter5
RC_BadParameter6
RC_FunctionNotSupported
Prototype:
SHORT __stdcall LabPac_EventClkEnable(ULONG DevNum, UCHAR ucCntr, UCHAR ucState);
This function can be used to enable and disable the Event clock.
Hardware Supported:LabMaster DMA, LabMaster AD/ADEX, LabMaster Pro
Possible Return Codes:
RC_NoErr
RC_BadParameter1
RC_BadParameter2
RC_BadParameter3
RC_FunctionNotSupported
Prototype:
SHORT __stdcall LabPac_EventCallback(ULONG DevNum,PHANDLE pCallbackEvent);
This function registers the Event with the device driver and associates it to the corresponding counter. When an Event Counter interrupt occurs, the driver will SET the event.
Windows is not a real-time operating system. The latency associated with callbacks is non-deterministic. Depending on the resources and tasks priorities, It may be necessary to loop on the LabPac_EventCallbackStatus function to obtain "real-time" results.
This function combined with the other Event Counter functions allow the application software to preform any functions necessary at regular time intervals.
Hardware Supported: LabMaster DMA, LabMaster AD/ADEX, LabMaster Pro
Possible Return Codes:
RC_NoErr
RC_BadParameter1
RC_BadParameter2
RC_BadParameter3
RC_FunctionNotSupported
Prototype:
USHORT LabPac_EventCallbackCntl (ULONG DevNum, USHORT Cntl, USHORT
CntlMask);
This
function will determine the
situation that
will cause the driver to call the Event callback function.
The table below shows the bit position corresponding to the event that
can
cause the Event callback function to be called.
A '1' will enable this event to cause the callback function to be called, while a '0' will disable the corresponding event from causing the callback function from being called.
The CntlMask variable is used to mask out the values that are not to be changed. A '1' will allow the corresponding bit to be changed, while a '0' will prevent the corresponding bit from changing.
| Bit | Event Callback Cntl |
| 0 | Counter1 |
| 1 | Counter2 |
| 2 | Counter3 |
| 4 | Counter4 |
All other bits are reserved and should be zero.
Hardware Supported: LabMaster DMA,LabMaster AD/ADEX, LabMaster Pro
Possible Return Codes:
RC_NoErr
RC_BadParameter1
RC_BadParameter2
RC_FunctionNotSupported
Prototype:
SHORT __stdcall LabPac_EventCallbackStatus(ULONG DevNum);
This function will return the bit pattern corresponding to the Event that caused the Event callback function to be called. Refer to the LabPac_EventCallbackCnt function and Event Callback Control table for details of the bit pattern.
Prototype:
SHORT __stdcall LabPac_CtrFout(ULONG DevNum, UCHAR ucCtrGroup, UCHAR ucState);
This
counter function will enable or disable the Fout output
for the
specified counter group.
If ucState is 0 then Fout is disabled, otherwise Fout is enabled.
Hardware Supported: LabMaster Pro LabMaster AD/ADEX, LabMaster Dma, LabTender
Possible Return Codes:
RC_NoErr
RC_FunctionNotSupported
Prototype:
SHORT __stdcall LabPac_CtrArm(ULONG DevNum, UCHAR ucCtrGroup, UCHAR ucCtr);
This
counter function will arm the specified counter.
Hardware Supported: LabMaster Pro LabMaster AD/ADEX, LabMaster Dma, LabTender
Possible Return Codes:
RC_NoErr
RC_FunctionNotSupported
Prototype:
SHORT __stdcall LabPac_CtrArmM(ULONG DevNum, UCHAR ucCtrGroup, UCHAR ucCtrs);
This
counter function will arm the specified counters.
Hardware Supported: LabMaster Pro LabMaster AD/ADEX, LabMaster Dma, LabTender
Possible Return Codes:
RC_NoErr
RC_FunctionNotSupported
Prototype:
SHORT __stdcall LabPac_CtrLoad(ULONG DevNum, UCHAR ucCtrGroup, UCHAR ucCtr);
This
counter function will load the specified counter with
the value
in
the counter's Load register.
Hardware Supported: LabMaster Pro LabMaster AD/ADEX, LabMaster Dma, LabTender
Possible Return Codes:
RC_NoErr
RC_FunctionNotSupported
Prototype:
SHORT __stdcall LabPac_CtrLoadM(ULONG DevNum, UCHAR ucCtrGroup, UCHAR ucCtrs);
This
counter function will load the specified counters with
the
value in
the corresponding Load register.
Hardware Supported: LabMaster Pro LabMaster AD/ADEX, LabMaster Dma, LabTender
Possible Return Codes:
RC_NoErr
RC_FunctionNotSupported
Prototype:
SHORT __stdcall LabPac_CtrSave(ULONG DevNum, UCHAR ucCtrGroup, UCHAR ucCtr);
This
counter function will save the contents of the
specified
counter in
the counters Hold register.
Hardware Supported: LabMaster Pro LabMaster AD/ADEX, LabMaster Dma, LabTender
Possible Return Codes:
RC_NoErr
RC_FunctionNotSupported
Prototype:
SHORT __stdcall LabPac_CtrSaveM(ULONG DevNum, UCHAR ucCtrGroup, UCHAR ucCtrs);
This
counter function will save the contents of the
specified
counters in
the corresponding counter Hold register.