📄 thermo.cpp
字号:
/*
****************************************************************************************
* Program : THERMO.CPP *
* Description : Demo program for temperature measurement with expansion board *
* Boards Supp. : PCL-818 series/816/1800/812PG/711B, PCM-3718 *
* PCI-1710/1713, PCL-813B, Demo board, *
* ADAM-4011/4011D/4018/4018M/5018 *
* APIs used : DRV_DeviceOpen,DRV_DeviceClose, DRV_TCMuxRead *
* DRV_GetErrorMessage *
* Revision : 1.00 *
* Date : 7/8/1999 Advantech Co., Ltd. *
****************************************************************************************
*/
#include <windows.h>
#include <windef.h>
#include <stdio.h>
#include <conio.h>
#include "..\..\..\include\driver.h"
#define MAXAICHL 8 //for usb-4718 only, if apply this constant
//to the other device, please refer to
//the hardware and software manual for the
//maximum channel number
/******************************
* Local function declaration *
******************************/
void ErrorHandler(DWORD dwErrCde);
void ErrorStop(long*, DWORD);
void main()
{
DWORD dwErrCde;
ULONG lDevNum;
long lDriverHandle;
USHORT usExpChan;
USHORT usChan;
USHORT usDasGan;
ULONG ulProperty[MAXAICHL];
ULONG ulLength;
BOOL BTSupportOrNot;
int InputChar;
int i;
float fTemp;
int usTcType;
PT_TCMuxRead tTCMuxRead;
//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);
//Step 3: Open device
dwErrCde = DRV_DeviceOpen(lDevNum, &lDriverHandle);
if (dwErrCde != SUCCESS)
{
ErrorHandler(dwErrCde);
printf("Program terminated!\n");
printf("Press any key to exit....");
getch();
exit(1);
}
//Step 4: Get the feature of device
PT_DeviceGetFeatures ptDeviceGetFeatures;
DEVFEATURES DeviceFeatures;
ptDeviceGetFeatures.buffer = &DeviceFeatures;
ptDeviceGetFeatures.size = sizeof(DEVFEATURES);
dwErrCde = DRV_DeviceGetFeatures(lDriverHandle,&ptDeviceGetFeatures);
if (dwErrCde != SUCCESS)
{
ErrorStop(&lDriverHandle, dwErrCde);
return;
}
printf("Input Channel on expansion board: ");
scanf("%d", &usExpChan);
printf("Input Channel on board: ");
scanf("%d", &usChan);
printf("Gain List:\n");
for(i=0;i<DeviceFeatures.usNumGain;i++)
printf("Gain Code: %2.2d Gain:%s\n",
DeviceFeatures.glGainList[i].usGainCde,DeviceFeatures.glGainList[i].szGainStr);
printf("Input Gain Code: ");
scanf("%d", &usDasGan);
printf("Thermocouple type (J:0, K:1, S:2, T:3, B:4, R:5, E:6): ");
scanf("%d", &usTcType);
BTSupportOrNot = FALSE;
ulLength = sizeof(ulProperty);
dwErrCde = DRV_DeviceGetProperty(lDriverHandle, CFG_BURNTEST, ulProperty, &ulLength);
if (dwErrCde == InvalidInputParam) {
dwErrCde = DRV_DeviceGetProperty(lDriverHandle, CFG_BURNTEST, ulProperty, &ulLength);
}
if (dwErrCde == SUCCESS) {
BTSupportOrNot = TRUE;
printf("Select burn out action:");
printf("0: Disable\n 1: 888888\n 2: -888888\n 3: Maximum value\n 4: Minimum value\n");
fflush(stdin);
scanf("%d", &InputChar);
}else if (dwErrCde != FunctionNotSupported) {
ErrorStop(&lDriverHandle, dwErrCde);
return;
}
if(BTSupportOrNot){
ulLength = sizeof(ulProperty);
ulProperty[usChan] = InputChar;
dwErrCde = DRV_DeviceSetProperty(lDriverHandle, CFG_BURNTEST, ulProperty, ulLength);
if (dwErrCde) {
ErrorStop(&lDriverHandle, dwErrCde);
return;
}
}
printf("\n");
// Step 5: Read one data
tTCMuxRead.DasChan = usChan; // input das channel = 0
tTCMuxRead.DasGain = usDasGan; // input gain code
tTCMuxRead.ExpChan = usExpChan; // input channel on expansion board
tTCMuxRead.TCType = usTcType; // J:0, K:1, S:2, T:3, B:4, R:5, E:6
tTCMuxRead.TempScale = 0; // Celsius:0, Fahrenheit:1, Rankine:2, Kelvin:3
tTCMuxRead.temp = &fTemp; // data pointer
dwErrCde = DRV_TCMuxRead(lDriverHandle, &tTCMuxRead);
if (dwErrCde != SUCCESS)
{
ErrorStop(&lDriverHandle, dwErrCde);
return;
}
// Step 6: Display reading data
printf("Reading data (scale: Celsius) %10.6f\n", fTemp);
// Step 7: Close device
dwErrCde = DRV_DeviceClose(&lDriverHandle);
printf("\nPress any key to exit....");
getch();
}//main
/**********************************************************************
* 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 + -