int main(void) { I16 card, err; BOOLEAN bStopped; setbuf( stdout, NULL ); clrscr(); printf("This program inputs %ld data from CH-0 to CH-%d of PCI-9111 in %d Hz, and\nstore data to file '%s'.\nPlease press any key to start the operation.", read_count, channel, (int)sample_rate, file_name); getch(); if ((card=Register_Card (PCI_9111DG, 0)) <0 ) { printf("Register_Card error=%d", card); exit(1); } err = AI_9111_Config(card, TRIG_INT_PACER, 0, 1024); if (err!=0) { printf("AI_9111_Config error=%d", err); Release_Card(card); exit(1); } err = AI_AsyncDblBufferMode(card, 0); if (err!=0) { printf("AI_DblBufferMode error=%d", err); Release_Card(card); exit(1); } mem_size=read_count * 2; ai_buf = (I16*)malloc(mem_size); //err = AI_ContScanChannelsToFile(card, channel, range, file_name, read_count, sample_rate, ASYNCH_OP); err = AI_ContScanChannels(card, channel, range, ai_buf, read_count, sample_rate, ASYNCH_OP); //err = AI_ContReadChannel(card, channel, range, ai_buf, read_count, sample_rate, ASYNCH_OP); if (err!=0) { printf("AI_ContReadChannel error=%d", err); Release_Card(card); free( ai_buf ); exit(1); } do { AI_AsyncCheck(card, &bStopped, &read_count); usleep(10); } while(bStopped == FALSE); AI_AsyncClear(card, &read_count); printf(" %ld data trnasfered !\n", read_count ); Release_Card(card); show_channel_data( ai_buf, channel+1 ); if( write_to_file( ai_buf, channel+1 ) ) printf("\n\nThe input data is already stored in file '%s'.\n", file_name); free( ai_buf ); printf("\nPress ENTER to exit the program. "); getchar(); return 0; }
int main(void) { I16 card, err; setbuf( stdout, NULL ); printf("This program inputs %ld data from CH-0 to CH-%d of PCI-9812 in %d Hz, and\nstore data to file '%s'.\nPlease press any key to start the operation.\n", read_count, channel, (int)sample_rate, file_name); getch(); if ((card=Register_Card (PCI_9812, 0)) <0 ) { printf("Register_Card error=%d\n", card); exit(1); } err = AI_9812_Config(card, P9812_TRGMOD_SOFT, P9812_TRGSRC_CH0, P9812_TRGSLP_POS, P9812_AD2_GT_PCI|P9812_CLKSRC_INT, 0x80, 0); if (err!=0) { printf("AI_9812_Config error=%d", err); exit(1); } err = AI_AsyncDblBufferMode(card, 0); if (err!=0) { printf("AI_DblBufferMode error=%d", err); exit(1); } mem_size=read_count * 2; ai_buf = (I16*)malloc(mem_size); err = AI_ContScanChannels(card, channel, range, ai_buf, read_count, sample_rate, SYNCH_OP); if (err!=0) { printf("AI_ContReadChannel error=%d", err); free( ai_buf ); Release_Card(card); exit(1); } printf(" %ld data trnasfered !\n", read_count ); Release_Card(card); if( write_to_file( (U16*)ai_buf, channel+1 ) ) printf("\n\nThe input data is already stored in file '%s'.\n", file_name); // show_channel_data( (U16*)ai_buf, channel+1 ); plot_channel_data(); free( ai_buf ); printf("\nPress ENTER to exit the program. "); //getch(); //putchar('\n'); return 0; }
int main(void) { I16 err; void * retval; setbuf( stdout, NULL ); clrscr(); printf("This program inputs data from CH-%d to CH-0 of PCI-9112 in %d Hz by\ndouble-buffer mode, and store data to file '%s.dat'. The size of circular\nbuffer is %ld. It will not stop until you press a key.\n\nPress any key to start the operation.\n", channel, (int)sample_rate, file_name, read_count); getch(); if ((card=Register_Card (PCI_9112, 0)) <0 ) { printf("Register_Card error=%d", card); exit(1); } err = AI_9112_Config(card, TRIG_INT_PACER); if (err!=0) { printf("AI_9112_Config error=%d", err); Release_Card( card ); exit(1); } err = AI_AsyncDblBufferMode(card, 1); //double-buffer mode if (err!=0) { printf("AI_DblBufferMode error=%d", err); Release_Card( card ); exit(1); } err = AI_ContScanChannelsToFile(card, channel, range, file_name, read_count, sample_rate, ASYNCH_OP); if (err!=0) { printf("AI_ContReadChannel error=%d", err); Release_Card( card ); exit(1); } clear_op = FALSE; printf("\n\n\n\n\n Data conversion start , Press any key to stop input operation.\n"); if( pthread_create( &thread1, NULL, ProcessThread, NULL ) != 0 ){ printf(" Can't create thread1 , terminate \n "); Release_Card(card); exit(-1); } getch(); clear_op = TRUE; pthread_join(thread1, &retval); Release_Card(card); exit(0); }
int main(void) { I16 err, card; U16 channel=3; U16 range=AD_B_10_V; U32 read_count=2048; F64 sample_rate=2048; U32 *ai_buf; int i; if((card=Register_Card(PCI_9114DG, 0))<0){ printf("Register_Card error=%d", card); Release_Card(card); exit(1); } do{ err = AI_9114_Config(card, TRIG_INT_PACER); if(err!=0){ printf("AI_9114_Config error=%d", err); Release_Card(card); exit(1); } err = AI_AsyncDblBufferMode(card, 0); if(err!=0){ printf("AI_DblBufferMode error=%d", err); Release_Card(card); exit(1); } ai_buf = (U32*)malloc(read_count*4); memset(ai_buf, '\0', read_count*4); err = AI_ContReadChannel(card, channel, range, ai_buf, read_count, sample_rate, SYNCH_OP); if(err!=0){ printf("AI_ContReadChannel error=%d", err); Release_Card(card); free(ai_buf); exit(1); } free(ai_buf); printf("Loop %d\n", ++i); }while(!kb_hit()); Release_Card(card); return 0; }
int main(void) { I16 card, err; setbuf( stdout, NULL ); printf("This program inputs %ld data from CH-0 to CH-%d of PCI-9118 in %d Hz, and\nstore data to file '%s'.\nPlease press any key to start the operation.\n", read_count, channel, (int)sample_rate, file_name); getch(); if ((card=Register_Card (PCI_9118DG, 0)) <0 ) { printf("Register_Card error=%d", card); exit(1); } err = AI_9118_Config(card, P9118_AI_BiPolar|P9118_AI_SingEnded, 0, 0, 0); if (err!=0) { printf("AI_9118_Config error=%d", err); Release_Card(card); exit(1); } err = AI_AsyncDblBufferMode(card, 0); if (err!=0) { printf("AI_DblBufferMode error=%d", err); Release_Card(card); exit(1); } mem_size=read_count*2; ai_buf = (U16*)malloc(mem_size); //err = AI_ContReadChannel(card, channel, range, ai_buf, read_count, sample_rate, SYNCH_OP); err = AI_ContScanChannels(card, channel, range, ai_buf, read_count, sample_rate, SYNCH_OP); if (err!=0) { printf("AI_ContReadChannel error=%d", err); Release_Card(card); free( ai_buf ); exit(1); } Release_Card(card); if( write_to_file( ai_buf, channel+1 ) ) printf("\n\nThe input data is already stored in file '%s'.\n", file_name); show_channel_data( ai_buf, channel+1 ); free( ai_buf ); printf("\nPress ENTER to exit the program. "); getchar(); return 0; }
int acquire_data() { I16 card, err; setbuf( stdout, NULL ); // printf("This program inputs %ld data from CH-0 to CH-%d of PCI-9812 in %d Hz, and\nstore data to file '%s'.\nPlease press any key to start the operation.\n", read_count, channel, (int)sample_rate, file_name); // getch(); if ((card=Register_Card (PCI_9812, 0)) <0 ) { printf("Register_Card error=%d\n", card); exit(1); } err = AI_9812_Config(card, P9812_TRGMOD_SOFT, P9812_TRGSRC_CH0, P9812_TRGSLP_POS, P9812_AD2_GT_PCI|P9812_CLKSRC_INT, 0x80, 0); if (err!=0) { printf("AI_9812_Config error=%d", err); exit(1); } err = AI_AsyncDblBufferMode(card, 0); if (err!=0) { printf("AI_DblBufferMode error=%d", err); exit(1); } mem_size=read_count * 2; ai_buf = (I16*)malloc(mem_size); err = AI_ContScanChannels(card, channel, range, ai_buf, read_count, sample_rate, SYNCH_OP); if (err!=0) { printf("AI_ContReadChannel error=%d", err); free( ai_buf ); Release_Card(card); exit(1); } printf("%ld data samples transfered.\n", read_count ); Release_Card(card); return 0; }
int main(void) { I16 err; U32 mem_size; setbuf( stdout, NULL ); clrscr(); printf("\n 9111 Double Buffer Demo : \n"); printf(" This program inputs data from CH-0 to CH-%d of PCI-9111 in %d Hz by\n double-buffer mode, and store data to file '%s'. The size of circular\n buffer is %ld. It will not stop until you press a key.\n\n Press any key to start the operation.\n", channel, (int)sample_rate, file_name,read_count); getch(); if ((card=Register_Card(PCI_9112, 0)) <0 ) { printf("Register_Card error=%d", card); Release_Card(card); exit(1); } err = AI_9112_Config(card, TRIG_INT_PACER); if (err!=0) { printf("AI_9111_Config error=%d", err); Release_Card(card); exit(1); } err = AI_AsyncDblBufferMode(card, 1); //double-buffer mode if (err!=0) { printf("AI_DblBufferMode error=%d", err); Release_Card(card); exit(1); } if (( fp = fopen( file_name , "w+b")) == NULL){ Release_Card(card); exit(1); } mem_size=read_count * 2; ai_buf = (I16*)malloc(mem_size); err = AI_ContScanChannels(card, channel, range, ai_buf, read_count, sample_rate, ASYNCH_OP); if (err!=0) { printf("AI_ContReadChannel error=%d", err); Release_Card(card); free( ai_buf ); exit(1); } clear_op = FALSE; printf("\n\n\n\n\n Data conversion start , Press any key to stop input operation.\n"); if( pthread_create( &thread1, NULL, ProcessThread, NULL ) != 0 ){ printf(" Can't create thread1 , terminate \n "); Release_Card(card); exit(-1); } getch(); clear_op = TRUE; sleep(1); printf("\n\n Press any key to exit the program..... "); getch(); exit(0); }
int main(int argc, char **argv) { I16 card, err; U16 card_num; U16 ConfigCtrl = P922x_AI_SingEnded|P922x_AI_CONVSRC_GPI0; U16 TrigCtrl = 0; /*Dose not support any trigger mode/source in external conversion source mode*/ U32 ReTriggerCount = 0; /*Dose not support any trigger mode/source in external conversion source mode*/ BOOLEAN AutoResetBuf = 1; /*Auto Reset Buffer Descriptor in Driver*/ U16 RDBuffer[AI_COUNT]; U16 BufferId; F64 VBuffer[AI_COUNT]; U32 AI_ReadCount = AI_COUNT; /*AI Read Count*/ U16 Channel = 0; /*AI Channel Number to be read*/ U16 AdRange = AD_B_10_V; /*AI range*/ BOOLEAN Stopped; U32 AccessCnt; FILE *w_file; U8 FileName[] = "ai_data.dat"; U32 i; /*--------------------------------*/ memset(RDBuffer, '\0', AI_COUNT*sizeof(U16)); memset(VBuffer, '\0', AI_COUNT*sizeof(F64)); if(!(w_file=fopen(FileName, "w"))){ printf("file open error...\n"); exit(1); } fprintf(w_file, "Channel %d,\n", Channel); printf("This sample performs continuous AI acquisition from AI Channel %d\n", Channel); printf("with external conversion source (GPI0).\n\n"); /*Open and Initialize Device*/ printf("Card Number? "); scanf(" %hd", &card_num); card = Register_Card(PCI_9223, card_num); if(card<0){ printf("Register_Card Error: %d\n", card); fclose(w_file); exit(1); } /*Configure AI*/ err = AI_9223_Config(card, ConfigCtrl, TrigCtrl, ReTriggerCount, AutoResetBuf); if(err<0){ printf("AI_9223_Config Error: %d\n", err); Release_Card(card); fclose(w_file); exit(1); } /*Disable Double Buffer Mode*/ err = AI_AsyncDblBufferMode(card, 0); if(err<0){ printf("AI_AsyncDblBufferMode Error: %d\n", err); Release_Card(card); fclose(w_file); exit(1); } /*Setup Buffer for AI DMA Transfer*/ err = AI_ContBufferSetup(card, RDBuffer, AI_ReadCount, &BufferId); if(err<0){ printf("AI_ContBufferSetup Error: %d\n", err); Release_Card(card); fclose(w_file); exit(1); } /*AI Acquisition Start*/ printf("\nPress any key to start AI to wait conversion source from GPI0.\n"); printf(" And you can press Enter to stop...\n"); getch(); err = AI_ContReadChannel(card, Channel, AdRange, &BufferId, AI_ReadCount, 0/*Ignore*/, ASYNCH_OP); if(err<0){ printf("AI_ContReadChannel Error: %d\n", err); AI_ContBufferReset(card); Release_Card(card); fclose(w_file); exit(1); } do{ /*Check whether AI Acquisition is done*/ err = AI_AsyncCheck(card, &Stopped, &AccessCnt); if(err<0){ printf("AI_AsyncCheck Error: %d\n", err); AI_AsyncClear(card, &AccessCnt); AI_ContBufferReset(card); Release_Card(card); fclose(w_file); exit(1); } }while((!kbhit())&&(!Stopped)); /*Clear AI Setting and Get Remaining data*/ err = AI_AsyncClear(card, &AccessCnt); if(err<0){ printf("AI_AsyncClear Error: %d\n", err); AI_AsyncClear(card, &AccessCnt); AI_ContBufferReset(card); Release_Card(card); fclose(w_file); exit(1); } if(Stopped){ printf("\n\nAI Acquisition Done... Acquired %d samples...\n", AccessCnt); printf("Write %d samples of Buffer to %s file...\n", AccessCnt, FileName); AI_ContVScale(card, AdRange, RDBuffer, VBuffer, AccessCnt); for(i=0; i<AccessCnt; i++){ fprintf(w_file, "%f,\n", VBuffer[i]); } } else{ printf("\nAI Acquisition has been stopped manually... Acquired %d samples...\n", AccessCnt); printf("Write %d samples of Buffer to %s file...\n", AccessCnt, FileName); AI_ContVScale(card, AdRange, RDBuffer, VBuffer, AccessCnt); for(i=0; i<AccessCnt; i++){ fprintf(w_file, "%f,\n", VBuffer[i]); } } if(!AutoResetBuf) AI_ContBufferReset(card); Release_Card(card); fclose(w_file); printf("\nPress any key to exit...\n"); getch(); return 0; }
int main(int argc, char **argv) { I16 card, err; U16 card_num; U16 ConfigCtrl = P922x_AI_SingEnded|P922x_AI_CONVSRC_INT; U16 TrigCtrl = P922x_AI_TRGMOD_GATED|P922x_AI_TRGSRC_GPI0|P922x_AI_TrgPositive; U32 ReTriggerCount = 0; /*Ignore if trigger mode is gated trigger*/ BOOLEAN AutoResetBuf = 1; /*Autoreset buffer descriptor build in driver*/ U32 ScanIntrv = 320; /*Scan rate: P922X_TIMEBASE/320=250K*/ U32 SampIntrv = 320; /*Sampling rate: P922X_TIMEBASE/320=250K*/ U32 RDBuffer[READCOUNT]; /*4 Bytes per a sample if trigger mode is Gated Trigger*/ U16 BufferId; F64 VBuffer[READCOUNT]; U32 AI_ReadCount = READCOUNT; /*AI read count*/ U16 Channel = 0; /*AI channel to be read*/ U16 AdRange = AD_B_10_V; /*AI range*/ BOOLEAN Stopped = FALSE; U32 AccessCnt = 0; FILE *w_file; U8 FileName[] = "ai_data.dat"; U32 i; memset(RDBuffer, '\0', READCOUNT*sizeof(U32)); memset(VBuffer, '\0', READCOUNT*sizeof(F64)); if(!(w_file=fopen(FileName, "w"))){ printf("file open error...\n"); exit(1); } fprintf(w_file, "Channel %d,\n", Channel); printf("This sample performs continuous AI acquisition with Gated trigger\n"); printf("from AI Channel %d at %6.3lf Hz sampling rate.\n", Channel, P922X_TIMEBASE/SampIntrv); /*Open and Initialize Devie*/ printf("Card Number? "); scanf(" %hd", &card_num); card = Register_Card(PCI_9222, card_num); if(card<0){ printf("Register_Card Error: %d\n", card); fclose(w_file); exit(1); } /*Configure AI configurations*/ err = AI_9222_Config(card, ConfigCtrl, TrigCtrl, ReTriggerCount, AutoResetBuf); if(err<0){ printf("AI_9222_Config Error: %d\n", err); Release_Card(card); fclose(w_file); exit(1); } /*Set Counter Scan and Sample Interval*/ err = AI_9222_CounterInterval(card, ScanIntrv, SampIntrv); if(err<0){ printf("AI_9222_CounterInterval Error: %d\n", err); Release_Card(card); fclose(w_file); exit(1); } /*Disable Double Buffer Mode*/ err = AI_AsyncDblBufferMode(card, 0); if(err<0){ printf("AI_AsyncDblBufferMode Error: %d\n", err); Release_Card(card); fclose(w_file); exit(1); } /*Buffer Setup - Build Buffer Descriptor in Driver*/ err = AI_ContBufferSetup(card, RDBuffer, AI_ReadCount, &BufferId); if(err<0){ printf("AI_ContBufferSetup Error: %d\n", err); Release_Card(card); fclose(w_file); exit(1); } /*Start AI Acquisition*/ err = AI_ContReadChannel(card, Channel, AdRange, &BufferId, AI_ReadCount, 0/*Ignore*/, ASYNCH_OP); if(err<0){ printf("AI_ContReadChannel Error: %d\n", err); AI_ContBufferReset(card); Release_Card(card); fclose(w_file); exit(1); } printf("\nWait Gated Positive Trigger from GPI0...\n"); do{ err = AI_AsyncCheck(card, &Stopped, &AccessCnt); if(err<0){ printf("AI_AsyncCheck Error: %d\n", err); AI_AsyncClear(card, &AccessCnt); AI_ContBufferReset(card); Release_Card(card); fclose(w_file); exit(1); } }while((!kbhit())&&(!Stopped)); err = AI_AsyncClear(card, &AccessCnt); if(err<0){ printf("AI_AsyncClear Error: %d\n", err); AI_AsyncClear(card, &AccessCnt); AI_ContBufferReset(card); Release_Card(card); fclose(w_file); exit(1); } if(Stopped) printf("\n\nAI Acquisition done...\n"); else printf("\n\nAI Acquisition has been stopped manually...\n"); printf("Write %d samples of Buffer to %s file...\n\n", AccessCnt, FileName); fprintf(w_file, "Raw Data, Scaled Voltage,\n"); AI_ContVScale(card, AdRange, RDBuffer, VBuffer, AccessCnt); for(i=0; i<AccessCnt; i++){ fprintf(w_file, "0x%x, %6.4f,\n", RDBuffer[i], VBuffer[i]); } if(!AutoResetBuf) AI_ContBufferReset(card); Release_Card(card); fclose(w_file); printf("\nPress any key to exit...\n"); getch(); return 0; }
int main(void) { I16 err; int ai_mode, dl_mode; setbuf( stdout, NULL ); printf("Please select the AI type (0:DMA 1:INT): "); scanf(" %d", &ai_mode); printf("Please select the Delay type (0:In Timebase 1:In Samples): "); scanf(" %d", &dl_mode); printf("Double Buffer Transfer With Delay Trigger operation\n"); printf("This program inputs data from CH-0 to CH-%d of PCI-9116 in %d Hz by\ndouble-buffer mode, and store data to file '%s'. The size of circular\nbuffer is %ld. It will not stop until you press a key.\n\n", channel, (int)sample_rate, file_name, read_count); if ((card=Register_Card (PCI_9116, 0)) <0 ) { printf("Register_Card error=%d\n", card); exit(1); } if(!ai_mode) AI_9116_Config(card,0,P9116_AI_DMA|P9116_TRGMOD_DELAY|(dl_mode?P9116_AI_DlyInSamples:P9116_AI_DlyInTimebase),postCount,0,0); else AI_9116_Config(card,0,P9116_AI_INT|P9116_TRGMOD_DELAY|(dl_mode?P9116_AI_DlyInSamples:P9116_AI_DlyInTimebase),postCount,0,0); AI_9116_CounterInterval (card, samp_intrv*(channel+1), samp_intrv); err = AI_AsyncDblBufferMode(card, 1); //double-buffer mode if (err!=0) { printf("AI_DblBufferMode error=%d", err); Release_Card(card); exit(1); } if (( fp = fopen( file_name , "w+b")) == NULL){ Release_Card(card); exit(1); } mem_size=read_count * 2; ai_buf = (U16*)malloc(mem_size); err = AI_ContScanChannels(card, channel, range, ai_buf, read_count/(channel+1), (F64)1, ASYNCH_OP); if (err!=0) { printf("AI_ContScanChannels error=%d", err); free( ai_buf ); exit(1); } clear_op = FALSE; printf("\n\n\n Start Data Conversion by External Trigger Signal and Press any key to stop.\n"); if( pthread_create( &thread1, NULL, ProcessThread, NULL ) != 0 ){ printf(" Can't create thread1 , terminate \n "); Release_Card(card); free( ai_buf ); fclose( fp ); exit(-1); } getch(); clear_op = TRUE; sleep(1); printf("\n\n Press any key to exit the program..... "); getch(); free( ai_buf ); fclose( fp ); return 0; }