📄 boarddrv.cpp
字号:
// BoardDrv.cpp : Defines the initialization routines for the DLL.
//
#include "stdafx.h"
#include <afxdllx.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
static AFX_EXTENSION_MODULE BoardDrvDLL = { NULL, NULL };
extern "C" int APIENTRY
DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
// Remove this if you use lpReserved
UNREFERENCED_PARAMETER(lpReserved);
if (dwReason == DLL_PROCESS_ATTACH)
{
TRACE0("BOARDDRV.DLL Initializing!\n");
// Extension DLL one-time initialization
if (!AfxInitExtensionModule(BoardDrvDLL, hInstance))
return 0;
// Insert this DLL into the resource chain
// NOTE: If this Extension DLL is being implicitly linked to by
// an MFC Regular DLL (such as an ActiveX Control)
// instead of an MFC application, then you will want to
// remove this line from DllMain and put it in a separate
// function exported from this Extension DLL. The Regular DLL
// that uses this Extension DLL should then explicitly call that
// function to initialize this Extension DLL. Otherwise,
// the CDynLinkLibrary object will not be attached to the
// Regular DLL's resource chain, and serious problems will
// result.
new CDynLinkLibrary(BoardDrvDLL);
}
else if (dwReason == DLL_PROCESS_DETACH)
{
TRACE0("BOARDDRV.DLL Terminating!\n");
// Terminate the library before destructors are called
AfxTermExtensionModule(BoardDrvDLL);
}
return 1; // ok
}
#include "PxiHDDrv.h"
////////////////////////////////////////////////////////////////////////////////
//万用表测量的作用域
//
///////////////////////////////////////////////////////////////////////////////
namespace NMDriver_DMM
{
#include "niDMM.h"
#pragma comment(lib, "nidmm_32.lib")
long Status = 0;
static ULONG hDMMSession = 0;
//初始化
BOOL AFX_EXT_API _DMM_Init(char szResource[256])
{
char szErrMsg[256] = {0};
Status = niDMM_init(szResource, TRUE, TRUE, &hDMMSession);
niDMM_error_message(hDMMSession, Status, szErrMsg);
Status = niDMM_ConfigurePowerLineFrequency(hDMMSession, 50); //50Hz电源频率
niDMM_error_message(hDMMSession, Status, szErrMsg);
Status = niDMM_SetAutoZero(hDMMSession, NIDMM_VAL_AUTO_ZERO_ON );
niDMM_error_message(hDMMSession, Status, szErrMsg);
if (Status <= 0)
return FALSE;
return TRUE;
}
BOOL AFX_EXT_API _DMM_GetSelf(void)
{
char szErrMsg[256] = {0};
short nTestResult = -1;
if (hDMMSession >0)
{
//::niDMM_self_test(hDMMSession, &nTestResult, szErrMsg);
Status = niDMM_reset(hDMMSession);
niDMM_error_message(hDMMSession, Status, szErrMsg);
return TRUE;
}
return FALSE;
}
//配置直流电压
void AFX_EXT_API _DMM_DCVoltMode(void)
{
char szErrMsg[256] = {0};
Status = niDMM_ConfigureMeasurement(hDMMSession, NIDMM_VAL_DC_VOLTS, NIDMM_VAL_AUTO_RANGE_ON, 0.0001);
niDMM_error_message(hDMMSession, Status, szErrMsg);
}
//配置交流电压
void AFX_EXT_API _DMM_ACVoltMode(void)
{
char szErrMsg[256] = {0};
Status = niDMM_ConfigureMeasurement(hDMMSession, NIDMM_VAL_AC_VOLTS, NIDMM_VAL_AUTO_RANGE_ON, 0.0001);
niDMM_error_message(hDMMSession, Status, szErrMsg);
}
void AFX_EXT_API _DMM_DCCurrMode(void)
{
char szErrMsg[256] = {0};
Status = niDMM_ConfigureMeasurement(hDMMSession, NIDMM_VAL_DC_CURRENT, NIDMM_VAL_AUTO_RANGE_ON, 0.0001);
niDMM_error_message(hDMMSession, Status, szErrMsg);
}
void AFX_EXT_API _DMM_ACCurrMode(void)
{
char szErrMsg[256] = {0};
Status = niDMM_ConfigureMeasurement(hDMMSession, NIDMM_VAL_AC_CURRENT, NIDMM_VAL_AUTO_RANGE_ON, 0.0001);
niDMM_error_message(hDMMSession, Status, szErrMsg);
}
//配置电阻
void AFX_EXT_API _DMM_ResiMode(void)
{
char szErrMsg[256] = {0};
Status = niDMM_ConfigureMeasurement(hDMMSession, NIDMM_VAL_2_WIRE_RES, NIDMM_VAL_AUTO_RANGE_ON, 0.0001);
niDMM_error_message(hDMMSession, Status, szErrMsg);
}
//开始测量
double AFX_EXT_API _DMM_Measure(void)
{
double valMeas = 0.0;
char szErrMsg[256] = {0};
::Sleep(100);
Status = niDMM_Read(hDMMSession, NIDMM_VAL_TIME_LIMIT_AUTO, &valMeas);
niDMM_error_message(hDMMSession, Status, szErrMsg);
return valMeas;
}
//关闭
BOOL AFX_EXT_API _DMM_Close(void)
{
if (hDMMSession >0)
{
niDMM_close(hDMMSession);
return TRUE;
}
return FALSE;
}
}
////////////////////////////////////////////////////////////////////////////////
//示波器测量的作用域
//
///////////////////////////////////////////////////////////////////////////////
namespace NMDriver_Scope
{
/************************************************************************************
#if 0
long niScope_init (char*, USHORT, USHORT, UINT*);
long niScope_self_test(UINT, SHORT*, char szMsg[256]);
long niScope_close(UINT);
long niScope_ActualNumWfms(UINT, const char *, long*);
long niScope_Commit(UINT);
long niScope_error_message(UINT, int, char *);
long niScope_ConfigureVertical(UINT, const char *, double, double, long, double, USHORT);
long niScope_FetchMeasurement(UINT, const char *, double, long, double *);
long niScope_AcquisitionStatus(UINT, long *);
long niScope_InitiateAcquisition(UINT);
long niScope_ConfigureHorizontalTiming(UINT, double, long, double, long, USHORT);
long niScope_ConfigureAcquisition(UINT, long);
long niScope_ActualRecordLength(UINT, long *);
long niScope_ConfigureChanCharacteristics(UINT, const char *, double, double);
#define NISCOPE_VAL_ACQ_COMPLETE 1
#define NISCOPE_VAL_ACQ_STATUS_UNKNOWN -1
#define NISCOPE_VAL_AC_ESTIMATE 1012
#define NISCOPE_VAL_DC 1
#define NISCOPE_VAL_NORMAL 0
#endif
**********************************************************************************/
#include "niScope.h"
#pragma comment(lib, "niScope.lib")
long Status = 0;
static ULONG hScopeSession = 0;
#define MAXSCOPECHNLNUM 2
#define MAXSAMPSIZE 10000
double ScopeBuffer[MAXSAMPSIZE] = {0};
BOOL AFX_EXT_API _Scope_Init(char szResource[256])
{
char szErrMsg[256];
Status = niScope_init (szResource, TRUE, TRUE, &hScopeSession);
niScope_error_message (hScopeSession, Status, szErrMsg);
return (Status == 0);
}
BOOL AFX_EXT_API _Scope_GetSelf(void)
{
short bResult = -1;
char szMsg[256], szErrMsg[256];
if (hScopeSession <= 0)
return FALSE;
Status = niScope_self_test (hScopeSession, &bResult, szMsg);
niScope_error_message (hScopeSession, Status, szErrMsg);
return (Status == 0);
}
void AFX_EXT_API _Scope_Config()
{
long ActualRecordLength = 0; //实际可使用的点数
char szErrMsg[256];
if (hScopeSession <= 0)
return ;
Status = niScope_ConfigureAcquisition(hScopeSession, NISCOPE_VAL_NORMAL);
niScope_error_message (hScopeSession, Status, szErrMsg);
Status = niScope_ActualRecordLength (hScopeSession, &ActualRecordLength);
niScope_error_message (hScopeSession, Status, szErrMsg);
Status = niScope_ConfigureHorizontalTiming (hScopeSession, 1*1000*1000, MAXSAMPSIZE, 0.0f, 1, VI_TRUE);
niScope_error_message (hScopeSession, Status, szErrMsg);
Status = niScope_ConfigureChanCharacteristics (hScopeSession, "0, 1", 1.0*1000*1000, -1);
niScope_error_message (hScopeSession, Status, szErrMsg);
Status = niScope_ConfigureVertical (hScopeSession, "0, 1", 10.0, 5.0, NISCOPE_VAL_DC, 1, TRUE);
niScope_error_message (hScopeSession, Status, szErrMsg);
Status = niScope_Commit (hScopeSession);
niScope_error_message (hScopeSession, Status, szErrMsg);
}
//读取单通道的有效值
double AFX_EXT_API _Scope_Fetch(int nChnl)
{
if (hScopeSession <= 0)
return 0.0f;
long ActualNumWfms = 0, MaxNumWfms = 0;
char szFmt[256];
char szErrMsg[256];
double measResult[MAXSCOPECHNLNUM] = {0.0f};
::sprintf(szFmt, "%d", nChnl);
//返回采集缓存的大小
Status = niScope_ActualRecordLength (hScopeSession, &MaxNumWfms); //每通道的总记录大小(所有记录和)
niScope_error_message (hScopeSession, Status, szErrMsg);
TRACE2("通道%d实际可用的缓存空间=%d.\n", nChnl, MaxNumWfms);
Status = niScope_InitiateAcquisition (hScopeSession);
niScope_error_message (hScopeSession, Status, szErrMsg);
long bAcqStatus = NISCOPE_VAL_ACQ_STATUS_UNKNOWN;
int nElapseCount = 0;
while (NISCOPE_VAL_ACQ_COMPLETE != bAcqStatus || nElapseCount < 100)
{
niScope_AcquisitionStatus (hScopeSession, &bAcqStatus);
::Sleep(20);
nElapseCount++;
}
//niScope_wfmInfo sniScope_wfmInfo;
//Status = niScope_Read (hScopeSession, szFmt, 3.0, 1000/*读取点数*/, ScopeBuffer/*缓存地址*/, &sniScope_wfmInfo);
//niScope_error_message (hScopeSession, Status, szErrMsg);
Status = niScope_ActualNumWfms (hScopeSession, szFmt, &ActualNumWfms);
niScope_error_message (hScopeSession, Status, szErrMsg);
TRACE2("通道%d实际可用的记录数=%d.\n", nChnl, ActualNumWfms);
//分析出有效值
Status = niScope_FetchMeasurement (hScopeSession, szFmt, 3.0, NISCOPE_VAL_AC_ESTIMATE, measResult);
niScope_error_message (hScopeSession, Status, szErrMsg);
return measResult[MAXSCOPECHNLNUM-ActualNumWfms];
}
void AFX_EXT_API _Scope_Close(void)
{
if (hScopeSession > 0)
niScope_close (hScopeSession);
}
}
////////////////////////////////////////////////////////////////////////////////
//ARINC429测量的作用域
//
///////////////////////////////////////////////////////////////////////////////
namespace NMDriver_AR429
{
#include "cei_types.h"
#include "utildefs.h"
#pragma comment(lib, "cei22032.lib")
typedef void *HANDLE;
static CEI_INT16 Status = 0;
static CEI_INT16 nARINC429Card = 0;
BOOL AFX_EXT_API _ARINC429_GetSelf(void)
{
//Status = ar_selftest(nCard, 1);
Status = ar_reset(nARINC429Card);
if (Status != ARS_NORMAL)
return FALSE;
return TRUE;
}
BOOL AFX_EXT_API _ARINC429_TxWord(short nChnlNo, long Data)
{
if (nARINC429Card <= 0)
return FALSE;
Status = ar_putword(nARINC429Card, nChnlNo, Data);
if (Status != ARS_NORMAL)
return FALSE;
return TRUE;
}
long AFX_EXT_API _ARINC429_TxWord(short nChnlNo)
{
if (nARINC429Card <= 0)
return FALSE;
long destData = 0;
Status = ar_getword (nARINC429Card, nChnlNo, &destData);
if (Status != ARS_NORMAL)
return -1;
return destData;
}
void AFX_EXT_API _ARINC429_GetChnlNum(short *RecvChnlNum, short *SendChnlNum)
{
if (nARINC429Card <= 0)
return ;
*SendChnlNum = ar_num_xchans(nARINC429Card);
*RecvChnlNum = ar_num_rchans(nARINC429Card);
}
BOOL AFX_EXT_API _ARINC429_Init(int nCard)
{
Status = ar_loadslv(nCard, 0, 0, 0);
if (Status != ARS_NORMAL)
return FALSE;
nARINC429Card = nCard;
short board_type = ar_get_boardtype(nARINC429Card);
if ((board_type & IS_717) || (board_type & IS_CSDB))
{
// display failure message and abort
TRACE0("\nError! CEI-x20 boards with 573/717 or CSDB channels are not supported\nby this application. ");
return FALSE;
}
// enable internal wrap mode
Status = ar_set_config(nARINC429Card, ARU_INTERNAL_WRAP, AR_WRAP_ON);
if (Status != ARS_NORMAL)
return FALSE;
// set the transmitters to low speed (12.5K)
Status = ar_set_config(nARINC429Card, ARU_XMIT_RATE, AR_LOW);
if (Status != ARS_NORMAL)
return FALSE;
// set the receivers to low speed (12.5K)
Status = ar_set_config(nARINC429Card, ARU_RECV_RATE, AR_LOW);
if (Status != ARS_NORMAL)
return FALSE;
// launch the board
Status = ar_go(nARINC429Card);
if (Status != ARS_NORMAL)
return FALSE;
return TRUE;
}
void AFX_EXT_API _ARINC429_Close(void)
{
if (nARINC429Card <= 0)
return ;
Status = ar_close(nARINC429Card);
}
}
////////////////////////////////////////////////////////////////////////////////
//75SD测量的作用域
//
///////////////////////////////////////////////////////////////////////////////
namespace NMDriver_75SD
{
#include "as_cPCI75sd1.h"
#pragma comment(lib, "as_cPCI75sd1.lib")
typedef void *HANDLE;
static int Status = 0;
static int n75SDCard = 0;
static HANDLE h75SDCardHandle = NULL;
BOOL AFX_EXT_API _75SD_GetSelf(void)
{
int nID = 0;
Status = as_75sd1_getID(n75SDCard, &nID);
if (nID == 0x7501 && Status == 0)
return TRUE;
else
return FALSE;
}
BOOL AFX_EXT_API _75SD_Init(int nCard)
{
n75SDCard = nCard;
h75SDCardHandle = as_75sd1_open(nCard);
if (h75SDCardHandle == NULL)
return FALSE;
Status = as_75sd1_softReset(h75SDCardHandle);
return (Status == 0);
}
double AFX_EXT_API _75SD_GetRefFreq(void)
{
double frequency = 0.0f;
if (h75SDCardHandle == NULL)
return 0.0f;
Status = as_75sd1_getRefFreq(h75SDCardHandle, &frequency);
if (Status != 0)
return 0.0f;
return frequency;
}
double AFX_EXT_API _75SD_GetRefVolt(void)
{
double voltage = 0.0f;
if (h75SDCardHandle == NULL)
return 0.0f;
Status = as_75sd1_getRefVoltage(h75SDCardHandle, &voltage);
if (Status != 0)
return 0.0f;
return voltage;
}
//
BOOL AFX_EXT_API _75SD_GetCardInfo(int *partNumber, int *serialNumber, int *dateCode)
{
BOOL bFuncStatus = TRUE;
*partNumber = -1;
*serialNumber= -1;
*dateCode = -1;
if (h75SDCardHandle == NULL)
return FALSE;
//This function will get the card's part number
Status = as_75sd1_getPartNumber(h75SDCardHandle, partNumber);
if (Status == 0)
bFuncStatus = TRUE;
else
return FALSE;
//This function will get the card's serial number
Status = as_75sd1_getSerialNumber(h75SDCardHandle, serialNumber);
if (Status == 0)
bFuncStatus |= TRUE;
else
return FALSE;
//This function will get the card's date code
Status = as_75sd1_getDateCode(h75SDCardHandle, dateCode);
if (Status == 0)
bFuncStatus |= TRUE;
else
return FALSE;
return TRUE;
}
BOOL AFX_EXT_API _75SD_GetStatusInfo(int *SigStatus, int *RefStatus, int *TestStatus)
{
if (h75SDCardHandle == NULL)
return FALSE;
Status = as_75sd1_getSignalStatusAll(h75SDCardHandle, SigStatus); //Get all signal status
Status |= as_75sd1_getRefStatusAll(h75SDCardHandle, RefStatus); //Get all reference status
Status |= as_75sd1_getTestStatusAll(h75SDCardHandle, TestStatus); //Get all test status
return (Status == 0);
}
double AFX_EXT_API _75SD_GetAngle(int Chnl)
{
double angle = 0.0f;
if (h75SDCardHandle == NULL)
return 0.0f;
Status = as_75sd1_getAngle(h75SDCardHandle, Chnl, &angle);
if(Status == 0)
return angle;
else
return 0.0f;
}
void AFX_EXT_API _75SD_Close(void)
{
Status = as_75sd1_close(h75SDCardHandle);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -