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

📄 bocommatrix.pas

📁 博康矩阵控制协议
💻 PAS
字号:
unit BoComMatrix;
{
 AB矩阵控制协议.
}
interface

uses

  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, CPort;
type
  TCommandKind = (CmUnknow,CmInMenu,CmOutMenu,CmSwMonitor,CmSwCamera);
  TControlEvent = procedure(Sender: TObject; InfoMsg:string) of object;
  TBKMatrixComCtrl = class(Tcomponent)
  private
    FDeviceID:string;
    FDeviceName:string;
    FCommPort:string;
    FBaudRate:Dword;
    FComPort:TComPort;
    FMonitorID:integer;
    FCameraID:integer;
    FOnControlMsg:TControlEvent;
    FCurrentCmd:TCommandKind;
    FPTZSpeed:integer;
    FKeyBoardNo:integer;
    procedure SetCommPort(Value: string);
    procedure SetBaudRate(Value: Dword);
  protected
    FReceiveLen:integer;
    FSendBuf:array[0..255] of char;
    FReceiveBuf:array[0..511] of char;
    procedure CommReceiveData(Sender: TObject; Count: Integer);    
    function SendCommData(SendBuffer:array of char; const SendLength:Integer):Boolean;
  public
    //function LoginMenu:Boolean;
    //function LogOutMenu:Boolean;
   // procedure SwitchMonitor;
   // procedure SwitchCamera;
    procedure SwitchMonitorAndCamera;
    procedure MoveDown;
    procedure MoveUp;
    procedure MoveLeft;
    procedure MoveRight;
    procedure LevelStop;
    procedure VertStop;
    //procedure IrisOpen;             //光圈打开
    //procedure IrisClose;            //光圈关闭
    //procedure FocusFar;             //远焦控制
    //procedure FocusNear;            //近焦控制
    procedure ZoomWide;               //视角变宽
    procedure ZoomTele;               //视角变窄
    procedure ZoomHalt;
    constructor Create( AOwner: TComponent ); override;
    destructor Destroy; override;
    function ControlStart: boolean; //开始控制
    procedure ControlEnd;           //结束控制
    //--辅助控制命令
  published
    property MonitorID:integer read FMonitorID write FMonitorID;
    property CameraID:integer read FCameraID write FCameraID;
    property PTZSpeed:integer read FPTZSpeed write FPTZSpeed;
    property DeviceID:string read FDeviceID write FDeviceID;
    property KeyBoardNo:integer read FKeyBoardNo write FKeyBoardNo;
    property DeviceName:string read FDeviceName write FDeviceName;
    property ComPort:TComPort read FComPort Write FComPort;
    property CommPort:string read FCommPort write SetCommPort;
    property BaudRate:Dword read FBaudRate write SetBaudRate;
    property CurrentCmd:TCommandKind read FCurrentCmd;
    property OnControlMsg:TControlEvent read FOnControlMsg write FOnControlMsg; 

  end;

procedure Register;

implementation

uses Contnrs;

procedure Register;
begin
  RegisterComponents('GSMonitor', [TBKMatrixComCtrl]);
end;

{ TBKMatrixComCtrl }

procedure TBKMatrixComCtrl.SetCommPort(Value: string);
begin
  if  Value <> FCommPort then
  begin
    FCommPort := Value;
  end;
end;

procedure TBKMatrixComCtrl.SetBaudRate(Value: Dword);
begin
  if  Value <> FBaudRate then
  begin
    FBaudRate := Value;
  end;
end;

procedure TBKMatrixComCtrl.ControlEnd;
begin
  if FComPort.Connected then
    FComPort.Close;
end;

function TBKMatrixComCtrl.ControlStart: boolean;
var tmpResult : Boolean;
begin
  tmpResult := true;
  FComPort.BaudRate := brCustom;
  FComPort.CustomBaudRate := FBaudRate;
  FComPort.Port := FCommPort;
  FComPort.OnRxChar := CommReceiveData;
  try
    if not FComPort.Connected then
    FComPort.Open;
  except
    tmpResult := False;
  end;
  Result := tmpResult;
end;

constructor TBKMatrixComCtrl.Create(AOwner: TComponent);
begin
  inherited Create( AOwner );
  FReceiveLen := 0;
  FBaudRate := 1200;
end;

destructor TBKMatrixComCtrl.Destroy;
begin
  inherited Destroy;
end;

function TBKMatrixComCtrl.SendCommData(SendBuffer:array of char; const SendLength:Integer):Boolean;
begin
  Result := (FComPort.Write(SendBuffer,SendLength)= SendLength);
end;

procedure TBKMatrixComCtrl.CommReceiveData(Sender: TObject; Count: Integer);
var BufferLength:integer;
begin
end;

procedure TBKMatrixComCtrl.ZoomTele;
var
  tmpCmd:string;
begin
  //#0[@K=2],[★]回车符($0D)
  FillChar(FSendBuf,Sizeof(FSendBuf),0);
  tmpCmd := '#0[@K='+IntToStr(KeyBoardNo)+'],[h]'+Chr($0D);
  StrPCopy(FSendBuf, tmpCmd);
  SendCommData(FSendBuf,length(tmpCmd));
