Accessing tempbook from a windows program, Accessing tempbook from a c-for-windows program, High-level analog input – Measurement Computing TempBook rev.3.0 User Manual
Page 33: Standard api programming of the tempbook with c

Standard API Programming of the TempBook with C
6
TempBook User’s Manual
Standard API Programming of the TempBook with C 6-1
Note: The enhanced API commands do not work exactly like the standard API commands; refer to chapters 10 and 11.
Accessing TempBook from a Windows Program
The structure of a Windows program generally dictates that actions take place in response to messages such
as an operator key-press, mouse action, menu selection, etc. This discussion covers the basic actions
needed to control the TempBook. How these actions are combined and coordinated in response to
Windows messages is up to the application designer.
Accessing TempBook from a C-for-Windows Program
There is one library and one header file located in the TEMPBOOK\WIN\C directory. The header file,
TEMPBOOK.H, must be included at the top of a C program using the #include command. This will
allow the compiler to know what TempBook functions and constants are available.
The library, TEMPBOOK.LIB, must be included in the application's makefile or project file so that the
linker will find the TempBook functions. This is a large memory model library; the appropriate compiler
and linker options for a large memory model program must be invoked. See the documentation for your
specific C compiler for a description on using header files, libraries, and memory models.
To use the example program located in the TEMPBOOK\DOS\C directory, create a makefile or project file
which consists of the TBKEX.C source file, TBKEX.RC resource file, TBKEX.DEF definition file,
TBKEX.ICO icon file and the TEMPBOOK.LIB library.
High-Level Analog Input
The following excerpt from TBKEX.C shows the usage of several high level analog input routines.
unsigned sample, buf [10], data[7], data2[80];
int i, scan, chan;
Set default operating mode to single-ended, bipolar. These parameters will affect all scanned channels.
tbkSetMode(0, 1);
Get one A/D sample from channel 0 at unity gain and print the unsigned integer that is returned. Since the
TempBook contains a 12-bit A/D converter, the least significant 4 bits are undefined. Shifting the value to
the right 4 times right justifies the 12 bit value in the 16 bit variable.
tbkRd(0, &sample, TgainX1);
sprintf(tempstr, "Result of tbkRd : %4d\r\n\r\n", sample>4);
Get 10 samples from channel 0, trigged by the pacer clock with a 1kHz sampling frequency at unity gain.
Once the data has been collected, print the 10 samples that were placed in the buffer.
tbkRdN(0, buf, 10, TtsPacerClock, 0, 1000, TgainX1);
sprintf("tempstr, "Results of tbkRdN:");
strcat (response, tempstr);
for(i=0;i<8;i++){
sprintf(tempstr, "%4d ", buf[i]>4);
strcat (response, tempstr);
}
Get 1 scan of channels 0 to 7 at unity gain. Once the data has been collected, print all 8 channel values.
tbkRdScan(0, 7, data, TgainX1);
sprintf(tempstr"\r\n\r\nResults of tbkRdscan:\r\n");
strcat (response, tempstr);
for(i=0;i<8;i++) {
sprintf(tempstr"Channel: %2d Data: %4d\r\n", i, data[i]>4);
strcat (response, tempstr);
}