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

📄 formrun.pas

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

interface

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

type
  Tfrmrun = class(TForm)
    CmdExit: TButton;
    GroupSample: TGroupBox;
    PictureBit0: Timage;
    PictureBit1: TImage;
    PictureBit2: TImage;
    PictureBit3: TImage;
    PictureBit4: TImage;
    PictureBit5: TImage;
    PictureBit6: TImage;
    PictureBit7: TImage;
    CmdBit0: TButton;
    CmdBit1: TButton;
    CmdBit2: TButton;
    CmdBit3: TButton;
    CmdBit4: TButton;
    CmdBit5: TButton;
    CmdBit6: TButton;
    CmdBit7: TButton;
    labBit0: TLabel;
    labBit1: TLabel;
    labBit2: TLabel;
    labBit3: TLabel;
    labBit4: TLabel;
    labBit5: TLabel;
    labBit6: TLabel;
    labBit7: TLabel;
    procedure CmdExitClick(Sender: TObject);
    procedure CmdBitClick(Sender: TObject);
    procedure PictureClick(Sender: TObject);
    procedure FormShow(Sender: TObject);

  private
    { Private declarations }
    DoValue : Integer;
    procedure UpdateLED(Bit : Integer ;  Mode : Boolean);
  public
    { Public declarations }
  end;

var
  frmrun: Tfrmrun;

implementation

uses formstar;

const
     LedON  = True;
     LedOFF = False;
var
   Response       : Integer;
{$R *.DFM}

Function DoBit(bit : Integer) : Integer;
var
  temp, i : Integer;
begin
  temp := 1;
  If bit >= 1 Then
    For i := 1 To bit do
      temp := temp * 2;
  DoBit := temp;
end;

procedure Tfrmrun.UpdateLED(Bit : Integer;  Mode : Boolean);
begin
     if Mode then
        DoValue := DoValue + DoBit(Bit)
     else
        DoValue := DoValue - DoBit(Bit);

     lpDioWritePort.port := lpDioPortMode.port;
     lpDioWritePort.mask := 255;
     lpDioWritePort.state := DoValue;
     ErrCde := DRV_DioWritePortByte(DeviceHandle, lpDioWritePort);
     If (ErrCde <> 0) Then
     begin
          DRV_GetErrorMessage(ErrCde, pszErrMsg);
          Response := Application.MessageBox(pszErrMsg, 'Error!!', MB_OK);
          Exit;
     end;
end;

procedure Tfrmrun.CmdExitClick(Sender: TObject);
begin
     frmRun.Close;
     Formstar.frmstart.Show;
end;

procedure Tfrmrun.CmdBitClick(Sender: TObject);
var
   tempBit : Integer;
begin
     tempBit := (Sender as TButton).Tag;
     UpdateLED(tempBit, LedON);
     (Sender as TButton).Visible := False;
     case tempBit of
          0 : PictureBit0.Visible := True;
          1 : PictureBit1.Visible := True;
          2 : PictureBit2.Visible := True;
          3 : PictureBit3.Visible := True;
          4 : PictureBit4.Visible := True;
          5 : PictureBit5.Visible := True;
          6 : PictureBit6.Visible := True;
          7 : PictureBit7.Visible := True;
     end;
end;

procedure Tfrmrun.PictureClick(Sender: TObject);
var
   tempBit : Integer;
begin
     tempBit := (Sender as TImage).Tag;
     UpdateLED(tempBit, LedOFF);
     (Sender as TImage).Visible := False;
     case tempBit of
          0 : CmdBit0.Visible := True;
          1 : CmdBit1.Visible := True;
          2 : CmdBit2.Visible := True;
          3 : CmdBit3.Visible := True;
          4 : CmdBit4.Visible := True;
          5 : CmdBit5.Visible := True;
          6 : CmdBit6.Visible := True;
          7 : CmdBit7.Visible := True;
     end;
end;

procedure Tfrmrun.FormShow(Sender: TObject);
var
     BitStatus : Smallint;
begin
     DoValue := 0;
     lpDioGetCurrentDOByte.port := lpDioPortMode.port;
     lpDioGetCurrentDOByte.value := @DoValue;
     ErrCde := DRV_DioGetCurrentDOByte(DeviceHandle, lpDioGetCurrentDOByte);
     If (ErrCde <> 0) Then
     begin
          DRV_GetErrorMessage(ErrCde, pszErrMsg);
          Response := Application.MessageBox(pszErrMsg, 'Error!!', MB_OK);
          Exit;
     end;

     BitStatus := DoValue and 1;
     if(BitStatus > 0) then
     begin
        PictureBit0.Visible := True;
        cmdBit0.Visible := False;
     end
     else
     begin
       PictureBit0.Visible := False;
       cmdBit0.Visible := True;
     end;

     BitStatus := DoValue and 2;
     if(BitStatus > 0) then
     begin
        PictureBit1.Visible := True;
        cmdBit1.Visible := False;
     end
     else
     begin
        PictureBit1.Visible := False;
        cmdBit1.Visible := True;
     end;

     BitStatus := DoValue and 4;
     if(BitStatus > 0)then
     begin
        PictureBit2.Visible := True;
        cmdBit2.Visible := False;
     end
     else
     begin
        PictureBit2.Visible := False;
        cmdBit2.Visible := True;
     end;
     BitStatus := DoValue and 8;
     if(BitStatus > 0)then
     begin
        PictureBit3.Visible := True;
        cmdBit3.Visible := False;
     end
     else
     begin
        PictureBit3.Visible := False;
        cmdBit3.Visible := True;
     end;
     BitStatus := DoValue and 16;
     if(BitStatus > 0)then
     begin
        PictureBit4.Visible := True;
        cmdBit4.Visible := False;
     end
     else
     begin
        PictureBit4.Visible := False;
        cmdBit4.Visible := True;
     end;

     BitStatus := DoValue and 32;
     if(BitStatus >0) then
     begin
        PictureBit5.Visible := True;
        cmdBit5.Visible := False;
     end
     else
     begin
        PictureBit5.Visible := False;
        cmdBit5.Visible := True;
     end;

     BitStatus := DoValue and 64;
     if(BitStatus >0 )then
     begin
        PictureBit6.Visible := True;
        cmdBit6.Visible := False;
     end
     else
     begin
        PictureBit6.Visible := False;
        cmdBit6.Visible := True;
     end;

     BitStatus := DoValue and 128;
     if(BitStatus >0) then
     begin
        PictureBit7.Visible := True;
        cmdBit7.Visible := False;
     end
     else
     begin
        PictureBit7.Visible := False;
        cmdBit7.Visible := True;
     end;

end;

end.

⌨️ 快捷键说明

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