This file descibes the functions supported by the libnidaq.so library.
Read it ONLY if you are interested in writing C programs to access National Instruments daq boards.

CHAP 1. GETTING STARTED
CHAP 2. GENERAL ISSUES - read it !
CHAP 3. REFERENCE
     3.1 AI functions
     3.2 AO functions
     3.3 DIO functions
     3.4 GPCT functions


CHAP 1. GETTING STARTED

To use this functions from a C program you should include "nidaq.h". This file
should be installed in the /usr/include directory (see install.txt).

You should also use the -lnidaq library when linking. This file should be installed in the /usr/lib directory (see install.txt) 

Sample: *****************

1. edit the file testao.c:

#include <nidaq.h>
main()
{
	int fh;
	if((fh=LxAoOpen(1))<0){exit(1);}
	LxAoUpdateChannel(f, 0, 2.0);
	return 0;
}

2. compile the program

gcc -o testao testao.c -lnidaq

This program writes 2.0V to DAC0 of the first board installed.

3. run the program:

./testao

**************************

CHAP 2. GENERAL ISSUES

Prior of using any function you should open the device. Choose from:
int LxAiOpen(__u16 device);
int LxAoOpen(__u16 device);
int LxDioOpen(__u16 device);
int LxGpctOpen(__u16 device, __u16 counter_no);
where 1<=device<=number of boards installed
note that device 1 corresponds to /dev/nidaq0, /dev/nidio0, /dev/nigpct{0,1}

All these functions return a handle which should be used when calling the rest of the library functions. If the returned handle <0, an error occured and you should not continue (maybe invalid device no or device already opened).



CHAP 3. REFERENCE

CHAP 3.1 AI FUNCTIONS:

int LxAiOpen(__u16 device);
opens AI device <device> and returns a handle; handle<0 on error

int LxAiCloseAll();
closes all AI devices opened by the current program; used by labVIEW

int LxAiScale(__s32 fh, __u32 nscans, __s16 rddata[], float voltages[]);
scales <nscans> from the <rddata> short int array into the <voltages> float array. The number of channels, gain & polarity info used for scaling are taken from the previous call of LxAiBoardConfig (see below)

int LxAiBoardConfig(__s32 fh, __u16 nch, __u16 channels[], __u16 gains[],
                    __u16 polars[], __u16 refers[]);
configures the input channels: <nch> channels will be used;
<channels>, <gains>, <polars>, <refers> are arrays of size <nch> and contain:
<channels>: the channel number
<gains>: tha gain (0=0.5, 1=1, 2=2, 3=5, 4=10, 5=20, 6=50, 7=100)
<polars>: the polarity (0=bipolar, 1=unipolar)
<refers>: the reference mode (0=diff, 1=NRSE, 2=RSE)

int LxAiTimeConfig(__s32 fh, double scan_freq, double spl_freq, 
                   double *act_scan_freq, double *act_spl_freq);
configures the timing parameters for AI.
<spl_freq> is the sample frequency; if =0 then the max freq possible is used
<scan_freq> is the scan frequency; if =0 then the max freq possible is used (sample frequency / no of chanels)
<act_scan_freq> and <act_spl_freq> return the actual scan and sample freq. Use them for exact computings or to see thew actual freq. if you used 0 parameters

int LxAiStart(__s32 fh, __s32 no_of_scans);
starts a buffered acquisition. LxAiBoardConfig anf LxAiTimeConfig should
be called prior to this function.
<no_of_scans> is the number of scans the driver will read. continuous mode
not supported yet.

int LxAiGetnch(__s32 fh);
returns the no of channels in a scan; the value is taken from the previous call to LxAiBoardConfig

int LxAiRead(__s32 fh, __s32 no_scans, __s16 buff[], __s32 *scans_read);
reads <no_scans> scan into the buff <buff>. The function should be called only after calling LxAiStart.
<scans_read> contains the no of scans actually read.
the function returns <0 if an error occured; at this moment the function
returns succsessfuly only if <scans_read>==<no_scans>

int LxAiClear(__s32 fh);
clears the AI acquisition

int LxAiSingleScan(__s32 fh, __s16 buff[]);
generates and reads a single scan in the <buff> buffer. Call it only after LxAiBoardConfig and LxAiTimeConfig ( of course, the <scan_freq> will be not used )
DO NOT call it after LxAiStart ! If you want to retrieve scan by scan from
a buffered acquisition, please use LxAiRead with <no_scans>=1


CHAP 3.2 AO FUNCTIONS:


int LxAoOpen(__u16 device);
opens AO device <device> and returns a handle; handle<0 on error

int LxAoCloseAll(void);
closes all AO devices opened by the current program; used by labVIEW

int LxAoUpdateChannel(__s32 fh, __u16 channel, double voltage);
outputs voltage <voltage> on the AO channel <channel>


CHAP 3.2 DIO FUNCTIONS

int LxDioOpen(__u16 device);
opens DIO device <device> and returns a handle; handle<0 on error

int LxDioCloseAll(void);
closes all AO devices opened by the current program; used by labVIEW

int LxDioConfPort(__s32 fh, __u16 port, __u32 rw_mask);
configures the port <port> for input / output
For E-series boards each bit in <rw_mask> corresponds to a line (0=in, 1=out) i.e. 0xF0 configure bits 7..4 as outputs and bits 3..0 as inputs
For 8255 based boards <rw_mask> is 0=input port, !0=output port

int LxDioWrite(__s32 fh, __u16 port, __u32 wr_data, __u32 wr_mask);
writes <wr_data> on the port <port>, using <wr_mask> mask; i.e. writing w/ <wr_mask=0x03> will write only bits 1..0, the rest remain unchanged
At this moment all suported boads have 8-bit ports, so only 8 bits of <wr_data> are currently used.

int LxDioRead(__s32 fh, __u16 port, __u32 *read_data);
reads from port <port> and places the result in <read_data>


CHAP 3.3 GPCT FUNCTIONS

int LxGpctOpen(__u16 device, __u16 counter_no);
opens counter <counter_no> of device <device> and returns a handle; handle<0 on error

int LxGpctCloseAll(void);
closes all GPCT devices opened by the current program; used by labVIEW

int LxGpctSetapp(__s32 fh, __s16 function);
sets up the counter for the application <function>:
1: event count
5: 1 pulse genaration
6: 1 triggered pulse generation
7: retriggerable pulse generation
8: pulse train generation
at this moment the other functions are not supported

int LxGpctSetpar(__s32 fh, __s16 param, __u32 value);
sets the counter paramater <parameter> to <value>. Call it after LxGpctSetapp.
<parameter> can be:
1: source select
2: source polarity
3: gate select
4: gate polarity
6,7,8,9: cnt1, cnt2, cnt3 and cnt4
11: up/down
12: output mode
13: output polarity

int LxGpctControl(__s32 fh, __s16 function);
gives a command to the counter; <function> can be:
1: reset - resets the counter
2: prepare - prepare the counter before arming
3: arm - arm (activate) the counter
4: program = prepare + arm
7: disarm - disarms (deactivate) the counter

int LxGpctWatch(__s32 fh, __s16 function, __u32 *result);
reads a parame. from a counter and places it into <result>. <function> can be:
1: read - reads the current counter value


