📄 adcards.c
字号:
// #########################################################################
// *************************************************************************
// Copyright (C) 2002-2004, Xi'an KeXing M&C Ltd. Corp.
// THIS IS AN UNPUBLISHED WORK CONTAINED CONFIDENTIAL, AND PROPRIETARY
// INFORMATION WHICH IS THE PROPERTY OF Xi'an KeXing M&C Ltd. Corp.
// ANY DISCLOSURE, USE, OR REPRODUCTION, WITHOUT WRITTERN AUTHORIZATION FROM
// Xi'an KeXing M&C Ltd. Corp., IS STRICT
// #########################################################################
// *************************************************************************
#include <ansi_c.h>
#include <windows.h>
#include <WinBase.h>
#include <userint.h>
#include "ADCards.h"
static DWORD g_DOMask = 0x0000;
//------------------------------------------------------------------------------------------------
int __stdcall ADCards_Open(LPT_DAQCard pDev)
{
LRESULT ErrCde; // Return error code
if (pDev->hDevice != 0)
return 0;
ErrCde = DRV_DeviceOpen (pDev->dwDeviceIndex, (LONG far*)&pDev->hDevice);
if (ErrCde != SUCCESS)
return -1;
return 0;
}
//------------------------------------------------------------------------------------------------
int __stdcall ADPCards_Close(LPT_DAQCard pDev)
{
LRESULT ErrCde; // Return error code
if (pDev->hDevice == NULL)
return 0;
ErrCde = DRV_DeviceClose ((LONG far*)&pDev->hDevice);
if (ErrCde != SUCCESS)
return -1;
pDev->hDevice = NULL;
return 0;
}
//------------------------------------------------------------------------------------------------
int __stdcall ADCards_AIConfig(LPT_DAQCard pDev, USHORT ushChannel)
{
LRESULT ErrCde; // Return error code
PT_AIConfig ptAIConfig; // structure for AIConfig table
if ( pDev->hDevice == NULL )
return -1;
//
// configures the gain for the specifed analog input channel
//
ptAIConfig.DasGain = pDev->dwGainCode;
ptAIConfig.DasChan = ushChannel;
ErrCde = DRV_AIConfig( (LONG)pDev->hDevice, &ptAIConfig );
if ( ErrCde != 0 )
return -1;
return 0;
}
//------------------------------------------------------------------------------------------------
int __stdcall ADCards_AIValue(LPT_DAQCard pDev, USHORT ushChannel, DWORD nCount, double* pdfVoltage)
{
LRESULT ErrCde; // Return error code
PT_AIVoltageIn ptAIVoltageIn; // structure for AIVoltageIn table
DWORD i;
double dfValue;
float fVoltage;
if ( pDev->hDevice == NULL )
return -1;
if ( nCount <= 0 )
return -1;
//
// reads an analog input channel
//
ADCards_AIConfig(pDev, ushChannel);
dfValue = 0.0;
for ( i = 0; i < nCount; i ++ )
{
ptAIVoltageIn.chan = ushChannel;
ptAIVoltageIn.gain = pDev->dwGainCode;
ptAIVoltageIn.TrigMode = 0; // internal trigger
ptAIVoltageIn.voltage = (float far *)&fVoltage;
ErrCde = DRV_AIVoltageIn( (LONG)pDev->hDevice, &ptAIVoltageIn );
if ( ErrCde != 0 )
return -1;
dfValue += fVoltage;
}
*pdfVoltage = dfValue / nCount;
return 0;
}
//------------------------------------------------------------------------------------------------
int __stdcall ADCards_AOConfig( LPT_DAQCard pDev, USHORT ushChannel )
{
LRESULT ErrCde; // Return error code
PT_AOConfig ptAOConfig; // structure for AIConfig table
if ( pDev->hDevice == NULL )
return -1;
//
// configures the gain for the specifed analog input channel
//
ptAOConfig.chan = ushChannel;
ptAOConfig.RefSrc = 0;
ptAOConfig.MaxValue = 10;
ptAOConfig.MinValue = -10;
ErrCde = DRV_AOConfig( (LONG)pDev->hDevice, &ptAOConfig );
if ( ErrCde != 0 )
return -1;
return 0;
}
//------------------------------------------------------------------------------------------------
int __stdcall ADCards_AOValue( LPT_DAQCard pDev, USHORT ushChannel, float fVoltage )
{
LRESULT ErrCde; // Return error code
PT_AOVoltageOut ptAOVoltageOut; // structure for AIVoltageIn table
if ( pDev->hDevice == NULL )
return -1;
//
// writes an analog output channel
//
ptAOVoltageOut.chan = ushChannel;
ptAOVoltageOut.OutputValue = fVoltage;
ErrCde = DRV_AOVoltageOut( (LONG)pDev->hDevice, &ptAOVoltageOut );
if ( ErrCde != 0 )
return -1;
return 0;
}
//------------------------------------------------------------------------------------------------
int __stdcall ADCards_DOBit( LPT_DAQCard pDev, USHORT ushChannel, USHORT ushState )
{
LRESULT ErrCde; // Return error code
PT_DioWriteBit ptDioWriteBit;
if ( pDev->hDevice == NULL )
return -1;
// output bit
ptDioWriteBit.port = ushChannel / 8;
ptDioWriteBit.bit = ushChannel % 8;
ptDioWriteBit.state = ushState;
ErrCde = DRV_DioWriteBit( (LONG)pDev->hDevice, &ptDioWriteBit );
if ( ErrCde != 0)
return -1;
return 0;
}
//------------------------------------------------------------------------------------------------
int __stdcall ADCards_DOWord( LPT_DAQCard pDev, USHORT ushPort, USHORT ushState )
{
LRESULT ErrCde; // Return error code
PT_DioWritePortWord ptDioWritePortWord;
if ( pDev->hDevice == NULL )
return -1;
// output bit
ptDioWritePortWord.port = ushPort;
ptDioWritePortWord.mask = 0xffff;
ptDioWritePortWord.state = ushState;
ErrCde = DRV_DioWritePortWord( (LONG)pDev->hDevice, &ptDioWritePortWord );
if ( ErrCde != 0)
return -1;
return 0;
}
//------------------------------------------------------------------------------------------------
int __stdcall ADCards_DIBit( LPT_DAQCard pDev, USHORT ushChannel, USHORT* pusState )
{
LRESULT ErrCde; // Return error code
PT_DioReadBit ptDioReadBit;
if ( pDev->hDevice == NULL )
return -1;
// output bit
ptDioReadBit.port = ushChannel / 8;
ptDioReadBit.bit = ushChannel % 8;
ptDioReadBit.state = pusState;
ErrCde = DRV_DioReadBit( (LONG)pDev->hDevice, &ptDioReadBit );
if ( ErrCde != 0)
return -1;
return 0;
}
//------------------------------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -