📄 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 <userint.h>
#include "ADCards.h"
//------------------------------------------------------------------------------------------------
//
int __stdcall ADCards_Open(LPT_DAQCard pDev)
{
LRESULT ErrCde; // Return error code
if (pDev->hDevice != 0)
return 0;
ErrCde = DRV_DeviceOpen (pDev->dwIndex, (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->usGainCode;
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_AIBinaryIn ptAIVoltageIn; // structure for AIVoltageIn table
DWORD i;
double dfValue;
float fVoltage;
short nData;
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.reading = &nData;
ptAIVoltageIn.TrigMode = 0; // internal trigger
// ptAIVoltageIn.voltage = (float far *)&fVoltage;
ErrCde = DRV_AIBinaryIn( (LONG)pDev->hDevice, &ptAIVoltageIn );
if ( ErrCde != 0 )
return -1;
// dfValue += fVoltage;
}
*pdfVoltage = nData;
return 0;
}
//------------------------------------------------------------------------------------------------
//
int __stdcall ADCards_DOBit(LPT_DAQCard pDev, short ushChannel, short 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_DIBit(LPT_DAQCard pDev, short ushChannel, short* 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 + -