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

📄 displayform.cpp

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

#include <vcl.h>
#pragma hdrstop

#include "DisplayForm.h"
#include "..\..\..\include\driver.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TfrmDisplay *frmDisplay;

extern      char        szErrMsg[80];               // Use for MESSAGEBOX function
extern      char        szBuffer[40];				// Temperatory buffer
extern      LRESULT     ErrCde;                     // Return error code

extern LONG   DriverHandle ;         // driver handle
extern      PT_MAIVoltageIn  ptMAIVoltageIn;  // structure for AIVoltageIn table
extern      FLOAT       fVoltageArray[64];

//---------------------------------------------------------------------------
__fastcall TfrmDisplay::TfrmDisplay(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TfrmDisplay::ScanTimerTimer(TObject *Sender)
{
   AnsiString buff;

    if ((ErrCde = DRV_MAIVoltageIn(DriverHandle,
             (LPT_MAIVoltageIn)&ptMAIVoltageIn)) != 0)
    {
         DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
         Application->MessageBox((LPCSTR)szErrMsg,"Driver Message",MB_OK);
         DRV_DeviceClose((LONG far *)&DriverHandle);
         ScanTimer->Enabled = false;
         return;
     }

   Canvas->Font->Color =  clBlue;
   for(int i=0;i<ptMAIVoltageIn.NumChan;i++)
   {
      buff.sprintf( "Chan%d: %0.5fV",ptMAIVoltageIn.StartChan+i,fVoltageArray[i]);
      Canvas->TextOut(20+(i%4)*100,80+(i/4)*20,buff);
   }        
}
//---------------------------------------------------------------------------
void __fastcall TfrmDisplay::btnExitClick(TObject *Sender)
{
    ScanTimer->Enabled = false;
     ErrCde = DRV_DeviceClose((LONG far *)&DriverHandle);
    if (ErrCde != SUCCESS)
    {
        DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
        Application->MessageBox((char *)szErrMsg, "Driver Message", MB_OK);
     }
     Close();
}
//---------------------------------------------------------------------------
void __fastcall TfrmDisplay::trbTimerChange(TObject *Sender)
{
   if( trbTimer->Position >0 )
   {
       ScanTimer->Interval = 1000 / trbTimer->Position;
         ScanTimer->Enabled = true;
   }
   else
         ScanTimer->Enabled = false;

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

void __fastcall TfrmDisplay::FormClose(TObject *Sender,
      TCloseAction &Action)
{
   if(ScanTimer->Enabled)
   {
     ScanTimer->Enabled = false;
     ErrCde = DRV_DeviceClose((LONG far *)&DriverHandle);
     if (ErrCde != SUCCESS)
     {
        DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
        Application->MessageBox((char *)szErrMsg, "Driver Message", MB_OK);
     }
     Close();
   }
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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