adtcommimpl.~pas

来自「完成Linux下的串口程序,串口发送延时程序」· ~PAS 代码 · 共 1,443 行 · 第 1/4 页

~PAS
1,443
字号
//清除主屏显示
function ClearMainScreen(Addr: string; var Success: Boolean; ComPort: TComPort): Boolean;
var
  strAnswer: string;
begin
  Result := False;
  Success := False;

  try
    if CommSend(Addr, '20', CmdFormat(Addr, '20', '', 0), strAnswer, ComPort) then
    begin
      if Copy(strAnswer, 1, 2) = '01' then//指令执行成功
        Success := True;

      Result := True;
    end;
  except
    ShowMessage('清除主屏显示时出错!');
  end;
end;

function CloseMSCM(Addr: string; var Success: Boolean; ComPort: TComPort): Boolean;
var
  strAnswer: string;
begin
  Result := False;
  Success := False;

  try
    if CommSend(Addr, '2F', CmdFormat(Addr, '2F', '', 0), strAnswer, ComPort) then
    begin
      if Copy(strAnswer, 1, 2) = '01' then//指令执行成功
        Success := True;

      Result := True;
    end;
  except
    ShowMessage('关闭主屏客户模式时出错!');
  end;
end;

function CloseSSCM(Addr: string; var Success: Boolean; ComPort: TComPort): Boolean;
var
  strAnswer: string;
begin
  Result := False;
  Success := False;

  try
    if CommSend(Addr, '3F', CmdFormat(Addr, '3F', '', 0), strAnswer, ComPort) then
    begin
      if Copy(strAnswer, 1, 2) = '01' then//指令执行成功
        Success := True;

      Result := True;
    end;
  except
    ShowMessage('关闭副屏客户模式时出错!');
  end;
end;

//清除副屏显示
function ClearSubScreen(Addr: string; var Success: Boolean; ComPort: TComPort): Boolean;
var
  strAnswer: string;
begin
  Result := False;
  Success := False;

  try
    if CommSend(Addr, '30', CmdFormat(Addr, '30', '', 0), strAnswer, ComPort) then
    begin
      if Copy(strAnswer, 1, 2) = '01' then//指令执行成功
        Success := True;

      Result := True;
    end;
  except
    ShowMessage('清除副屏显示时出错!');
  end;
end;

//副屏显示姓名图片
function SubShowNameBMP(Addr, FileName: string; var Success: Boolean; ComPort: TComPort): Boolean;
var
  strAnswer: string;
begin
  Result := False;
  Success := False;

  try
    if CommSend(Addr, '32', CmdFormat(Addr, '32', StrToValid(FileName), Length(FileName)), strAnswer, ComPort) then
    begin
      if Copy(strAnswer, 1, 2) = '01' then//指令执行成功
        Success := True;

      Result := True;
    end;
  except
    ShowMessage('副屏显示姓名图片时出错!');
  end;
end;

//副屏显示姓名
function SubShowName(Addr, Name: string; var Success: Boolean; ComPort: TComPort): Boolean;
var
  strAnswer: string;
begin
  Result := False;

  try
    if CommSend(Addr, '31', CmdFormat(Addr, '31', StrToValid(Name), Length(Name)), strAnswer, ComPort) then
    begin
      if Copy(strAnswer, 1, 2) = '01' then//指令执行成功
        Success := True;

      Result := True;
    end;
  except
    ShowMessage('副屏显示姓名时出错!');
  end;
end;

//打开文本文件
function OpenTextFile(FileName: string; var Success: Boolean; ComPort: TComPort): Boolean;
var
  strAnswer: string;
begin
  Result := False;
  Success := False;

  try
    if CommSend('00', '33', CmdFormat('00', '33', StrToValid(FileName), Length(FileName)), strAnswer, ComPort) then
    begin
      if Copy(strAnswer, 1, 2) = '01' then//指令执行成功
        Success := True;

      Result := True;
    end;
  except
    ShowMessage('打开文本文件时出错!');
  end;
end;

//设置文本文件起始位置
function SetFilePos(FileName: string; Pos: integer; var Success: Boolean; ComPort: TComPort): Boolean;
var
  strAnswer: string;
begin
  Result := False;
  Success := False;

  try
    if CommSend('00', '34', CmdFormat('00', '34', Chr(Pos div 256) + Chr(Pos mod 256) + FileName, Length(FileName) + 2), strAnswer, ComPort) then
    begin
      if Copy(strAnswer, 1, 2) = '01' then//指令执行成功
        Success := True;

      Result := True;
    end;
  except
    ShowMessage('设置文本文件起始位置时出错!');
  end;
end;

//设置滚动速度
function SetScrollSpeed(Addr: TStrings; Speed: integer; var Success: Boolean; ComPort: TComPort): Boolean;
var
  i: integer;
  strAnswer: string;
