⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gainlistform.cpp

📁 16 relay output channels and 16 isolated digital input channels LED indicators to show activated
💻 CPP
字号:
//---------------------------------------------------------------------------

#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  lpDevConfig_AI ;
extern USHORT        gwDevice;
extern DEVLIST       DeviceList[];   // MAX_DEVICES
extern LONG          DriverHandle;
extern PT_DeviceGetFeatures  ptDevFeatures;
extern PT_AIGetConfig  lpAIGetConfig;

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
    int iLogChan;

    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;
    iLogChan = usStartChan;
    for(int i=0; i<usChanNum; i++, iPhyChan++)
    {
        // For cards that can not combine differential and single-ended
        // If all channels are differential, lpDevConfig_AI.ulChanConfig = 1
        // If all channels are differential, lpDevConfig_AI.ulChanConfig = 0
        if ( lpDevConfig_AI.ulChanConfig == 1)
        {
           if ( iLogChan >= DevFeatures.usMaxAIDiffChl )
                break;
        }
        else
        {
           if(iPhyChan >= DevFeatures.usMaxAISiglChl)
                break;
        }

        pItem = lstGainCtrl->Items->Add();
        pItem->Caption = "chan "+ IntToStr(iPhyChan);
        pItem->SubItems->Add( DevFeatures.glGainList[usGainIndx[PhyChanToLogChan(&lpDevConfig_AI,iPhyChan)]].szGainStr );

        if ( lpDevConfig_AI.ulChanConfig == 1 )
        {
           pItem->SubItems->Add( "Differential" );
           pItem->Caption = "chan " + IntToStr(iPhyChan);
        }
        else
        {
            // 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 = usGainIndx[PhyChanToLogChan(&lpDevConfig_AI,usStartChan)+lstGainCtrl->ItemIndex];
}
//---------------------------------------------------------------------------


 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(&lpDevConfig_AI,usStartChan) + lstGainCtrl->ItemIndex] = 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);
    }
    
    DRV_DeviceClose(&DriverHandle);

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

//---------------------------------------------------------------------------

⌨️ 快捷键说明

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