gainlistform.cpp

来自「16 relay output channels and 16 isolated」· C++ 代码 · 共 177 行

CPP
177
字号
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop
//#include "MainForm.h"
#include "GainListForm.h"
#include "..\..\..\include\driver.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TfrmGainList *frmGainList;

extern USHORT         usStartChan;
extern USHORT         usChanNum;
extern DEVFEATURES    DevFeatures;    // structure for device features
extern USHORT         usGainIndx[64];
extern DEVCONFIG_AI   Devconfig_AI;
extern DEVLIST        DeviceList[];     //MaxEntries + 1
extern PT_DeviceGetFeatures    ptDevGetFeatures;
extern long                    DeviceHandle;
extern PT_AIGetConfig          ptAIGetConfig;
extern int gwDevice;
extern int            giMaxLogChanNum;
int PhyChanToLogChan(DEVCONFIG_AI * pDevCfg,int PhyChan);
//---------------------------------------------------------------------------

__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<usChanNum; i++, iPhyChan++)
    {
        if(Devconfig_AI.ulChanConfig == 1)
        {
                if(iPhyChan >= DevFeatures.usMaxAIDiffChl)
                      iPhyChan -= DevFeatures.usMaxAIDiffChl;
        }
        else
               if(iPhyChan >= DevFeatures.usMaxAISiglChl)
                      iPhyChan -= DevFeatures.usMaxAISiglChl;
                      
        pItem = lstGainCtrl->Items->Add();
        pItem->Caption = "chan "+ IntToStr(iPhyChan);
        pItem->SubItems->Add( DevFeatures.glGainList[usGainIndx[PhyChanToLogChan(&Devconfig_AI,iPhyChan)]].szGainStr );

        if(Devconfig_AI.ulChanConfig == 1)
        {
             pItem->SubItems->Add( "Differential" );
             pItem->Caption = "chan "+ IntToStr(iPhyChan);
        }
        // If the channel number between 0 and 31
        else if (iPhyChan < 32)
        {
           if( Devconfig_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( Devconfig_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 = usGainIndx[(PhyChanToLogChan(&Devconfig_AI,usStartChan)+lstGainCtrl->ItemIndex) % giMaxLogChanNum];


}
//---------------------------------------------------------------------------


 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);
     usGainIndx[(PhyChanToLogChan(&Devconfig_AI,usStartChan) + lstGainCtrl->ItemIndex)% giMaxLogChanNum] = 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 *)&DeviceHandle);
    if (ErrCde != SUCCESS)
    {
        DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
        Application->MessageBox((char *)szErrMsg, "Driver Message", MB_OK);
    }

    // get device features
    ptDevGetFeatures.buffer = (LPDEVFEATURES)&DevFeatures;
    ptDevGetFeatures.size = sizeof(DEVFEATURES);
    if ((ErrCde = DRV_DeviceGetFeatures(DeviceHandle,
        (LPT_DeviceGetFeatures)&ptDevGetFeatures)) != SUCCESS)
    {
        DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
        DRV_DeviceClose((LONG far *)&DeviceHandle);
        Application->MessageBox((char *)szErrMsg, "Driver Message", MB_OK);
    }
    ptAIGetConfig.size = sizeof(LPDEVCONFIG_AI);
    ptAIGetConfig.buffer = &Devconfig_AI;
    ErrCde = DRV_AIGetConfig(DeviceHandle, &ptAIGetConfig);
    if (ErrCde != SUCCESS)
    {
        DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
        Application->MessageBox((char *)szErrMsg, "Driver Message", MB_OK);
    }

    DRV_DeviceClose(&DeviceHandle);

    SetGainList();
    return;
}
//---------------------------------------------------------------------------


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?