Exemple #1
0
int main( void )
{
    I16 err;
    int i;

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

    if (read_count <= postCount) {
        printf("Buffer Size have to be larger than %ld\n", postCount+2);
        Release_Card(card);
        exit(1);
    }

    err=AI_9118_Config(card,P9118_AI_BiPolar|P9118_AI_SingEnded,P9118_AI_DtrgPositive|P9118_AI_EtrgPositive|P9118_AI_PostTrgEn,0,postCount);
    if( err != NoError) {
        printf("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 = (U16*)malloc(mem_size);

    for (i=0;i<read_count;i++)
        ai_buf[i]=0xffff;
    fstop =0;

    err=AI_ContReadChannel(card, channel, AD_B_5_V, ai_buf, read_count, sample_rate, ASYNCH_OP);
    if( err != NoError) {
        printf("AI_ContReadPort Error = %d\n", err);
        Release_Card(card);
        free( ai_buf );
        fclose( fp );
        exit(1);
    }

    do {
        AI_AsyncCheck(card, &fstop, &count);
    }while (!fstop);
    AI_AsyncClear(card, &count);

    ProcessData();
    show_channel_data();
    printf(" the data is saved into %s\n", file_name );
    fclose( fp );
    free( ai_buf );

    return 5;
}
Exemple #2
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;
}
Exemple #3
0
int main(int argc, char **argv)
{
    I16 card, err;
    U16 card_num;
    U32 DO_Write = 0xffff;
    U32 DO_Read, DI_Read;

    printf("This sample write digital data to DO port and read digital value from DI port.\n");
    printf("Card Number? ");
    scanf(" %hd", &card_num);

    card = Register_Card(PCI_9223, card_num);
    if(card<0){
        printf("Register_Card Error: %d\n", card);
        exit(1);
    }

    do{
        /*Write DO port*/
        err = DO_WritePort(card, 0, DO_Write);
        if(err<0){
            printf("DO_WritePort Error: %d\n", err);
            Release_Card(card);
            exit(1);
        }
        /*Read the written data from DO port*/
        err = DO_ReadPort(card, 0, &DO_Read);
        if(err<0){
            printf("DO_ReadPort Error: %d\n", err);
            Release_Card(card);
            exit(1);
        }
        /*Read DI Port*/
        err = DI_ReadPort(card, 0, &DI_Read);
        if(err<0){
            printf("DI_ReadPort Error: %d\n", err);
            Release_Card(card);
            exit(1);
        }
        clrscr();
        printf("/*--------------------------------*/\n");
        printf("  DO Read Data : %#x\n", DO_Read);
        printf("  DI Read Data : %#x\n", DI_Read);
        printf("\n\tPress Enter to exit...\n");
        printf("/*--------------------------------*/\n");

        DO_Write = (DO_Write==0)? 0xffff: (DO_Write-1);
        usleep(100000);
    }while(!kbhit());

    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-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;
}
Exemple #5
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;
}
Exemple #6
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);
}
Exemple #7
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;
}
Exemple #8
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;
}
Exemple #9
0
int main( void )
{
    I16 card;
    U32 input=0, output_value=0;

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

    printf("\n Press Enter for Exit \n");

    do{
        clrscr();
        printf("*****************************************************************\n" );
        printf("                      PCI9111 IO Polling                         \n");
        printf("*****************************************************************\n\n");
        printf("                                                                 \n\n\n\n");
        DO_WritePort(card,0, output_value);
        printf("        Value write to OUTPUT PORT : %02x                        \n\n", (U16)output_value);
        DI_ReadPort(card,0,&input);
        printf("        Value read from INPUT PORT : %02x                        \n\n\n\n\n\n\n", (U16)input );
        printf("                                        press Enter to stop      \n\n\n");

        usleep( 10000 );
        if( output_value == 0xff )
            output_value = 0;
        else
            output_value ++;
    }while( !kbhit() );

    Release_Card( card );
    return 0;
}
Exemple #10
0
int main( void )
{
    I16 card=-1, card_number = 0;
    U32 input = 0;

    if ((card=Register_Card(PCI_7433, card_number)) < 0) {
        printf ("Can't open device file: PCI7433\n");
        exit(-1);
    }

    printf ("open device file successfully!!\n");

    do {
        clrscr();
        printf ("PCI-7433 DI Sample :\n\n");
        printf ("The Data from DI are shown in the following table:\n");
        printf ("--------------------------------------------------\n");
        DI_ReadPort(card,  PORT_DI_LOW, &input);
        printf(" DI low port input = 0x%lx\n", input);
        DI_ReadPort(card,  PORT_DI_HIGH, &input);
        printf(" DI high port input = 0x%lx\n", input);
        printf ("--------------------------------------------------\n");
        printf (" Press Enter to stop...\n");
        //usleep(100000);
    }while( !kbhit() );

    if(card>=0) {
        Release_Card(card);
    }
    return 0;
}
Exemple #11
0
void * ProcessThread( void * temp_pt )
{
    BOOLEAN HalfReady;

    U32 count=0, count1;

    fprintf( fp, " ContScanChannels with Double Buffer Transfer \n\n\n");
    fprintf( fp, "CH0   CH1   CH2   CH3 \n======================\n");

    do {
        do {
            AI_AsyncDblBufferHalfReady(card, &HalfReady, &fStop);
            usleep(10);
        } while (!HalfReady);
        if( !clear_op ){
            AI_AsyncDblBufferTransfer(card, ai_buf);
            count += (read_count / 2);
            write_to_file( ai_buf, channel+1 );
        }
    } while( !clear_op );

    fclose( fp );

    printf(" Data conversion stop\n");
    printf(" %li input data are stored in file '%s'.\n\n\n\n", count, file_name);

    AI_AsyncClear(card, &count1);
    Release_Card(card);

    return NULL;
}
Exemple #12
0
int main( void )
{
    I16 card = -1, card_number = 0;
    U32 input, out_value = 0;

    if((card = Register_Card(PCI_6208V, card_number))<0){
        printf("Can't open device file: PCI6208V\n");
        exit(-1);
    }

    do{
        clrscr();
        printf("PCI-6208V DIO Sample :\n");
        printf("\nThe Data to/from DO/DI are shown in the following table:\n");
        printf("--------------------------------------------------------\n");
        DO_WritePort(card, 0, out_value);
        printf(" DO port output = 0x%x\n", (U16)(out_value&0x0f));
        usleep(100);
        DI_ReadPort(card,  0, &input);
        printf(" DI port input = 0x%x\n", (U16)(input&0x0f));
        printf("--------------------------------------------------------\n");
        //if(stop_flag) break;
        printf(" Press Enter to stop...\n");
        //usleep(100000);
        out_value = (out_value+1)%16;
    }while(!kbhit());

    if(card>=0){
        Release_Card(card);
    }
    return 0;
}
Exemple #13
0
int main(void)
{
    I16 card = -1, card_number = 0;
    U32 out_value = 1;

    if((card = Register_Card(PCI_7234, card_number))<0){
        printf("Can't open device file: PCI7234\n");
        exit(-1);
    }

    printf("open device file successfully!!\n");

    do{
        clrscr();
        printf("PCI-7234 DO Sample :\n");
        printf("\nThe Data to DO are shown in the following table:\n\n");
        printf("-------------------------------------------------\n");
        DO_WritePort(card, 0, out_value);
        printf(" Do port output = 0x%lx\n", (out_value));
        printf("-------------------------------------------------\n");
        printf(" Press Enter to stop...\n");
        //usleep(100000);
        out_value = (out_value*2)%((1<<31)+1);
        if(!out_value)
            out_value = 1;
    }while(!kbhit());

    if(card>=0){
        Release_Card(card);
    }
    return 0;
}
Exemple #14
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;
}
Exemple #15
0
void main(void)
{

	I16 card, err, card_num=0;
	U8 status;
	U32 DO_RB_Data;

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

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

/*	err = DO_ReadPort(card, P7444_CH0, &DO_RB_Data);
	printf("err: %d, DO CH0 ReadBack: %x\n", err, DO_RB_Data);	
	err = DO_ReadPort(card, P7444_CH1, &DO_RB_Data);
	printf("err: %d, DO CH1 ReadBack: %x\n", err, DO_RB_Data);	
	err = DO_ReadPort(card, P7444_CH2, &DO_RB_Data);
	printf("err: %d, DO CH2 ReadBack: %x\n", err, DO_RB_Data);	
	err = DO_ReadPort(card, P7444_CH3, &DO_RB_Data);
	printf("err: %d, DO CH3 ReadBack: %x\n", err, DO_RB_Data);

	err = HotResetHoldControl(card, HRH_OFF);
	if(err < 0){
		printf("HotResetHoldControl Error: %d\n", err);
		exit(1);
	}
	err = HotResetHoldStatus(card, &status);
	if(err < 0){
		printf("HotResetHoldControl Error: %d\n", err);
		exit(1);
	}

	err = DO_WritePort(card, P7444_CH0, 0xff);
	//printf("err: %d, DO CH0 : %x\n", err, DO_RB_Data);	
	err = DO_WritePort(card, P7444_CH1, 0xffff);
	//printf("err: %d, DO CH1 ReadBack: %x\n", err, DO_RB_Data);	
	err = DO_WritePort(card, P7444_CH2, 0xffffff);
	//printf("err: %d, DO CH2 ReadBack: %x\n", err, DO_RB_Data);	
	err = DO_WritePort(card, P7444_CH3, 0xffffffff);
	//printf("err: %d, DO CH3 ReadBack: %x\n", err, DO_RB_Data);
*/
	{
		U32 BaseAddr, BaseAddr2, LcrAddr;
		U16 cardType;

		err = GetBaseAddr(card, &BaseAddr, &BaseAddr2);
		printf("BaseAddr: %x, BaseAddr2: %x\n", BaseAddr, BaseAddr2);
		err = GetLCRAddr(card, &LcrAddr);
		printf("LcrAddr: %x\n", LcrAddr);
		err = GetCardType(card, &cardType);
		printf("cardType: %d\n", cardType);
	}
	Release_Card(card);
}
Exemple #16
0
int main(void)
{
    I16 err;
    int card_number = 0;
    U32 input = 0, out_value = 1, pattern = 0;
    F32 rt = 0.0;

    printf(" Please input the Card_Index for PCI7260 :");
    scanf(" %d", &card_number ); getchar();

    if((card = Register_Card(PCI_7260, (I16)card_number))<0){
        printf ("Can't open device file: PCI7260 %d\n", card);
        exit(-1);
    }
    printf("open device file successfully!!\n");
    err = IdentifyLED_Control (card, 1);
    GetInitPattern(card, INIT_PTN, &pattern);
    printf("Init Pattern: %x\n", pattern);
    DO_WritePort(card, 0, pattern);
    GetInitPattern(card, EMGSHDN_PTN, &pattern);
    printf("EMG Shutdown Pattern: %x\n", pattern);

    err = WDT_Setup(card, 0, 5.0, &rt, wdt_sig_handler);
    if(err!=NoError){
        printf("WDT_Setup err %d!", err);
        Release_Card(card);
        exit(1);
    }
    err = WDT_Control(card, 0, WDT_ARM);
    if(err!=NoError){
        printf("WDT_Control err %d!", err);
        Release_Card(card);
        exit(1);
    }
    printf("\nWDT will overflow after %.4f seconds ...\n", rt);
    getch();
    WDT_Control(card, 0, WDT_DISARM);
    IdentifyLED_Control(card, 0);

    if(card>=0){
        Release_Card(card);
    }
    return 0;
}
Exemple #17
0
int main(void)
{
    int  err;
    char temp_char;

    setbuf( stdout, NULL );
    printf("\nPCI-7443 Dual Interrupt Sample\n" );
    printf("\nThis program shows the number of occurrence of interrupt\n" );
    printf("for COS0, COS1, COS2 and COS3 interrupt lines.\n" );

    printf("\nPlease input a card number: ");
    scanf(" %hd", &card_number);

    if((card=Register_Card(PCI_7443, card_number))<0){
        printf("Register_Card Error = %d\n", card);
        exit(0);
    }

    usleep(1000);

    err = DIO_SetCOSInterrupt32(card, P7443_CH0, 0x1, sig1_handler);
    if(err!=NoError){
        printf(" error from DIO_SetCOSInterrupt32 : %d \n" , err );
        goto exit_after_error;
    }
    err = DIO_SetCOSInterrupt32(card, P7443_CH1, 0x1, sig2_handler);
    if(err!=NoError){
        printf(" error from DIO_SetCOSInterrupt32 : %d \n" , err );
        goto exit_after_error;
    }

    err = DIO_SetCOSInterrupt32(card, P7443_CH2, 0x1, sig3_handler);
    if(err!=NoError){
        printf(" error from DIO_SetCOSInterrupt32 : %d \n" , err );
        goto exit_after_error;
    }

    err = DIO_SetCOSInterrupt32(card, P7443_CH3, 0x1, sig4_handler);
    if(err!=NoError){
        printf(" error from DIO_SetCOSInterrupt32 : %d \n" , err );
        goto exit_after_error;
    }

    printf("\nPress any key to exit...\n" );
    temp_char = getch();

    DIO_SetCOSInterrupt32(card, P7443_CH0, 0, /*sig1_handler*/NULL);
    DIO_SetCOSInterrupt32(card, P7443_CH1, 0, /*sig2_handler*/NULL);
    DIO_SetCOSInterrupt32(card, P7443_CH2, 0, /*sig2_handler*/NULL);
    DIO_SetCOSInterrupt32(card, P7443_CH3, 0, /*sig3_handler*/NULL);

exit_after_error:
    if(card>=0)
        Release_Card(card);
    exit(0);
}
Exemple #18
0
void main(void)
{
    I16 card, err, card_num=0;
    U16 in_value, out_value = 0;

    printf("This program output data from TTL0 to TTL1.\n");
    printf("Please input a card number: ");
    scanf(" %hd", &card_num);

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

    err = DIO_PortConfig(card, P7444_TTL0, OUTPUT_PORT);
    if(err!=NoError) {
        printf("Input Port Config Error: %d\n",err);
        exit(1);
    }

    err = DIO_PortConfig(card, P7444_TTL1, INPUT_PORT);
    if(err!=NoError) {
        printf("Output Port Config Error: %d\n",err);
        exit(1);
    }

    do{
        clrscr();
        printf ("-------------------------------------------------\n");

        err = DO_WritePort(card, P7444_TTL0, out_value);
        if (err!=NoError) {
            printf("DO_WritePort error=%d", err);
            exit(1);
        }
        printf(" TTL0 output = 0x%x\n", out_value);

        err = DI_ReadPort(card, P7444_TTL1, &in_value);
        if (err!=NoError) {
            printf("DI_ReadPort error=%d", err);
            exit(1);
        }
        printf(" TTL1 input = 0x%x\n", in_value);

        printf ("-------------------------------------------------\n");
        printf ("\n Press Enter to stop...\n");

        usleep(200000);
        if(out_value < 0xffff)
            out_value = (out_value + 1);
        else
            out_value = 0;
    } while(!kbhit());

    Release_Card(card);
}
Exemple #19
0
int main( void )
{
    I16 card = -1, card_number = 0;
    U32 input, out_value = 0;

    if((card = Register_Card(PCI_7248, card_number))<0) {
        printf ("Can't open device file: PCI7248\n");
        exit(-1);
    }
    printf("open device file successfully!!\n");

    DIO_PortConfig(card,Channel_P1A, INPUT_PORT);
    DIO_PortConfig(card,Channel_P2A, OUTPUT_PORT);
    DIO_PortConfig(card,Channel_P1B, INPUT_PORT);
    DIO_PortConfig(card,Channel_P2B, OUTPUT_PORT);
    DIO_PortConfig(card,Channel_P1C, INPUT_PORT);
    DIO_PortConfig(card,Channel_P2C, OUTPUT_PORT);
    clrscr();
    printf("PCI-7248 DIO Sample :\n\n");
    printf("-------------------------------------------------\n");
    printf(" P1A, p1B, P1C are configured as input port.\n");
    printf(" P2A, p2B, P2C are configured as output port.\n");
    printf("-------------------------------------------------\n");
    printf(" Press any key to continue...\n");
    getch();

    do {
        clrscr();
        printf ("PCI-7248 DIO Sample :\n\n");
        printf ("-------------------------------------------------\n");
        printf (" P1A, p1B, P1C are configured as input port.\n");
        printf (" P2A, p2B, P2C are configured as output port.\n\n");
        DO_WritePort(card, Channel_P2A, out_value);
        printf(" P2A output = 0x%x\n", (U16)out_value);
        DI_ReadPort(card,  Channel_P1A, &input);
        printf(" P1A input = 0x%x\n", (U16)input);
        DO_WritePort(card, Channel_P2B, out_value);
        printf(" P2B output = 0x%x\n", (U16)out_value);
        DI_ReadPort(card,  Channel_P1B, &input);
        printf(" P1B input = 0x%x\n", (U16)input);
        DO_WritePort(card, Channel_P2C, out_value);
        printf(" P2C output = 0x%x\n", (U16)out_value);
        DI_ReadPort(card,  Channel_P1C, &input);
        printf(" P1C input = 0x%x\n", (U16)input);
        printf ("-------------------------------------------------\n");
        printf (" Press ENTER to stop...\n");
        //usleep(100000);
        out_value = (out_value+1)%256;
    } while(!kbhit());

    if(card>=0) {
        Release_Card(card);
    }
    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;
}
Exemple #21
0
int main(int argc, char **argv)
{
    I16 card, err;
    U16 card_num;

    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);
    }	

    printf("---------- EEPROM_DEFAULT_BANK -------------\n");
    err = PCI_Load_CAL_Data((U16)card, EEPROM_DEFAULT_BANK);
    if(err<0){
        printf("PCI_Load_CAL_Data Error: %d\n", err);
        Release_Card(card);
        exit(1);
    }

    printf("---------- EEPROM_USER_BANK1 -------------\n");
    err = PCI_Load_CAL_Data((U16)card, EEPROM_USER_BANK1);
    if(err<0){
        printf("PCI_Load_CAL_Data Error: %d\n", err);
        Release_Card(card);
        exit(1);
    }

	printf("---------- AUTO K -------------\n");
    err = PCI_DB_Auto_Calibration_ALL((U16)card);
    if(err<0){
        printf("PCI_DB_Auto_Calibration_ALL Error: %d\n", err);
        Release_Card(card);
        exit(1);
    }

	printf("---------- Write Constant to EEPROM -------------\n");
    err = PCI_EEPROM_CAL_Constant_Update((U16)card, EEPROM_USER_BANK1);
    if(err<0){
        printf("PCI_EEPROM_CAL_Constant_Update Error: %d\n", err);
        Release_Card(card);
        exit(1);
    }

    printf("---------- EEPROM_USER_BANK1 -------------\n");
    err = PCI_Load_CAL_Data((U16)card, EEPROM_USER_BANK1);
    if(err<0){
        printf("PCI_Load_CAL_Data Error: %d\n", err);
        Release_Card(card);
        exit(1);
    }

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

    return 0;
}
Exemple #22
0
int main(void)
{
    int  err;
    char temp_char;

    setbuf( stdout, NULL );

    printf("PCI-7396 Interrupt Sample (INT1)\n" );
    printf("This program shows the number of occurrence\n");
    printf("of COS INT1 interupt. COS INT1 interrupt is\n");
    printf("generated by external signal from DI Port 1.\n");
    printf("If you connect CN1 to CN2, press any key can generate an interrupt.\n");
    printf("Or press ESC for exit\n\n" );

    int_count=0;

    if ((card=Register_Card(PCI_7396, card_number)) < 0) {
        printf("Register_Card Error = %d\n", card);
        exit(0);
    }

    if( DIO_PortConfig(card,Channel_P1, INPUT_PORT) != NoError )
        goto exit_after_error;
    if( DIO_PortConfig(card,Channel_P2, OUTPUT_PORT) != NoError )
        goto exit_after_error;

    //DIO_SetCOSInterrupt(card, Channel_P1, 1, 1, 1);
    err = DIO_SetDualInterrupt(card, INT1_FP1C0, INT2_DISABLE, sig1_handler, NULL);
    if( err != NoError ){
        printf(" error from DIO_SetDualInterrupt : %d \n" , err );
        goto exit_after_error;
    }

    while(1){
        temp_char = getch();
        if( temp_char == 0x1b )
            break;

        DO_WritePort(card,Channel_P2C, 0x1);
        usleep(1000);
        DO_WritePort(card,Channel_P2C, 0x0);
        usleep(1000);
    }

    DIO_SetDualInterrupt(card, INT1_DISABLE, INT2_DISABLE, NULL, NULL);

exit_after_error:
    if (card >= 0)
        Release_Card(card);
    exit(0);
}
Exemple #23
0
int main(int argc, char **argv)
{
    I16 card, err;
    U16 card_num;
    U16 Channel = 0;
    U16 AdRange = AD_B_5_V; // -5V ~ +5V
    U16 acq_value;
    F64 v_acq_value;

    printf("This sample reads analog data from AI channel 0\n\n");
    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);
    }

    do{
        clrscr();
        usleep(100000);
        //err = AI_ReadChannel(card, Channel, AdRange, &acq_value);
        err = AI_VReadChannel(card, Channel, AdRange, &v_acq_value);
        if(err<0){
            printf("AI Read Ch0 Error: %d\n", err);
            Release_Card(card);
            exit(1);
        }
        //printf("\nAI CH0 Raw Data: 0x%x\n", acq_value);
        printf("\nAI CH0 Voltage Value: %f\n", (F32)v_acq_value);
        printf("\n\n     Press Enter to exit...\n");
    }while(!kbhit());

    Release_Card(card);
    return 0;
}
Exemple #24
0
int main( void )
{
    int card_number = 0;
    U32 input = 0, out_value = 1, pattern=0;
    F32 rt = 0.0;
    U8 sts = 0;

    printf("Please input the Card_Index for PCI7452 :");
    scanf("%d", &card_number ); getchar();

    if ((card=Register_Card(PCI_7452, (I16)card_number)) < 0) {
        printf ("Can't open device file: PCI7452 %d\n", card);
        exit(-1);
    }

    err = WDT_Setup (card, 0, 5.0, &rt, wdt_sig_handler);
    if(err != NoError) {
        printf("WDT_Setup err %d!", err);
        Release_Card(card);
        exit(1);
    }
    err = WDT_Control (card, 0, WDT_ARM);
    if(err != NoError) {
        printf("WDT_Control err %d!", err);
        Release_Card(card);
        exit(1);
    }
    printf("\n\nWDT will overflow after %.4f seconds ...\n", rt);
    getch();
    WDT_Control (card, 0, WDT_DISARM);

    if(card>=0) {
        Release_Card(card);
    }
    return 0;
}
Exemple #25
0
int main(int argc, char **argv)
{
    I16 card, err;
    U16 card_num;
    U16 acq_ch[ChNum];
    U16 acq_gain[ChNum];
    U16 acq_value[ChNum];
    F64 voltage=0.0;
    int i;
    int j=0;

    for(i=0; i< ChNum; i++){
        acq_ch[i]=i;
        acq_gain[i]=AD_B_5_V;
    }  
    fout = fopen("acq.txt", "w");
    
    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);
    }

    do{
        clrscr();
        err = AI_ReadMultiChannels(card, ChNum, acq_ch, acq_gain, acq_value);
        if(err < 0){
            printf("AI Read Multi Channel Error: %d\n", err);  
           exit(1);
        }
	for(i=0; i<ChNum; i++){
	    AI_VoltScale(card, acq_gain[i], acq_value[i], &voltage);
            fprintf(fout, "%f\t", voltage);
	}
        fprintf(fout, "\n");
        printf("Loop %d\n", j++);
    }while(!kb_hit());
    
    err = Release_Card(card);
    if(err < 0){
        printf("Release_Card error=%d", err);
        exit(1);
    }

    return 0;
}
Exemple #26
0
int main(void)
{
    I16 card = -1, card_number = 0;
    int ch;
    F64 out_value;
    char c;

    setbuf(stdout, NULL);

    if((card = Register_Card(PCI_6202, card_number))<0){
        printf ("Can't open device file: PCI6202\n");
        exit(-1);
    }

    while(1){
        clrscr();
        printf("PCI-6202 AO Sample :\n\n");
        printf("-------------------------------------------------\n");
        printf("Please type the channel number [0-3]: ");
        scanf(" %d", &ch);
        if((ch<0)||(ch>3)){
            printf("The channel number is invalid\n");
            goto endwhile;
        }
        printf("Please specify a voltage to output (-10V~10V): ");
        scanf(" %lf", &out_value);
        if((out_value<-10)||(out_value>10)){
            printf("The voltage value is invalid\n");
            goto endwhile;
        }
        printf("The output value is %lf .\n", out_value);
        AO_VWriteChannel(card, ch, out_value);
        printf ("-------------------------------------------------\n");
endwhile:
        printf ("[q]Quit [c]Continue ? ");
        //scanf(" %c", &c);
        c = getch();
        if((c=='q')||(c=='Q'))
            break;
    }
    putchar('\n');

    if(card>=0){
        Release_Card(card);
    }
    return 0;
}
Exemple #27
0
int main(void)
{
    int  err;
    char temp_char;

    setbuf( stdout, NULL );
    printf("PCI-7432 Dual Interrupt Sample\n" );
    printf("This program shows the number of occurrence of interrupt\n" );
    printf("for Dual interrupt lines.\n" );
    printf("INT1 interrupt is generated by external signal from DI bit-0.\n");
    printf("INT2 interrupt is generated by external signal from DI bit-1.\n");
    printf("If you connect DO bit-0 to DI bit-0 and DO bit-1 to DI bit-1,\n");
    printf("press any key can generate two interrupts.\n");
    printf("One for INT1 and the other for INT2.\n");
    printf("Or press ESC for exit\n\n" );

    int_count = int2_count=0;
    if ((card=Register_Card(PCI_7432, card_number)) < 0) {
        printf("Register_Card Error = %d\n", card);
        exit(0);
    }

    err = DIO_SetDualInterrupt(card, INT1_EXT_SIGNAL, INT2_EXT_SIGNAL, sig1_handler, sig2_handler);

    if( err != NoError ){
        printf(" error from DIO_SetDualInterrupt : %d \n" , err );
        goto exit_after_error;
    }

    while(1){
        temp_char = getch();
        if( temp_char == 0x1b )
            break;

        DO_WritePort(card,0, 0x3);
        usleep(1000);
        DO_WritePort(card,0, 0x0);
    }

    DIO_SetDualInterrupt(card, INT1_DISABLE, INT2_DISABLE, NULL, NULL);

exit_after_error:
    if (card >= 0)
        Release_Card(card);
    exit(0);
}
Exemple #28
0
int main(void)
{
    int  err;
    char temp_char;
    int  card_number = 0;

    setbuf(stdout, NULL);
    printf(" Please input the Card Index: ");
    scanf(" %d", &card_number);

    system("clear");
    printf("PCI-7258 Interrupt Sample (INT1)\n\n");
    printf("This program shows the number of occurrence of INT1 interupt.\n");
    printf("INT1 interrupt is generated by external signal from DI bit-0/bit-1.\n");
    printf("Press ESC for exit\n\n");

    int_count = 0;

    if((card = Register_Card(PCI_7258, (I16)card_number))<0){
        printf ("Can't open device file: PCI7258\n");
        exit(-1);
    }
    DO_WritePort(card,0, out_Val);
    err = DIO_SetDualInterrupt(card, INT1_EXT_SIGNAL, INT2_DISABLE, sig1_handler, NULL );
    if(err!=NoError){
        printf(" error from DIO_SetDualInterrupt : %d \n" , err );
        goto exit_after_error;
    }

    while(1){
        temp_char = getch();
        if(temp_char==0x1b)
            break;
        DO_WritePort(card, 0, 0x0);
        sleep(0);
        DO_WritePort(card, 0, 0x1);
    }

    DIO_SetDualInterrupt(card, INT1_DISABLE, INT2_DISABLE, NULL, NULL);
    DO_WritePort(card, 0, 0x0);

exit_after_error:
    if(card>=0)
        Release_Card(card);
    exit(0);
}
Exemple #29
0
int main( void )
{
    I16 card = -1, card_number = 0, i;
    U32 input = 0, out_value = 1;

    if((card = Register_Card(PCI_7250, card_number))<0){
        printf("Can't open device file: PCI7250\n");
        exit(-1);
    }
    printf("open device file successfully!!\n");

    do{
        clrscr();
        printf("PCI-7250 DIO Sample :\n");
        printf("\nThe Data to/from DO/DI are shown in the following table:\n");
        printf("--------------------------------------------------------\n");
        printf(" PCI-7250   : ");
        DO_WritePort(card, 0, out_value);
        printf("Do port output = 0x%x\n", (U16)out_value);
        DI_ReadPort(card,  0, &input);
        printf("              DI port input = 0x%x\n", (U16)input);
        for(i=1; i<4; i++){
            printf(" PCI-7251#%d : ", i);
            if(DO_WritePort(card, 0, out_value)==NoError){
                printf("\nDo port output = 0x%x\n", (U16)out_value);
                DI_ReadPort(card,  0, &input);
                printf("\n            DI port input = 0x%x\n", (U16)input);
            }
            else
                printf("None\n");
        }
        printf("--------------------------------------------------------\n");
        printf(" Press Enter to stop...\n");
        //usleep(200000);
        out_value = (out_value<<1)%256;
        if(!out_value)
            out_value = 1;
    }while(!kbhit());

    if(card>=0){
        DO_WritePort(card, 0, 0);
        Release_Card(card);
    }
    return 0;
}
Exemple #30
0
int main(void)
{
    int err;

    setbuf( stdout, NULL );
    printf("PCI-7300A Dual Interrupt Sample\n");

    int_count = int2_count = 0;

    if ((card=Register_Card (PCI_7300A_RevA, 0)) <0 ) {
      printf ("Can't open device file: PCI7300A\n");
      exit(-1);
    }
    CTR_Setup (card, 2, RATE_GENERATOR, 0, BIN);
    usleep(1000);

    err = DIO_7300SetInterrupt(card, 1, 1, sig_handler1, sig_handler2);
    if( err != NoError ){
       printf(" error from DIO_SetDualInterrupt : %d \n" , err );
       goto exit_after_error;
    }
    // setup the Timer clock
    c2=10000000/(sample_rate);
    err = CTR_Setup (card, 2, 2, c2, BIN);
    if( err != NoError ){
       printf(" error from CTR_Setup : %d \n" , err );
       goto end_of_proc;
    }
    printf("**The INT2 Singal will be sent back in 4 secs, or you can press ENTER for exit**\n");
    getchar();

    if( int2_count < total_count ){
       CTR_Setup (card, 2, RATE_GENERATOR, 0, BIN);
       goto end_of_proc;
    }

end_of_proc:
    DIO_7300SetInterrupt(card, 0, 0, NULL, NULL);
exit_after_error:
    if (card >= 0) Release_Card(card);
    exit(0);
}