Exemplo n.º 1
0
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;
}
Exemplo n.º 3
0
int main(void)
{
    I16 err;
    int ai_mode;

    setbuf( stdout, NULL );
    printf("Please select the AI type (0:DMA  1:INT): ");
    scanf(" %d", &ai_mode);
    if ( (card = Register_Card(PCI_9116, 0)) < 0) {
        printf("Register_Card error=%d", card);
        exit(1);
    }
    if(!ai_mode)
        AI_9116_Config(card,0,P9116_AI_DMA|P9116_TRGMOD_POST,0,0,0);
    else
        AI_9116_Config(card,0,P9116_AI_INT|P9116_TRGMOD_POST,0,0,0);

    AI_9116_CounterInterval (card, samp_intrv*(channel+1), samp_intrv);

    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/(channel+1), (F64)1, ASYNCH_OP);
    if( err != NoError) {
        printf(" 9116 : AI_ContReadPort Error = %d\n", err);
        Release_Card(card);
        free( ai_buf );
        fclose( fp );
        exit(1);
    }

    printf(" ContScanChannels with Post Trigger operation \n");
    printf(" Start the Data consversion with the External Trigger signal \n" );

    fstop = 0;
    do{
        AI_AsyncCheck(card, &fstop, &count);
    }while (!fstop);
    AI_AsyncClear(card, &count); // stop data aquisition & memory copy

    ProcessData();
    show_channel_data();
    free( ai_buf );
    printf(" the data is saved into %s\n", file_name );
    return 0;
}
Exemplo n.º 4
0
int main(void)
{
    I16 err;

    setbuf( stdout, NULL );
    if ( (card = Register_Card(PCI_9812, 0)) < 0) {
        printf("Register_Card error=%d", card);
        exit(1);
    }

    err = AI_9812_Config(card,P9812_TRGMOD_PRE, P9812_TRGSRC_EXT_DIG, P9812_TRGSLP_POS, P9812_AD2_GT_PCI|P9812_CLKSRC_INT,0,0x1);
    if( err != NoError){
        printf("9812 : AI_Config Error = %d\n", 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 != NoError) {
        printf(" 9118 : AI_ContReadPort Error = %d\n", err);
        Release_Card(card);
        free( ai_buf );
        fclose( fp );
        exit(1);
    }

    printf( "ContScanChannels with Pre-Trigger operation \n");
    printf(" About the Data consversion with the External Trigger signal \n" );

    fstop = 0;
    do{
        AI_AsyncCheck(card, &fstop, &count);
    }while (!fstop);
    AI_AsyncClear(card, &count); // stop data aquisition & memory copy

    ProcessData();
    show_channel_data();
    free( ai_buf );
    printf(" the data is saved into %s\n", file_name );
    return 0;
}
Exemplo n.º 5
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;
}
Exemplo n.º 6
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;
}
Exemplo n.º 7
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);
}
Exemplo n.º 8
0
int main(int argc, char **argv)
{
    I16 card, err;
    U16 card_num;
    //U16 ConfigCtrl = P9221_AI_Differential|P9221_AI_ExtTimeBase|P9221_TimeBaseSRC_GPI1;
    //U16 TrigCtrl = P9221_TRGMOD_ExtD|P9221_TRGSRC_GPI2;
    U16 ConfigCtrl = P9221_AI_SingEnded;
    U16 TrigCtrl = P9221_TRGMOD_SOFT;
    BOOLEAN AutoResetBuf = TRUE;
    U16 Buffer[ReadCount];
    F64 ScaleBuffer[ReadCount];
    U16 AdRange = AD_B_5_V;
    U16 BufferId;
    F64 voltage = 0.0;
    FILE* fout;
    int i, j;

    if(!(fout=fopen("acq_data","w"))) {
        printf("fopen Failed\n");
    }
    memset(Buffer, '\0', ReadCount*2);
    memset(ScaleBuffer, '\0', ReadCount*8);

    printf("Please input a card number: ");
    scanf(" %hd", &card_num);

    if((card=Register_Card(PCI_9221, card_num)) < 0) {
        printf("Register_Card error=%d", card);
        exit(1);
    }

    err = AI_SetTimeOut(card, 1000);
    if(err < 0) {
        printf("AI_SetTimeOut error: %d\n", err);
        Release_Card(card);
        exit(1);
    }

    err = AI_9221_CounterInterval(card, ScanIntrv, SampIntrv);
    if(err < 0) {
        printf("AI_9221_CounterInterval error: %d\n", err);
        Release_Card(card);
        exit(1);
    }

    err = AI_9221_Config(card, ConfigCtrl, TrigCtrl, AutoResetBuf);
    if(err < 0) {
        printf("AI_9221_Config error: %d\n", err);
        Release_Card(card);
        exit(1);
    }

    //printf("[APP] Virtual Address of Setup Buffer :0x%x\n", Buffer);
    err = AI_ContBufferSetup(card, Buffer, ReadCount, &BufferId);
    if(err < 0) {
        printf("AI_ContBufferSetup error: %d\n", err);
        Release_Card(card);
        exit(1);
    }

    err = AI_ContScanChannels(card, Channel, AdRange, &BufferId, ReadCount, 0, SYNCH_OP);
    if(err < 0) {
        printf("AI count Scan Channels error\n");
        Release_Card(card);
        exit(1);
    }

    err = AI_ContBufferReset(card);
    if(err < 0) {
        printf("AI_ContBufferReset error: %d\n", err);
        Release_Card(card);
        exit(1);
    }

    AI_ContVScale(card, AD_B_5_V, Buffer, ScaleBuffer, ReadCount);

    for(i=0; i<(ReadCount/(Channel+1)); i++) {
        for(j=0; j<(Channel+1); j++) {
            //err = AI_VoltScale(card, AdRange, Buffer[i*(Channel+1)+j], &voltage);
            //if(err < 0)
            //    printf("AI_VoltScale Failed\n");
            //fprintf(fout,"%f\t", (float)voltage);
            fprintf(fout, "%f\t", (float)ScaleBuffer[i*(Channel+1)+j]);
        }
        fprintf(fout, "\n");
    }

    fclose(fout);
    Release_Card(card);
    printf("Press any key to exit...\n");
    getch();

    return 0;
}
Exemplo n.º 9
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;
}