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

📄 init.pas

📁 16 relay output channels and 16 isolated digital input channels LED indicators to show activated
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit Init;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Menus, StdCtrls, ExtCtrls, Mask, Global, Driver,Math;

type
  TfrmInit = class(TForm)
    butExit: TButton;
    lstDevice: TListBox;
    labDevice: TLabel;
    butConvert: TButton;
    butGainList: TButton;
    grpScanChl: TGroupBox;
    labStartChl: TLabel;
    cmbStartChl: TComboBox;
    labChlCnt: TLabel;
    cmbChlCount: TComboBox;
    grpTrigSrc: TGroupBox;
    radExtTrig: TRadioButton;
    radInterTrig: TRadioButton;
    grpChecks: TGroupBox;
    chkCyclic: TCheckBox;
    chkEventEnable: TCheckBox;
    chkFloatData: TCheckBox;
    Label1: TLabel;
    Label2: TLabel;
    GroupBox1: TGroupBox;
    editSpeed: TMaskEdit;
    labSpeed: TLabel;
    labHz: TLabel;
    labDataCount: TLabel;
    editDataCounts: TMaskEdit;
    GroupBox2: TGroupBox;
    labFifo: TLabel;
    editFifo: TMaskEdit;
    chkFifo: TCheckBox;
    GroupBox3: TGroupBox;
    cmbOverallGain: TComboBox;
    radGainList: TRadioButton;
    radOverall: TRadioButton;
    procedure FormCreate(Sender: TObject);
    procedure butExitClick(Sender: TObject);
    procedure cmbStartChlChange(Sender: TObject);
    procedure butConvertClick(Sender: TObject);
    procedure lstDeviceClick(Sender: TObject);
    procedure butGainListClick(Sender: TObject);
    procedure cmbOverallGainClick(Sender: TObject);
    procedure radExtTrigClick(Sender: TObject);
    procedure radInterTrigClick(Sender: TObject);
    procedure chkFifoClick(Sender: TObject);
    procedure radOverallClick(Sender: TObject);
    procedure radGainListClick(Sender: TObject);
    procedure cmbOverallGainChange(Sender: TObject);

  private
    { Private declarations }
    ptDevFeatures : PT_DeviceGetFeatures;
    iMaxChl       : Smallint;
    wGainCode  : array [0..64] of Word;
    //DeviceList     : array [0..MaxDev] of PT_DEVLIST;
    ptAiStart      : PT_FAIIntScanStart;

    procedure ThreadDone(Sender: TObject);

  public
    { Public declarations }
    iGainIndex : array [0..15] of Smallint;
    giConvCount : LongInt;
    hBuf        : HGLOBAL;
    hUserbuf    : HGLOBAL;     { for voltage data }
    ghDev       : Longint;

  end;

var
  frmInit: TfrmInit;
  DeviceList     : array [0..MaxDev] of PT_DEVLIST;
  ptAIConfig     : PT_AIGetConfig;
  ptDevFeatures  : PT_DeviceGetFeatures;
  DevConfig_AI   : Driver.DEVCONFIG_AI;
  Function DoesErr(var lErrCode: LongInt): integer;  
  Function PhyChanToLogChan(DevCfg:Driver.DEVCONFIG_AI;PhyChan:smallint): smallint;
  Function GetMaxLogChanNum(DevCfg:Driver.DEVCONFIG_AI;DevFeature:Driver.DEVFEATURES): smallint;  
implementation

uses Convert, DataShow, GainListForm, GetEvent;

{$R *.DFM}

{Internal used procedure}
procedure IsNumbericKey(var Key: Char);
begin
     {Check the pressed key}
     if ((Key < '0') or (Key > '9')) and (Key <> Chr(8))then
        Key := Chr(0);
end;

{*************************************************************
 * Function: Handle the error code. If the input error code > 0,
 *           it means some error apperent.  This function can
 *           show the error message to a message box and stop
 *           this application.
 * Input:    The error code.
 * return:   none
 ************************************************************* }
Function DoesErr(var lErrCode: LongInt): integer;
var
    szErrMsg   : string[100];
    pszErrMsg  : PChar;
begin
    {Check the pressed error code}
    If (lErrCode <> 0) Then
    begin
        pszErrMsg := @szErrMsg;
        DRV_GetErrorMessage(lErrCode, pszErrMsg);
        Application.MessageBox(pszErrMsg, 'Error!!', MB_OK);
        DoesErr := 1;
    end
    else
        DoesErr := 0;
end;
                
Function PhyChanToLogChan(DevCfg:Driver.DEVCONFIG_AI;PhyChan:smallint): smallint;
var
        i :smallint;
        FunResult:smallint;
begin
        if(DevCfg.ulChanConfig = 1) then
        begin
                PhyChanToLogChan := PhyChan;
                Exit;
        end;
        FunResult := 0;
        i := 0;
        while (i <=Min(PhyChan,31)) do
        begin
		if ((DevCfg.ulChanConfig and (1 shl i))<>0) then i:= i+1;
		FunResult := FunResult + 1;
                i := i+1;
        end;

	if(phychan >= 32) then
        begin
                i := 32;
                while i<=phychan  do
                begin
		    if((DevCfg.ulChanConfigEx[0] and (1 shl (i-32)))<>0) then i := i+1;
                    FunResult := FunResult + 1;
                    i := i+1;
                end;
        end;
    PhyChanToLogChan := FunResult -1;
end;

Function GetMaxLogChanNum(DevCfg:Driver.DEVCONFIG_AI;DevFeature:Driver.DEVFEATURES): smallint;
var
        i :smallint;
        FunResult : smallint;
begin
        if(DevCfg.ulChanConfig = 1) then
        begin
                GetMaxLogChanNum := DevFeature.usMaxAIDiffChl;
                Exit;
        end;

        FunResult := 0;
        i := 0;
        while (i < DevFeature.usMaxAISiglChl) do
        begin
                if(i <32) then
                begin
                   if ((DevCfg.ulChanConfig and (1 shl i))<>0) then i:= i+1;
                end
                else
                   if ((DevCfg.ulChanConfigEx[0] and (1 shl (i-32)))<>0) then i:= i+1;
                FunResult := FunResult + 1;
                i := i+1;
        end;
        GetMaxLogChanNum := FunResult ;
end;

procedure TfrmInit.FormCreate(Sender: TObject);
var
    iNumOfDevices : Smallint;
    lErrCde : Longint;
    i : Smallint;

begin
    { Initialize controls}

  { Make Device list }
  lErrCde := DRV_DeviceGetNumOfList(iNumOfDevices);
  if( DoesErr(lErrCde) = 1 ) then
    Exit;

  lErrCde := DRV_DeviceGetList(DeviceList[0], iNumOfDevices, iNumOfDevices);
  if DoesErr(lErrCde) = 1 then
    Exit;

  For i := 0 To (iNumOfDevices - 1) do
  begin
    lstDevice.Items.Add(DeviceList[i].szDeviceName);
  end;
  lstDevice.ItemIndex := 0;
  lstDeviceClick(Sender);


  {Give the initialize value}

end;

procedure TfrmInit.butExitClick(Sender: TObject);
begin
  Close;
end;

procedure TfrmInit.cmbStartChlChange(Sender: TObject);
var
  i, iIndex : Smallint;
  szTmp     : string;

begin
  {We suggest the stop channel# should large then stop channel}

  {1. Make channel count selection}
  iIndex := cmbChlCount.itemIndex;
  cmbChlCount.Clear;
  for i := 1 to gwMaxLogChanNum do
  begin
    szTmp := IntToStr(i);
    cmbChlCount.items.Add(szTmp)
  end;

  {2. Selection current count}
  if iIndex >= cmbChlCount.items.Count then
    iIndex := cmbChlCount.items.Count - 1;

  cmbChlCount.itemIndex := iIndex;
end;

procedure TfrmInit.butConvertClick(Sender: TObject);
var
  i             : Smallint;
  lErrCde       : Longint;
  ptEnableEvent : PT_EnableEvent;
  logChan       : integer;
begin
  {Start converting action}

  {1. Open device }
  lErrCde := DRV_DeviceOpen( DeviceList[lstDevice.ItemIndex].dwDeviceNum,
                             ghDev);
  if ( DoesErr(lErrCde) = 1 ) then
    Exit;

  {Allocate memory for INT conversion}
  giConvCount := StrToInt(editDataCounts.Text);
  hBuf := GlobalAlloc(GPTR, SizeOf(Word) * (giConvCount+1));
  if hBuf = 0 then
  begin
    Application.MessageBox('Allocate memory for INT transfering failure.',
                           'Error!!', MB_OK);
    DRV_DeviceClose(ghDev);
    exit;
  end;
  if(chkFloatData.Checked ) then
    hUserbuf := GlobalAlloc(GPTR, SizeOf(Single) * (giConvCount+1))
  else
    hUserbuf := GlobalAlloc(GPTR, SizeOf(Word) * (giConvCount+1));
  if hUserbuf = 0 then
  begin
    Application.MessageBox('Allocate memory for INT transfering failure.',
                           'Error!!', MB_OK);
    DRV_DeviceClose(ghDev);
    exit;
  end;

⌨️ 快捷键说明

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