📄 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 + -