📄 gainlistform.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "MainForm.h"
#include "GainListForm.h"
#include "..\..\..\include\driver.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
#define min(a,b) (((a) > (b))?(b):(a))
TfrmGainList *frmGainList;
extern USHORT usStartChan;
extern USHORT usChanNum;
extern DEVFEATURES DevFeatures; // structure for device features
extern USHORT gwGain[64];
extern DEVCONFIG_AI lpDevConfig_AI ;
//#define MAX_DEVICES 100
extern DEVLIST DeviceList[]; //MAX_DEVICES
extern int gwDevice;
extern LONG DriverHandle; // driver handle
extern PT_DeviceGetFeatures ptDevFeatures;
extern PT_AIGetConfig lpAIGetConfig;
extern LONG gwMaxLogChanNum;
int PhyChanToLogChan(DEVCONFIG_AI * pDevCfg,int PhyChan);
int GetMaxLogChanNum(DEVCONFIG_AI * pDevCfg,DEVFEATURES *pDevFeature);
//---------------------------------------------------------------------------
__fastcall TfrmGainList::TfrmGainList(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TfrmGainList::btnExitClick(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void TfrmGainList::SetGainList()
{
//TODO: Add your source code here
int iPhyChan; // Physical channel number
lstGainCtrl->Clear();
cmbGain->Clear();
for(int i = 0; i < DevFeatures.usNumGain;i++)
{
cmbGain->Items->Add(DevFeatures.glGainList[i].szGainStr);
cmbGain->ItemIndex = 0;
}
TListItem *pItem;
iPhyChan = usStartChan;
for(int i=0; i<min(usChanNum,gwMaxLogChanNum); i++, iPhyChan++)
{
if((iPhyChan >= DevFeatures.usMaxAISiglChl))
{
iPhyChan -= DevFeatures.usMaxAISiglChl;
}
pItem = lstGainCtrl->Items->Add();
pItem->Caption = "chan "+ IntToStr(iPhyChan);
pItem->SubItems->Add( DevFeatures.glGainList[gwGain[PhyChanToLogChan(&lpDevConfig_AI,iPhyChan)]].szGainStr );
// If the channel number between 0 and 31
if (iPhyChan < 32)
{
if( lpDevConfig_AI.ulChanConfig & (1 << iPhyChan) )
{
pItem->SubItems->Add( "Differential" );
if (iPhyChan % 2 == 0)
{
iPhyChan++;
}
pItem->Caption = "chan "+ IntToStr(iPhyChan-1) + "," + IntToStr(iPhyChan);
}else{
pItem->SubItems->Add( "Single-Ended" );
}
}
else
{ // If the channel number between 32 and 63
if( lpDevConfig_AI.ulChanConfigEx[0] & (1 << iPhyChan-32) )
{
pItem->SubItems->Add( "Differential" );
if (iPhyChan % 2 == 0)
{
iPhyChan++;
}
pItem->Caption = "chan "+ IntToStr(iPhyChan-1) + "," + IntToStr(iPhyChan);
}else{
pItem->SubItems->Add( "Single-Ended" );
}
}
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmGainList::lstGainCtrlClick(TObject *Sender)
{
if( lstGainCtrl->ItemIndex >= 0 )
cmbGain->ItemIndex = gwGain[(PhyChanToLogChan(&lpDevConfig_AI,usStartChan) \
+lstGainCtrl->ItemIndex) % gwMaxLogChanNum];
}
//---------------------------------------------------------------------------
void __fastcall TfrmGainList::cmbGainChange(TObject *Sender)
{
if( lstGainCtrl->ItemIndex >= 0 )
{
TListItem *pItem = lstGainCtrl->Selected;
pItem->SubItems[0].Strings[0] =
AnsiString( DevFeatures.glGainList[cmbGain->ItemIndex].szGainStr);
gwGain[(PhyChanToLogChan(&lpDevConfig_AI,usStartChan) + lstGainCtrl->ItemIndex) % gwMaxLogChanNum] = cmbGain->ItemIndex;
}
}
void __fastcall TfrmGainList::FormShow(TObject *Sender)
{
char szErrMsg[80]; // Use for MESSAGEBOX function
LRESULT ErrCde; // Return error code
ErrCde = DRV_DeviceOpen(DeviceList[gwDevice].dwDeviceNum,
(LONG far *)&DriverHandle);
if (ErrCde != SUCCESS)
{
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
Application->MessageBox((char *)szErrMsg, "Driver Message", MB_OK);
}
// get device features
ptDevFeatures.buffer = (LPDEVFEATURES)&DevFeatures;
ptDevFeatures.size = sizeof(DEVFEATURES);
if ((ErrCde = DRV_DeviceGetFeatures(DriverHandle,
(LPT_DeviceGetFeatures)&ptDevFeatures)) != SUCCESS)
{
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
DRV_DeviceClose((LONG far *)&DriverHandle);
Application->MessageBox((char *)szErrMsg, "Driver Message", MB_OK);
}
lpAIGetConfig.size = sizeof(LPDEVCONFIG_AI);
lpAIGetConfig.buffer = &lpDevConfig_AI;
ErrCde = DRV_AIGetConfig(DriverHandle, &lpAIGetConfig);
if (ErrCde != SUCCESS)
{
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
Application->MessageBox((char *)szErrMsg, "Driver Message", MB_OK);
}
gwMaxLogChanNum = GetMaxLogChanNum(&lpDevConfig_AI,&DevFeatures);
DRV_DeviceClose(&DriverHandle);
SetGainList();
return;
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -