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

📄 settingform.pas

📁 16 relay output channels and 16 isolated digital input channels LED indicators to show activated
💻 PAS
字号:
unit SettingForm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,Global, ExtCtrls, Driver;

type
  TfrmSetting = class(TForm)
    GroupBox2: TGroupBox;
    RadioDataWidth16: TRadioButton;
    RadioDataWidth8: TRadioButton;
    GroupBox3: TGroupBox;
    RadioStartTypeSoftware: TRadioButton;
    RadioStartTypeExt: TRadioButton;
    GroupBox4: TGroupBox;
    RadioStopTypeSoftware: TRadioButton;
    RadioStopTypeExt: TRadioButton;
    GroupBox5: TGroupBox;
    RadioCyclic: TRadioButton;
    RadioNonCyclic: TRadioButton;
    GroupBox6: TGroupBox;
    Label2: TLabel;
    ListBoxTriggerSource: TListBox;
    EditCounterValue: TEdit;
    GroupBox7: TGroupBox;
    ListBoxUserBuffer: TListBox;
    ButtonOK: TButton;
    GroupBox1: TGroupBox;
    radNormal: TRadioButton;
    radBurst: TRadioButton;
    rad8255: TRadioButton;
    RadioDataWidth32: TRadioButton;
    RadioGroup1: TRadioGroup;
    RadioDmaSlave: TRadioButton;
    RadioDmaMaster: TRadioButton;
    GroupBox8: TGroupBox;
    txtDigitalValue: TEdit;
    procedure ButtonOKClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure txtDigitalValueChange(Sender: TObject);
    procedure txtDigitalValueKeyPress(Sender: TObject; var Key: Char);
    procedure radBurstClick(Sender: TObject);
    procedure radNormalClick(Sender: TObject);
    procedure rad8255Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmSetting: TfrmSetting;

implementation

uses MainForm;

{$R *.dfm}

procedure TfrmSetting.ButtonOKClick(Sender: TObject);
begin

     // save the data width
     if RadioDataWidth32.Checked then // 32-bit
        gdwDataWidth := 1
     else if RadioDataWidth16.Checked then //16-bit
        gdwDataWidth := 2
     else
        gdwDataWidth := 3;

     // save operation type
     if  radNormal.Checked then // normal
        gdwDOOperationMode := 0;
     if rad8255.Checked then // 8255
         gdwDOOperationMode := 1;
     if radBurst.Checked  then // burst
        gdwDOOperationMode := 2;

     // save the start type
     if RadioStartTypeSoftware.Checked then    // software
        gdwDOStartMode := 1;
     if RadioStartTypeExt.Checked then    // External
        gdwDOStartMode := 2;

     // save the stop type
     if RadioStopTypeSoftware.Checked then    // software
        gdwDOStopMode := 1;
     if RadioStopTypeExt.Checked then    // External
        gdwDOStopMode := 2;

     // save the cyclic mode
     if RadioCyclic.Checked then           // cyclic
        gdwCyclicMode := 1
     else
        gdwCyclicMode := 0;

     // save the trigger source
     gdwDOTriggerSource := ListBoxTriggerSource.ItemIndex + 1;

     // save the counter 0 value
     gdwCounterValue[0] := StrToInt(EditCounterValue.Text);

     // save the user bufer
     gdwUserbufferSize :=  ListBoxUserBuffer.ItemIndex;

     //txtDigitalValue
     gdwDigitalValue :=  StrToInt('$'+ txtDigitalValue.Text);

     // save DMA mode
     if gdwBoardId = BD_MIC3755 then
     begin
        if RadioDmaSlave.Checked then
           gdwDoDmaMode := 0
        else
           gdwDoDmaMode := 1
     end;

     Close;
end;

procedure TfrmSetting.FormShow(Sender: TObject);
begin
     // initialize data width
     if ( gdwDataWidth = 0 ) then// 32-bit
        RadioDataWidth32.Checked := TRUE
     else if ( gdwDataWidth = 1 ) then// 32-bit
        RadioDataWidth32.Checked := TRUE
     else if ( gdwDataWidth = 2 ) then // 16-bit
        RadioDataWidth16.Checked := TRUE
     else // 8-bit
        RadioDataWidth8.Checked := TRUE;

     // initialize start type
     if ( gdwDOStartMode = 1 ) then // software
        RadioStartTypeSoftware.Checked := TRUE;
     if ( gdwDOStartMode = 2 ) then // External
        RadioStartTypeExt.Checked := TRUE;

     // initialize operation type
     if ( gdwDOOperationMode = 0 ) then // normal
        radNormal.Checked := TRUE;
     if ( gdwDOOperationMode = 1 ) then // 8255
        rad8255.Checked := TRUE;
     if ( gdwDOOperationMode = 2 ) then // burst
        radBurst.Checked := TRUE;

     // initialize stop type
     if ( gdwDOStopMode = 1 ) then // software
        RadioStopTypeSoftware.Checked := TRUE ;
     if ( gdwDOStopMode = 2 ) then // External
        RadioStopTypeExt.Checked := TRUE;

     // initialize cycle mod
     if ( gdwCyclicMode = 0 ) then // nocyclic
        RadioNonCyclic.Checked := TRUE
     else
        RadioCyclic.Checked := TRUE;

     // initialize trigger source listbox
     ListBoxTriggerSource.ItemIndex := gdwDOTriggerSource - 1;

     // initialize counter 0 value
     EditCounterValue.Text := InttoStr(gdwCounterValue[0]);

     // initialize the user buffer
     ListBoxUserBuffer.ItemIndex := gdwUserBufferSize;

     // initialize DO DMA mode
     if gdwBoardId = BD_MIC3755 then
     begin
        if gdwDoDmaMode = 0 then
           RadioDmaSlave.Checked := true;
        if gdwDoDmaMode = 1 then
           RadioDmaMaster.Checked := true;
     end;

 
end;

procedure TfrmSetting.txtDigitalValueChange(Sender: TObject);
var
    lStart : Longint;
    lLength : Longint;
    DataSize : Longint;
    strHex : String;
begin

  //ound the Pattern Match value in 0 ~ FFFFFFFFh
     // save the data width
     if RadioDataWidth32.Checked then // 32-bit
        DataSize := 8
     else if RadioDataWidth16.Checked then //16-bit
        DataSize := 4
     else
        DataSize := 2;

  If (Length(txtDigitalValue.Text) > DataSize) Then
  begin
    //Out of value bound
    lStart := txtDigitalValue.SelStart;
    lLength := txtDigitalValue.SelLength;
    If lStart <> 0 Then lStart := lStart - 1;

    txtDigitalValue.Text := IntToHex(txtDigitalValue.Tag,DataSize);
    
    txtDigitalValue.SelStart := lStart;
    txtDigitalValue.SelLength := lLength  ;
  end;
  
  If (Length(txtDigitalValue.Text) = 0) Then
  begin
    // 0 Value
    txtDigitalValue.Text := '0';
    txtDigitalValue.SelStart := 0;
  end;

  // Valid Patterm Match value,write this new property value to device.
  strHex := '$' + txtDigitalValue.Text;
  lStart := StrToInt(strHex);
  txtDigitalValue.Tag := lStart;
end;

procedure TfrmSetting.txtDigitalValueKeyPress(Sender: TObject;
  var Key: Char);
var
  Asckey : BYTE;
  i      : Integer;

begin

  Asckey :=  BYTE(Key);



 If ((Asckey >= BYTE('0')) and (Asckey <= BYTE('9')) ) Then
    exit;

  If ( (Asckey >= BYTE('A')) And (Asckey <= BYTE('F')) ) Then
   exit;

  If ( (Asckey >= BYTE('a')) And (Asckey <= BYTE('f')) ) Then
  begin
      for i :=0 to (BYTE('a') - BYTE('A')-1) do
      begin
         Dec(Key);
      end;
       exit;
  end;


  Key := Low(Key);
end;

procedure TfrmSetting.radBurstClick(Sender: TObject);
begin
   if gdwBoardId = BD_PCI1755 then
      ListBoxTriggerSource.ItemIndex := 4;

   if gdwBoardId = BD_MIC3755 then
   begin
      RadioDmaSlave.Enabled := true;
      RadioDmaMaster.Enabled := true;
   end;

end;

procedure TfrmSetting.radNormalClick(Sender: TObject);
begin
   RadioDmaSlave.Enabled := false;
   RadioDmaMaster.Enabled := false;
end;

procedure TfrmSetting.rad8255Click(Sender: TObject);
begin
   RadioDmaSlave.Enabled := false;
   RadioDmaMaster.Enabled := false;
end;

end.

⌨️ 快捷键说明

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