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.
Hardware Supported: LabMaster Pro LabMaster AD/ADEX, LabMaster Dma, LabTender
Possible Return Codes:
RC_NoErr
RC_FunctionNotSupported
Prototype:
SHORT __stdcall LabPac_CtrDisarm(ULONG DevNum, UCHAR ucCtrGroup, UCHAR ucCtr);
This
counter function will disarm the specified counter.
Hardware Supported: LabMaster Pro LabMaster AD/ADEX, LabMaster Dma, LabTender
Possible Return Codes:
RC_NoErr
RC_FunctionNotSupported
Prototype:
SHORT __stdcall LabPac_CtrDisarmM(ULONG DevNum, UCHAR ucCtrGroup, UCHAR ucCtrs);
This
counter function will disarm the specified counters.
Hardware Supported: LabMaster Pro LabMaster AD/ADEX, LabMaster Dma, LabTender
Possible Return Codes:
RC_NoErr
RC_FunctionNotSupported
Prototype:
SHORT __stdcall LabPac_CtrStep(ULONG DevNum, UCHAR ucCtrGroup, UCHAR ucCtr);
This
counter function will step the specified counter by one
count.
Hardware Supported: LabMaster Pro LabMaster AD/ADEX, LabMaster Dma, LabTender
Possible Return Codes:
RC_NoErr
RC_FunctionNotSupported
Prototype:
SHORT __stdcall LabPac_CtrSet(ULONG DevNum, UCHAR ucCtrGroup, UCHAR ucCtr);
This
counter function will set the specified counter output
high.
The counter mode register must be set for TC toggle mode.
Hardware Supported: LabMaster Pro LabMaster AD/ADEX, LabMaster Dma, LabTender
Possible Return Codes:
RC_NoErr
RC_FunctionNotSupported
Prototype:
SHORT __stdcall LabPac_CtrClr(ULONG DevNum, UCHAR ucCtrGroup, UCHAR ucCtr);
This
counter function will clear the specified counter
output to a
low
state.
The counter mode register must be set for TC toggle mode.
Hardware Supported: LabMaster Pro LabMaster AD/ADEX, LabMaster Dma, LabTender
Possible Return Codes:
RC_NoErr
RC_FunctionNotSupported
Prototype:
SHORT __stdcall LabPac_CtrState(ULONG DevNum, UCHAR ucCtrGroup, PUCHAR ucState);
This
counter function will return the state of the five
counter
outputs in
the State variable.
Bits 1-5 correspond to counter 1-5. A bit value of one indicates the
output
is high, and a value of zero indicates the corresponding counter output
is
low.
Hardware Supported: LabMaster Pro LabMaster AD/ADEX, LabMaster Dma, LabTender
Possible Return Codes:
RC_NoErr
RC_FunctionNotSupported
Prototype:
SHORT __stdcall LabPac_CtrConfig(ULONG DevNum, UCHAR ucCtrGroup, UCHAR ucCtr,USHORT usMode, USHORT usLoad, USHORT usHold);
This
counter function will set the specified counter mode,
load and
hold
register.
Hardware Supported: LabMaster Pro LabMaster AD/ADEX, LabMaster Dma, LabTender
Possible Return Codes:
RC_NoErr
RC_FunctionNotSupported
Prototype:
SHORT __stdcall LabPac_CtrHoldRd(ULONG DevNum, UCHAR ucCtrGroup, UCHAR ucCtr,PUSHORT usData);
This
counter function will read the contents of the Hold
register
for the
specified counter.
Hardware Supported: LabMaster Pro LabMaster AD/ADEX, LabMaster Dma, LabTender
Possible Return Codes:
RC_NoErr
RC_FunctionNotSupported
Prototype:
SHORT __stdcall LabPac_ExtIrq_Callback(ULONG DevNum, LONG ExtIrqNum, PHANDLE Event);
This
function will
register the Event with the device driver and
associate it with the specified Externel Interrupt line.
When an External Interrupt Request is received by the device driver,
that interrupt is disabled and the associated Event will be SET.
Interrupts can be Enabled or Disabled using the LabPac_ExtIrq_Enable
function.
The
External
Interrupts are Low Level sensitive, that is bringing
this line low will cause an interrupt
when the interrupt has been enabled.
Hardware
Supported:
LabMaster Pro
Possible
Return Codes:
RC_NoErr
Prototype:
SHORT __stdcall LabPac_ExtIrq_Enable(ULONG DevNum, LONG ExtIrqNum, LONG state);
This function is used to Enable or Disable External Interrupts.
The
External Interrupts are
Low
Level
sensitive,
that is bringing
this line low will cause an interrupt when the interrupt has been
enabled.
When an External Interrupt Request is received by the device driver,
that interrupt is disabled and the associated Event will be
SET.
An Event is associated with the ExtIrq line by using the
LabPac_ExtIrq_Callback function.
If the ExtIrq line is high
when calling this function, then the interrupts will be enabled and the
function will return zero. If
the ExtIrq line is low when calling this function, then interrupts will
not be enabled and the function
will return RC_Timeout.
Hardware
Supported:
LabMaster Pro
Possible
Return Codes:
RC_NoErr
RC_Timeout
/*
Event Example Code
Segment Begin
*/
/* The Initialization functions must be call before these functions. */
/**
Count pulsed on External
Source2
connector **/
/* No Gating */
UCHAR ClkSrc = 7;
UCHAR ClkEdge = 0;
UCHAR GateCntl = 0;
USHORT Load = 0;
LabPac_EventClkSrc (DevNum, 2, ClkSrc, ClkEdge, GateCntl, Load);
/*
Enable the Event Clock */
LabPac_EventClkEnable (DevNum, 1);
/*
Wait some time */
Sleep (10);
/*
Retrieve the Event
Counter's
contents */
ULONG count;
count = LabPac_EventGetCount (DevNum, 1);
printf ("Count = %d \n", 65535 - count);
/*
Enable the Event Clock */
LabPac_EventClkEnable (DevNum, 0);
/**
Create a
callback
function that will
be
called every 5ms **/
/* Create a handle to the application callback function and pass it to
the
driver*/
/*
The
Callback
Function
*/
DWORD WINAPI MyCallbackFunction (LPVIOD Dummy)
{
while (1)
{
if (WaitForSingleObjectEx (MyCallbackEvent, 1000, FALSE)
printf(" The Event Counter caused an Interrupts\n");
Sleep (10);
}
return (0);
}
main
( )
{
ULONG
DevNum;
ULONG results;
UCHAR ClkSrc = 3;
UCHAR ClkEdge = 0;
UCHAR GateCntl = 0;
UCHAR Load = 200;
CHAR DeviceName = "LMPro0";
/*
Refer to windows
programming
documentation for
details */
MyCallbackEvent = CreateEvent (NULL, FALSE, FALSE, NULL);
MyCallbackEventThread = CreateThread (NULL, 0, MyCallbackFunction,
NULL,
0,&results);
/*
LabPac Functions */
LabPac_AddDev (DeviceName, & DevNum);
LabPac_EventClkSrc (DevNum, 2, ClkSrc, ClkEdge, GateCntl, Load);
LabPac_EventCallback (DevNum, MycallbackEvent);
LabPac_EventClkEnable (DevNum, 1);
while ( !kbhit () )
{
Sleep(5);
}
CloseHandle ( MyCallbackEvent);
TerminateThread (MyCallbackEventThread, 0);
CloseHandle ( MyCallbackEventThread);
}
When the sampling rate is great, the Event Counter Callback method may not be quick enough and data may be lost. For this situation, the application program should use DMA or Bus Master Transfers DMA.
Using DMA (Direct Memory Access) the data acquisition hardware will transfer the data to the system memory without using the system's CPU. ISA boards that use DMA transfers require a system DMA Controller (DMAC) and a DMA channel. These limited resources are reserved for the hardware when the hardware is installed in the computer system. ISA DMA transfers can be 8 or 16 bit depending on the hardware.
Bus Master PCI boards have the hardware necessary to perform the DMA functions without using the system DMAC, so there are never any dma resource conflicts. The Scientific Solutions PCI hardware perform 32 bit transfers.
For acquiring analog samples, set the sample rate using the LabPac_AiSampleRate function. This function will use the internal clocks to best match the sampling rate. The actual sampling period will be returned.
NOTE:
Windows is not a real-time operating system. The latency associated
with
callbacks is non-deterministic. Depending on the resources and tasks
priorities data can be lost. The Callback functions are supported by
the
device drivers, however we recommend new programs use the AiBM_PingPong
function for high speed analog conversions.
The LabPac_AiBM_PingPong will transfer the analog input data directly in to the specified buffer. The driver will 'ping pong' the data between the first and second half of the application buffer. When the buffer is half full, the driver will set the Half Full bit in the AiCallbackStatus and continue filling the application buffer. When the buffer is full, the half full bit is again set, the driver then starts fill the application buffer at the beginning.
The application program should use the LabPac_AiCallbackStatus function to monitor the half full bit. When the half full bit is detected, the application can then call LabPac_AiBm_PPIdx function to determine which half of the buffer is available for reading.
For analog output transfers, the sample rate is set using the Event Counter. Data is sent to the analog output FIFOs. When the Fifo is half full, and interrupt will occur, causing the driver to call the analog output callback function specified in the LabPac_AoCallback function.
Prototype:
ULONG LabPac_AiSampleRate (ULONG ulDevNum, USHORT usChannels, ULONG ulHz, UCHAR ucGateCntl);
Select the number of analog input channels, the sample rate and the gate control for analog input conversions. This function will use the onboard clocks to best match the sampling rate specified. The actual sampling rate can be determined using the LabPac_GetSampleRate function.
The Gate control can be used to gate analog input sampling with a signal applied to the external connection Gate4. Note, some hardware will have Gate3 connected to gate 4.
The analog input clock source can be enabled and disabled via software
using
the LabPac_AiClkEnable
function.The
LabPac_AiClkEnable function must be called to enable the analog input
clock
regardless of the GateCntl option selected.
Gate Control Value | No Gating |
---|---|
0 | No Gating |
4 | Enable Clock when Out3/Gate4 is High |
5 | Enable Clock when Out3/Gate4 is Low |
Operation
Notes:
This function programs the hardware for Burst Mode or pseudo
simultaneous
sampling. In this mode, the ADC is sampled using Counter 5. Counter 5
is
programmed to sample at the maximum sampling rate and Counter 4 is used
to
gate Counter 5 on and off for the desired sampling rate. For example,
if the
ADC maximum sampling rate is 333 KHz, Counter 5 will be programmed to
have a
clock period of 3 micro seconds. If five analog input channels are
used, then
Counter 4 will be programmed to be high for (5 channels x 3 us/channel)
= 15
us. Counter 4 will then be low for the remainder of the time necessary
for
the specified sample rate. If the specified sample rate is 10KHz (100
us),
then Counter 4 would be high for 15 us and low for 85 us.
The analog input channels can be sampled continuously or can be controlled using Counter 3 output to gate Counter 4
Hardware Supported: LabMaster DMA, LabMaster AD/ADEX, LabMaster Pro
This function will return the period of the actual sampling rate. If the function is not supported, a zero will be returned.
This function can be used to enable and disable the analog output clock.
Hardware Supported: LabMaster Pro, LabMaster AD/ADEX, LabMaster Dma
Return
Codes:
RC_NoErr
RC_BadParameter1
RC_BadParameter2
RC_FunctionNotSupported
This function is used to start the analog input sampling using bus master dma to transfer the data directly from the hardware to the application buffer. The function LabPac_AiSampleRate should be used with this function to select the sampling rate. The data will be placed in the application buffer in a 32 bit format, with the MSB of the data aligned to the MSB of the user application.
This function will continuously fill the supplied buffer, using the supplied buffer as a buffer ring. Refer to LabPac_AiDmaPt function description for valid data region details.
PacketSize is the number of samples to be transferred to the application buffer on each Dma cycle. That is the Head of the buffer ring will increment by the PacketSize on each Dma cycle.
This function offers quicker data updates and supersedes the AiBM_PingPong function.
Hardware
Supported:
LabMaster Pro,
*LabMaster ADEX,
*LabMasterAD,
*LabMaster DMA
* These devices emulate the bus mastering call.
Return
Codes:
RC_NoErr
RC_BadParameter1
RC_BadParameter2
RC_BadParameter3
RC_FunctionNotSupported
This function is used with the function AiDmaPacket to transfer analog input data from the hardware to an application buffer. The buffer is used as a buffer ring. Initially the Head and Tail are at position zero, TTC and HTC are zero.
The Head of the buffer ring is incremented as data is inserted into the buffer by the driver, while the Tail of the buffer ring is incremented by the application program as data is read from the buffer. The Head position is greater than the Tail position.
When the Head reaches the end of the buffer, HTC will be one and the Head will again go to position zero. In this situation, the Head position is less than the Tail position. The buffer will contain valid data from the Tail position to the end of the buffer.
When the application program reaches the end of the buffer, it will set TTC (Tail Terminal Count) to one and go to position zero. When the application sets TTC to one, the driver will reset HTC and TTC to zero, and the buffer ring will once again be in the initial state where the Head position is greater than the Tail position.
This
function will check for
a
buffer
overrun
conditions.
When HTC is zero, the Head should be greater than the Tail and if HTC
is one,
the Head should be less than the Tail, otherwise and OverRun condition
exists
and this function will return RC_BufferOverRun.
Hardware Supported: LabMaster Pro
Return
Codes:
RC_NoErr
RC_BufferOverRun
RC_FunctionNotSupported
This function has been superseded with the AiDmaPacket function.
This function is used to start the analog input sampling using bus master dma to transfer the data directly from the hardware to the application buffer. The function LabPac_AiSampleRate should be used with this function to select the sampling rate. The data will be placed in the application buffer in a 32 bit format, with the MSB of the data aligned to the MSB of the user application. This function will continuously fill the supplied buffer. Use the function LabPac_AiBMPPIdx to determine which half of the buffer has been filled with data.
Use the AiCallBack_Status to monitor for buffer OverRuns or TimeOut conditions.
Hardware
Supported:
LabMaster Pro,
*LabMaster ADEX,
*LabMasterAD,
*LabMaster DMA
* These devices emulate the bus mastering call.
Return
Codes:
RC_NoErr
RC_BadParameter1
RC_BadParameter2
RC_BadParameter3
RC_FunctionNotSupported
This function is will return either a zero or 1. A zero indicates the lower half of the application buffer contains data and the upper half is being filled with data. A one indicates the upper half of the user buffer contains data and the lower half is being filled with data by the Dma process .
The application program should monitor the return value to determine when valid data is available.
Hardware Supported: LabMaster Pro, LabMaster AD/ADEX, LabMaster Dma
Return
Codes:
RC_NoErr
RC_FunctionNotSupported
This function is used to stop the analog input sampling and free up resources used during the conversion process.
Always call this function when analog input dma process are no longer needed.
Hardware Supported: LabMaster Pro, LabMaster AD/ADEX, LabMaster Dma
Return
Codes:
RC_NoErr
RC_FunctionNotSupported
This function will register the Event with the device driver and associate it with analog input interrupts. When the device driver receives an analog input interrupt request, the Event will be SET.
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_AiCallbackStatus function to obtain "real-time" results.
Hardware Supported: LabMaster Pro, LabMaster AD/ADEX, LabMaster Dma
Return
Codes:
RC_NoErr
RC_BadParameter1
RC_BadParameter2
RC_FunctionNotSupported
Prototype:
USHORT LabPac_AiCallbackCntl (ULONG DevNum, USHORT Cntl, USHORT
CntlMask);
This
function
will
determine the
situation that
will cause the driver to call the analog input callback function.
The table below shows the bit position corresponding to the event that
can
cause the analog input 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 | Analog Input Event |
0 | Ai Conversion process completed |
1 | Ai Dma 1/2 Completed
(Not Available) |
2 | Ai Fifo > 1/2 Full |
4 | Ai Fifo Overrun |
5 | The Event is Set when the dma controller issues a Terminal Count (TC). A TC will happen after a PacketLenth of data or a PageSize of data is received. This callback can be used to determine when to call the AiDmaPt function.. |
All other bits are reserved and should be set to zero.
Hardware Supported: LabMaster Pro, LabMaster AD/ADEX, LabMaster Dma
Return
Codes:
RC_NoErr
RC_BadParameter1
RC_BadParameter2
RC_FunctionNotSupported
This function will return the bit pattern corresponding to the analog input event that caused the Analog Input callback function to be called. Refer to the function LabPac_AiCallbackCntl and the Analog Input Event Table for a description of the valid events.
This function will return the number of samples transferred during the DMA process.
Hardware Supported: LabMaster Pro, LabMaster AD/ADEX, LabMaster Dma
Return
Codes:
Function will return the number of samples transferred.
This function is used to start the analog output conversion using bus master dma to transfer the data directly from the hardware to the application buffer. Use LabPac_AoClkSrc to select the clock for updating the DAC
The data must be placed in the application buffer in a 32 bit format, with the MSB of the data aligned to the MSB of the user application. This function will continuously read from AoBuf and write to the specified Analog output channel.
Use the function LabPac_AoBMPPIdx to determine when each half of the data buffer is being sent to the DACs
Hardware Supported: LabMaster Pro, LabMaster AD/ADEX, LabMaster Dma
Return
Codes:
RC_NoErr
RC_BadParameter1
RC_BadParameter2
RC_BadParameter3
RC_FunctionNotSupported
This function is used to stop the analog output dma process and free up resources.
Always call this function when analog output dma process are no longer needed.
Hardware Supported: LabMaster Pro, LabMaster AD/ADEX, LabMaster Dma
Return
Codes:
RC_NoErr
RC_FunctionNotSupported
This function will register the Event with the device driver and associate it with analog output interrupts. When the device driver receives an analog output interrupt request, the Event will be SET.
The
function
LabPac_AoCallbackCntl can
be used to set and view these conditions.
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_AoCallbackStatus function to obtain "real-time" results.
Hardware Supported: LabMaster Pro, LabMaster AD/ADEX, LabMaster Dma
Return
Codes:
RC_NoErr
RC_BadParameter1
RC_BadParameter2
RC_FunctionNotSupported
Prototype:
USHORT LabPac_AoCallbackCntl (ULONG DevNum, USHORT Cntl, USHORT
CntlMask);
This
function
will
determine the
situation that
will cause the driver to call the analog output callback function.
The table below shows the bit position corresponding to the event that
can
cause the analog output 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 | Analog Output Event |
0 | Ao Dma process completed |
1 | Ao Dma 1/2 Completed
(Not Available) |
2 | Ao Fifo < 1/2 Full |
4 | Ao Fifo Underrun |
All other bits are reserved and should be zero.
Hardware Supported: LabMaster Pro, LabMaster AD/ADEX, LabMaster Dma
Return
Codes:
RC_NoErr
RC_BadParameter1
RC_BadParameter2
RC_FunctionNotSupported
This function will return the bit pattern corresponding to the analog output event that caused the Analog output callback function to be called. Refer to the function LabPac_AoCallbackCntl and the Analog Output Event Table for a description of the valid events.
The LabPac functions will usually return the status of the call. The following is a list of return code values and the associated description. The definitions for these return codes are included in the RCode.h file. A reference to this file is usually included in the application source code.
In
general, the LabPac
functions
have the
following
format:
ReturnCode = LabPac_FunctionName (Param1, Param2, ...)
Return Value | Abbrev | Description |
---|---|---|
0 | RC_NoErr | No Error |
1 | RC_BadParameter1 | 1st Parameter is invalid. The device number is not valid |
2 | RC_BadParameter2 | 2nd Parameter is invalid |
3 | RC_BadParameter3 | 3rd parameter is invalid |
4 | RC_BadParameter4 | 4th parameter is invalid |
5 | RC_BadParameter5 | 5th parameter is invalid |
6 | RC_BadParameter6 | 6th parameter is invalid |
7 | RC_DeviceOpenError | Device could not be opened |
8 | RC_DeviceCloseError | Device could not be closed |
10 | RC_HwNotFound | Hardware not found |
11 | RC_JumperSelectable | Option requires a jumper or switch setting on the hardware. |
12 | RC_FunctionNotSupported | Function is not supported by the hardware |
13 | RC_XferInProgress | A Data Transfer is in progress |
14 | RC_BadPortDirection | Incorrect port direction was specified |
15 | RC_PortNotReconfigurable | The port cannot be reconfigured |
16 | RC_IOPortDiff | Reading from a port configured as an output |
17 | RC_InsufficientResources | Insufficient resources available |
18 | RC_BufferEmpty | Data transfer buffer is empty |
19 | RC_BufferFull | Data transfer buffer is full |
20 | RC_BufferOverRun | Data buffer Overrun |
21 | RC_FifoOverrun | Fifo overrun |
22 | RC_TimeOut | Function did not complete in the allowed time |
23 | RC_Ioctl_Failed | Invalid IOCTL code |
24 | RC_NoData | No data available |
25 | RC_InvalidDevNum | Invalid device number specified |
26 | RC_BadIrqNum | Invalid Interrupt level specified |
27 | RC_BadDmaNum | Invalid Dma channel specified |
28 | RC_BadAoFifoSize | Invalid Analog Fifo size |
29 | RC_BadConvMode12 | Hardware does not support 12 bit conversion mode |
30 | RC_BadConvMode16 | Hardware does not support 16 bit conversion mode |
31 | RC_BadPort | Invalid I/O address space specified |
32 | RC_BadDirection | Invalid direction specified |
33 | RC_Range | Invalid range specified |
34 | RC_NullPointer | Null pointer, Invalid memory pointer |
35 | RC_NoIrqResource | No interrupt resources available |
36 | RC_NoDmaResource | No dma resources available |
37 | RC_NotImplemented | Function is not implemented |
38 | RC_BadConvMode8 | Hardware does not support 8 bit conversion mode |
Version
2005.10.10
Added LabPac functions: AiSetNoC, AiBufInit, AiGetBuf
Version
2005.04.13
Add ExtIrq_Callback, ExtIrq_Enable functions.
Specifications subject to change without notice.
Scientific Solutions liability, trademarks, and export notices apply.
Copyright © 1974-2005 Scientific Solutions - All rights reserved