end;

procedure TBKMatrixComCtrl.ZoomWide;
var
  tmpCmd:string;
begin
  //#0[@K=2],[★]回车符($0D)
  FillChar(FSendBuf,Sizeof(FSendBuf),0);
  tmpCmd := '#0[@K='+IntToStr(KeyBoardNo)+'],[g]'+Chr($0D);
  StrPCopy(FSendBuf, tmpCmd);
  SendCommData(FSendBuf,length(tmpCmd));
end;

procedure TBKMatrixComCtrl.MoveDown;
var
  tmpCmd:string;
begin
  //#0[@K=2],[★]回车符($0D)
  FillChar(FSendBuf,Sizeof(FSendBuf),0);
  tmpCmd := '#0[@K='+IntToStr(KeyBoardNo)+'],[j'+IntToStr(PTZSpeed)+']'+Chr($0D);
  StrPCopy(FSendBuf, tmpCmd);
  SendCommData(FSendBuf,length(tmpCmd));
end;

procedure TBKMatrixComCtrl.MoveLeft;
var
  tmpCmd:string;
begin
  //#0[@K=2],[★]回车符($0D)
  FillChar(FSendBuf,Sizeof(FSendBuf),0);
  tmpCmd := '#0[@K='+IntToStr(KeyBoardNo)+'],[d'+IntToStr(PTZSpeed)+']'+Chr($0D);
  StrPCopy(FSendBuf, tmpCmd);
  SendCommData(FSendBuf,length(tmpCmd));
end;

procedure TBKMatrixComCtrl.MoveRight;
var
  tmpCmd:string;
begin
  //#0[@K=2],[★]回车符($0D)
  FillChar(FSendBuf,Sizeof(FSendBuf),0);
  tmpCmd := '#0[@K='+IntToStr(KeyBoardNo)+'],[c'+IntToStr(PTZSpeed)+']'+Chr($0D);
  StrPCopy(FSendBuf, tmpCmd);
  SendCommData(FSendBuf,length(tmpCmd));
end;

procedure TBKMatrixComCtrl.MoveUp;
var
  tmpCmd:string;
begin
  //#0[@K=2],[★]回车符($0D)
  FillChar(FSendBuf,Sizeof(FSendBuf),0);
  tmpCmd := '#0[@K='+IntToStr(KeyBoardNo)+'],[k'+IntToStr(PTZSpeed)+']'+Chr($0D);
  StrPCopy(FSendBuf, tmpCmd);
  SendCommData(FSendBuf,length(tmpCmd));
end;

procedure TBKMatrixComCtrl.SwitchMonitorAndCamera;
  var  tmpCmd:string;
begin
  {//--直连式
  FillChar(FSendBuf,Sizeof(FSendBuf),0);
  tmpCmd := '*0V'+IntToStr(MonitorID)+','+IntToStr(CameraID)+Chr($0D);
  StrPCopy(FSendBuf, tmpCmd);
  Result := FSendBuf;
  }
  //外部PC,#0[@K=2]M1.H,C1.回车符($0D)
  FillChar(FSendBuf,Sizeof(FSendBuf),0);
  tmpCmd := '#0[@K='+IntToStr(KeyBoardNo)+']M'+IntToStr(MonitorID)+'.H,C'+IntToStr(CameraID)+Chr($0D);
  StrPCopy(FSendBuf, tmpCmd);
  SendCommData(FSendBuf,length(tmpCmd));
end;

procedure TBKMatrixComCtrl.LevelStop;
var
  tmpCmd:string;
begin
  //#0[@K=2],[★]回车符($0D)
  FillChar(FSendBuf,Sizeof(FSendBuf),0);
  tmpCmd := '#0[@K='+IntToStr(KeyBoardNo)+'],[t]'+Chr($0D);
  StrPCopy(FSendBuf, tmpCmd);
  SendCommData(FSendBuf,length(tmpCmd));
end;

procedure TBKMatrixComCtrl.VertStop;
var
  tmpCmd:string;
begin
  //#0[@K=2],[★]回车符($0D)
  FillChar(FSendBuf,Sizeof(FSendBuf),0);
  tmpCmd := '#0[@K='+IntToStr(KeyBoardNo)+'],[y]'+Chr($0D);
  StrPCopy(FSendBuf, tmpCmd);
  SendCommData(FSendBuf,length(tmpCmd));
end;

procedure TBKMatrixComCtrl.ZoomHalt;
var
  tmpCmd:string;
begin
  //#0[@K=2],[★]回车符($0D)
  FillChar(FSendBuf,Sizeof(FSendBuf),0);
  tmpCmd := '#0[@K='+IntToStr(KeyBoardNo)+'],[o]'+Chr($0D);
  StrPCopy(FSendBuf, tmpCmd);
  SendCommData(FSendBuf,length(tmpCmd));
end;


end.

⌨️ 快捷键说明

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