tic  130
tic_totalcount.c
/*
* TIC/TINA demo programm
*/
#include <stdio.h>
#include "tic/tic_c.h"
#if defined(MMSYS_linux)
#include <sys/select.h>
int kbhit()
{
struct timeval tv = { 0L, 0L };
fd_set fds;
FD_ZERO(&fds);
FD_SET(0, &fds);
return select(1, &fds, NULL, NULL, &tv);
}
#else
#include <conio.h>
int kbhit() { return _kbhit(); }
#endif
const int iTic=0; /* index of the first instrument installed */
int main(int argc, char **argv) {
/* initialize device */
if (tic_init(iTic) <0) goto lFail;
/* initialize demo stimuli */
if (tic_init_stimuli(iTic)) goto lFail;
/*
* continously take measurements until a key is hit
*/
do {
/* set measurement mode */
if (tic_mode_totalcount(iTic)) goto lFail;
/* arm device */
if (tic_arm(iTic)) goto lFail;
/* run device until it has results */
while (tic_loop(iTic) > 0 && !kbhit());
/* get measurements */
while (tic_count_samples(iTic) > 0) {
long long cTotal; /* at least 64 bits by C99 standard */
cTotal=tic_read_totalcount(iTic);
printf("count=%lld\n", cTotal);
}
} while (!kbhit());
tic_fini(iTic);
return 0;
lFail:
/* error handling */
fprintf(stderr, "tic failed: %s %d\n", tic_errortext(iTic), tic_diagcode(iTic));
tic_fini(iTic);
return 2;
}