begin
  Result := False;
  Success := False;

  try
    for i := 0 to Addr.Count - 1 do
    begin
      if CommSend(Addr[i], '35', CmdFormat(Addr[i], '35', Chr(Speed mod 256), 1), strAnswer, ComPort) then
      begin
        if Copy(strAnswer, 1, 2) = '01' then//指令执行成功
          Success := True;

        Result := True;
      end
      else begin
        Result := False;
        Success := False;
      end;
    end;
  except
    ShowMessage('设置滚动速度时出错!');
  end;
end;

//查询发言人文章起始地址
function GetManuPos(Addr: string; var Pos: integer; var Success: Boolean; ComPort: TComPort): Boolean;
var
  strAnswer: string;
begin
  Result := False;
  Success := False;

  try
    if CommSend(Addr, '36', CmdFormat(Addr, '36', '', 0), strAnswer, ComPort) then
    begin
      Pos := HexToInt(Copy(strAnswer, 1, 2)) * 256 + HexToInt(Copy(strAnswer, 3, 2));

      Success := True;
      Result := True;
    end;
  except
    ShowMessage('查询发言人文章起始地址时出错!');
  end;
end;

//准备倒计时
function PrepareCountDown(Addr: string; Minute, Second: integer; var Success: Boolean; ComPort: TComPort): Boolean;
var
  strAnswer: string;
begin
  Result := False;
  Success := False;

  try
    if CommSend(Addr, '37', CmdFormat(Addr, '37', Chr(Minute mod 256) + Chr(Second mod 256), 2), strAnswer, ComPort) then
    begin
      if Copy(strAnswer, 1, 2) = '01' then//指令执行成功
        Success := True;

      Result := True;
    end;
  except
    ShowMessage('准备倒计时出错!');
  end;
end;

//发言倒计时
function SpokesCountDown(Addr: string; Minute, Second: integer; var Success: Boolean; ComPort: TComPort): Boolean;
var
  strAnswer: string;
begin
  Result := False;
  Success := False;

  try
    if CommSend(Addr, '38', CmdFormat(Addr, '38', Chr(Minute mod 256) + Chr(Second mod 256), 2), strAnswer, ComPort) then
    begin
      if Copy(strAnswer, 1, 2) = '01' then//指令执行成功
        Success := True;

      Result := True;
    end;
  except
    ShowMessage('发言倒计时出错!');
  end;
end;

//发送消息
function SendMsg(Addr, Msg: string; var Success: Boolean; ComPort: TComPort): Boolean;
var
  strAnswer: string;
begin
  Result := False;
  Success := False;

  try
    if CommSend(Addr, '39', CmdFormat(Addr, '39', StrToValid(Msg), Length(Msg)), strAnswer, ComPort) then
    begin
      if Copy(strAnswer, 1, 2) = '01' then//指令执行成功
        Success := True;

      Result := True;
    end;
  except
    ShowMessage('发送消息时出错!');
  end;
end;

//副屏任意位置显示文字
function SubShowText(Addr, Text: string; x, y: integer; var Success: Boolean; ComPort: TComPort): Boolean;
var
  strHigh, strLow: string;
  strAnswer: string;
begin
  Result := False;
  Success := False;

  try
    if x > 255 then
    begin
      strHigh := '01';
      strLow := IntToHex(x mod 256, 2);
    end
    else begin
      strHigh := '00';
      strLow := IntToHex(x, 2);
    end;

    if CommSend(Addr, '3A', CmdFormat(Addr, '3A', Chr(x div 256) + Chr(x mod 256) + Chr(y mod 256) + Text, 3 + Length(Text)), strAnswer, ComPort) then
    begin
      if Copy(strAnswer, 1, 2) = '01' then//指令执行成功
        Success := True;

      Result := True;
    end;
  except
    ShowMessage('副屏任意位置显示文字时出错!');
  end;
end;

function SubDispAgendaList(Addr: string; var Success: Boolean; ComPort: TComPort): Boolean;//副屏显示议程清单
var
  strAnswer: string;
begin
  Result := False;
  Success := False;

  try
    if CommSend(Addr, '3B', CmdFormat(Addr, '3B', '', 0), strAnswer, ComPort) then
    begin
      if Copy(strAnswer, 1, 2) = '01' then//指令执行成功
        Success := True;

      Result := True;
    end;
  except
    ShowMessage('副屏显示议程清单时出错!');
  end;
end;

//轮询终端请求代码
function QueryRequest(Addr: string; var Answer: TStrings; var Success: Boolean; ComPort: TComPort): Boolean;
var
  strAnswer: string;
begin
  Result := False;
  Success := False;
  strAnswer := '';

  try
    if CommSend(Addr, '40', CmdFormat(Addr, '40', '', 0), strAnswer, ComPort) then
    begin
      while strAnswer <> '' do
      begin
        Answer.Add(Copy(strAnswer, 1, 2));

        strAnswer := Trim(Copy(strAnswer, 3, Length(strAnswer) - 2));
      end;

      Success := True;
    end;

    Result := True;
  except
    ShowMessage('轮询终端请求代码时出错!');
  end;
end;

end.

⌨️ 快捷键说明

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