⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fout.cpp

📁 16 relay output channels and 16 isolated digital input channels LED indicators to show activated
💻 CPP
字号:
// Fout.cpp : Defines the entry point for the console application.
//
/*
****************************************************************************************
* Program        : Fout.CPP                                                            *
* Description    : Demo program for frequency output function                     *
* Boards Supp.   :                                                                     *
* APIs used      : DRV_DeviceOpen,DRV_DeviceClose, DRV_GetErrorMessage,                *
*                  DRV_FreqOutStart,DRV_FreqReset                                 *
* Revision       : 1.00                                                                *
* Date           : 09/08/03                   Advantech Co., Ltd.                      *
****************************************************************************************
*/
#include <windows.h>
#include <windef.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>

#define WIN_CONSOLE
#include "..\..\..\..\include\driver.h"

/******************************
* Local function declaration *
******************************/
void ErrorHandler(DWORD dwErrCde);
void ErrorStop(long*, DWORD);



void main(int argc, char* argv[])
{
	DWORD  dwErrCde;
    ULONG  lDevNum;
    long   lDriverHandle;
	
    USHORT usPort;    // input port          
	USHORT usFreSrc;
	USHORT usDivider;
	PT_FreqOutStart ptFreqOutStart;
	DEVFEATURES     DevFeatures;    // structure for device features
	PT_DeviceGetFeatures  ptDevGetFeatures;
		
    //Step 1: Display hardware and software settings for running this example
    printf("Before running this example, please\n");
    printf("use the device installation utility to add the device.\n");
	
    //Step 2: Input parameters
    printf("\nPlease input parameters:");
    printf("\nDevice Number (check the device installation utility): ");
    scanf("%d", &lDevNum);
    printf("\nInput Port(0 ~ 1): ");
    scanf("\n%d", &usPort);
	printf("\nPlease input the frequency source:");
	printf("\n 0: External Clock");
	printf("\n 1: 20MHZ");
	printf("\n 2: 10MHZ");
	printf("\n 3: 5MHZ");
	printf("\n 4: 1MHZ");
	printf("\n 5: 100KHZ\n");
	
	scanf("%d", &usFreSrc);
	printf("\nPlease input the Divider(2~65535)");
	scanf("%d", &usDivider);

	//open deivice
	dwErrCde = DRV_DeviceOpen(lDevNum, &lDriverHandle);   
    if (dwErrCde != SUCCESS)
    {
        ErrorHandler(dwErrCde);
        printf("Program terminated!\n");
		
        printf("Press any key to exit....");
        getch();
        exit(1);
    }
	
	ptDevGetFeatures.buffer = (LPDEVFEATURES )&DevFeatures;
    ptDevGetFeatures.size   = sizeof(DEVFEATURES);
    dwErrCde = DRV_DeviceGetFeatures(lDriverHandle, (PT_DeviceGetFeatures*)&ptDevGetFeatures);
    if (dwErrCde != SUCCESS){
		ErrorStop(&lDriverHandle, dwErrCde);
        return;
		
    }

    if (0 == DevFeatures.usMaxTimerChl){
        ErrorStop(&lDriverHandle, dwErrCde);
        return;
		
    }
    //start the frequency output

	switch(usFreSrc){
	case 0: ptFreqOutStart.usFoutSrc = PA_FOUT_SRC_EXTER_CLK; break;
	case 1: ptFreqOutStart.usFoutSrc = PA_FOUT_SRC_CLK_20MHZ;     break;
	case 2: ptFreqOutStart.usFoutSrc = PA_FOUT_SRC_CLK_10MHZ; break;
	case 3: ptFreqOutStart.usFoutSrc = PA_FOUT_SRC_CLK_5MHZ; break;
	case 4: ptFreqOutStart.usFoutSrc = PA_FOUT_SRC_CLK_1MHZ;  break;
	case 5: ptFreqOutStart.usFoutSrc = PA_FOUT_SRC_CLK_100KHZ;break;
    }
	ptFreqOutStart.usChannel = usPort;
    ptFreqOutStart.usDivider = usDivider;
	dwErrCde = DRV_FreqOutStart((LONG)lDriverHandle,(LPT_FreqOutStart)&ptFreqOutStart);
    if (dwErrCde != SUCCESS){
		ErrorStop(&lDriverHandle, dwErrCde);
		return;
	}	   
	printf("\nThe frequency is outputed at port %d", usPort);

	getch();
	
   //stop frequency output
	dwErrCde = DRV_FreqOutReset(lDriverHandle,usPort);
    if(dwErrCde != SUCCESS){
		ErrorStop(&lDriverHandle, dwErrCde);
		return;
	}
	//close the device
	DRV_DeviceClose((LONG far *)&lDriverHandle);
	printf("\nPress any key to exit....");
    getch();
	
	
	return;
}

/**********************************************************************
* Function: ErrorHandler
*           Show the error message for the corresponding error code
* input:    dwErrCde, IN, Error code
* return:   none
**********************************************************************/
void ErrorHandler(DWORD dwErrCde)
{
    char szErrMsg[180];
	
    DRV_GetErrorMessage(dwErrCde, szErrMsg);
    printf("\nError(%d): %s\n", dwErrCde & 0xffff, szErrMsg);
}//ErrorHandler

 /**********************************************************************
 * Function:   ErrorStop
 *             Release all resource and terminate program if error occurs 
 * Paramaters: pDrvHandle, IN/OUT, pointer to Driver handle
 *             dwErrCde, IN, Error code.
 * return:     none             
**********************************************************************/
void ErrorStop(long *pDrvHandle, DWORD dwErrCde)
{
    //Error message 
    ErrorHandler(dwErrCde);
    printf("Program terminated!\n");
    
    //Close device
    DRV_DeviceClose(pDrvHandle);
	
    printf("Press any key to exit....");
    getch();
    exit(1);
}//ErrorStop

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -