/************************************** * icollect.c (remake version) * * * * Simple data acquisition program * * based on ComputerBoard's ULAI06.C * * * * Nov. 10, 2001 * * by I. Hidaka * **************************************/ /* Include files */ #ifdef WIN32 // WIN32 Console Application #include #include #include #include "cbw.h" #else // DOS text mode application #include #include #include #include #include "cb.h" typedef unsigned int WORD; // 16-bit unsigned int #endif // WIN32 Console, or DOS text mode? /* Prototypes */ void set_option(void); void data_io(void); void ClearScreen (void); int mystrncmp(char *ptr1, char *ptr2, int i, char sep); /* Global Variables */ char option[256]; int BoardNum = 0; int ULStat = 0; int LowChan = 0; int HighChan = 0; int nChan = 1; int Gain = BIP10VOLTS; long Rate = 1000; int fg_engunit = 0; void main(int argc, char **argv){ int i; for (*option = 0, i = 1; i < argc; i++) strcat(option, argv[i]); set_option(); data_io(); } void set_option(void){ char *token; int i; token = strtok(option, "/"); while (token != NULL) { /* check if line skip */ if (!mystrncmp(token, "TS:", 3, ' ')) { for (i = 0; i < 3; i++) token++; Rate = atoi(token); } if (!mystrncmp(token, "BG:", 3, ' ')) { for (i = 0; i < 3; i++) token++; LowChan = atoi(token); } if (!mystrncmp(token, "ED:", 3, ' ')) { for (i = 0; i < 3; i++) token++; HighChan = atoi(token); } if (!mystrncmp(token, "EU", 2, ' ')) { fg_engunit = 1; } if (!mystrncmp(token, "HE", 2, ' ')) { fprintf(stderr, "Valid options are:\n"); fprintf(stderr, " /TS:n sampling freq (Hz)\n"); fprintf(stderr, " /BG:n Start Ch\n"); fprintf(stderr, " /ED:n End Ch\n"); fprintf(stderr, " /EU output with eng. unit\n"); exit(0); } token = strtok(NULL, "/"); } } void data_io(void){ WORD *ADData; unsigned Options; float revision = (float)CURRENTREVNUM; /* for cbGetStatus() and ADC detection*/ short Status = RUNNING; long CurCount; long CurIndex; long oldCurCount = -1; long oldCurCount2 = -1; long Count2; int i,j; long k = 0; long l = 0; long Count = 1000; char pushedkey; float *EngUnit; float dummy; float *EngUnit2; float dummy2; EngUnit = &dummy; EngUnit2 = &dummy2; nChan = (HighChan - LowChan + 1); Count = Rate * nChan; Count2 = Count/2; /* Declare Revision level of the Universal Library */ ULStat = cbDeclareRevision(&revision); ADData = malloc(Count*2*sizeof(unsigned)); if (!ADData) /* Make sure it is a valid pointer */ { fprintf(stderr, "\nout of memory\n"); exit(1); } /* Initiate error handling Parameters: PRINTALL :all warnings and errors encountered will be printed STOPFATAL :if any fatal error is encountered, the program will stop */ cbErrHandling (PRINTALL, STOPFATAL); /* set up the display screen */ ClearScreen(); fprintf (stderr, " Channel: %d to %d\n", LowChan, HighChan); fprintf (stderr, " Sample rate: %d (Hz)\n", Rate); fprintf (stderr, "\n========Press \"s\" to start collection.========\n\n"); while (1){ if(_kbhit()!=0){ pushedkey = _getch(); if((pushedkey =='s') || (pushedkey == 'S')){ break; } } } /* Collect the values with cbAInScan() in BACKGROUND mode, CONTINUOUSLY */ Options = CONVERTDATA + BACKGROUND + CONTINUOUS + SINGLEIO; ULStat = cbAInScan (BoardNum, LowChan, HighChan, Count, &Rate, Gain, ADData, Options); fprintf (stderr, "\nCollecting data...\n\n"); fprintf (stderr, "Press 'q' to quit.\n\n"); /* During the BACKGROUND operation, check the status */ while (1){ ULStat = cbGetStatus (BoardNum, &Status, &CurCount, &CurIndex); if(Status != RUNNING){ break; } /* output 1st half of data array */ if (CurIndex % Count == Count2) { if(CurCount != oldCurCount){ for(i=0; i 0) && (CurIndex < Count2)){ for(i=0; i<=CurIndex; i+=nChan){ l++; fprintf(stdout, "%-7d ", l); for(j=0; j Count2) && (CurIndex < Count)){ for(i=Count2; i<=CurIndex; i+=nChan){ l++; fprintf(stdout, "%-7d ", l); for(j=0; j