?? sys.cpp
字號:
// 本程序演示了DA輸出過程
#include "stdafx.h"
#include "windows.h"
#include "stdio.h"
#include "conio.h"
#include "PCI8613.h" // 驅動程序接口頭件(必須)
#define ESC 27
int SelectOutputRange(void);
int main(int argc, char* argv[])
{
HANDLE hDevice; // 設備對象句柄
DWORD dwErrorCode;
char strErrorMsg[256];
int nDAChannel;
int DeviceLgcID; // 設備號
int OutputRange;
BOOL bRetStatus; // 函數的返回值
ULONG ResetMode;
char Key;
SHORT nDAData;
float Voltage;
DeviceLgcID = 0;
hDevice = PCI8613_CreateDevice(DeviceLgcID); // 創建設備對象
if (hDevice == INVALID_HANDLE_VALUE)
{
dwErrorCode = PCI8613_GetLastErrorEx("PCI8613_CreateDevice", strErrorMsg);
printf("dwErrorCode = %x, %s\n", dwErrorCode, strErrorMsg);
getch();
return 0;
}
OutputRange = SelectOutputRange();
Repeat:
printf("Please Input nDAChannel[0~3]:");
scanf("%d", &nDAChannel);
printf("Please Input Voltage[mV]:");
scanf("%f", &Voltage);
// 將原碼轉換為電壓值
switch (OutputRange)
{
case PCI8613_OUTPUT_0_P5000mV: // 0 - +5V
nDAData = (WORD)(Voltage/(5000.00/4096));
break;
case PCI8613_OUTPUT_0_P10000mV: // 0 - +10V
nDAData = (WORD)(Voltage/(10000.00/4096));
break;
case PCI8613_OUTPUT_N5000_P5000mV: // -5V - +5V
nDAData = (WORD)(Voltage/(10000.00/4096) + 2048);
break;
case PCI8613_OUTPUT_N10000_P10000mV: // -10V - +10V
nDAData = (WORD)(Voltage/(20000.00/4096) + 2048);
break;
default:
break;
}
printf("nDAData = %d\n", nDAData);
bRetStatus = PCI8613_InitDevProDA(hDevice, OutputRange, nDAChannel);
if(!bRetStatus)
{
dwErrorCode = PCI8613_GetLastErrorEx("PCI8613_InitDeviceDA", strErrorMsg);
printf("dwErrorCode = %x, %s\n", dwErrorCode, strErrorMsg);
getch();
goto ExitRead0;
}
ResetMode = PCI8613_RESET_MIDDLE;
PCI8613_DAReset(hDevice, ResetMode);
bRetStatus = PCI8613_WriteDevProDA(hDevice, nDAData, nDAChannel);
if(!bRetStatus)
{
dwErrorCode = PCI8613_GetLastErrorEx("PCI8613_WriteDeviceDA", strErrorMsg);
printf("dwErrorCode = %x, %s\n", dwErrorCode, strErrorMsg);
getch();
goto ExitRead0;
}
printf("Press ESC to quit, other key to continue...\n");
Key = getch();
if (Key != ESC) goto Repeat;
ExitRead0:
PCI8613_ReleaseDevice(hDevice); // 釋放設備對象
return 0;
}
//////////////////////////////////////////////////////
// 獲取用戶選擇的輸入量程
int SelectOutputRange(void)
{
LONG OutputRange;
Repeat:
printf("\n");
printf("0. 0V ~ +5V\n");
printf("1. 0V ~ +10V\n");
printf("2. -5V ~ +5V\n");
printf("3. -10V ~ +10V\n");
printf("Please Select Input Range[0-3]:");
scanf("%d", &OutputRange);
if (OutputRange<0 || OutputRange>3) goto Repeat; // 判斷用戶選擇的量程是否合法,不合法,則重新選擇
return OutputRange;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -