adtcommimpl.~pas

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

~PAS
1,443
字号
    finally
      if (UpperCase(ExtractFileExt(FileName)) = '.BMP') then
        CloseFile(F)
      else
        FileClose(intHandle);//关闭文件
    end;
  except
    ShowMessage('连续写文件数据“' + FileName + '”时出错!');
  end;
end;

//结束写文件
function CloseFlie(Addr: string; var Success: Boolean; ComPort: TComPort): Boolean;
var
  strAnswer: string;
begin
  Result := False;
  Success := False;

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

      Result := True;
    end;
  except
    ShowMessage('结束写文件时出错!');
  end;
end;

//删除文件
function DelFile(Addr, FileName: string; var Success: Boolean; ComPort: TComPort): Boolean;
//FileName:不包括文件路径,是指下位机中非系统文件的名字
var
  strAnswer: string;
begin
  Result := False;
  Success := False;

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

      Result := True;
    end;
  except
    ShowMessage('删除文件时出错!');
  end;
end;

//格式化磁盘
function FormatDisk(Addr: TStrings; 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 (Application.MessageBox(PChar('您确实要格式化“' + Addr[i] + '”桌牌的磁盘吗?'),
        PChar(Application.Title), MB_YESNO + MB_ICONQUESTION) = IDYES) then
      begin
        if CommSend(Addr[i], '10', CmdFormat(Addr[i], '10', '', 0), strAnswer, ComPort) then
        begin
          if Copy(strAnswer, 1, 2) = '01' then//指令执行成功
            Success := True;

          Result := True;
        end
        else begin
          Result := False;
          Success := False;
          break;
        end;
      end;
    end;
  except
    ShowMessage('格式化磁盘时出错!');
  end;
end;

function SubDispSysInfo(Addr: TStrings; 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
      begin
        if CommSend(Addr[i], '08', CmdFormat(Addr[i], '08', Chr(1), 1), strAnswer, ComPort) then
        begin
          if Copy(strAnswer, 1, 2) = '01' then//指令执行成功
            Success := True;

          Result := True;
        end
        else begin
          Result := False;
          Success := False;
          break;
        end;
      end;
    end;
  except
    ShowMessage('副屏显示系统信息时出错!');
  end;
end;

function SubHideSysInfo(Addr: TStrings; 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
      begin
        if CommSend(Addr[i], '08', CmdFormat(Addr[i], '08', '', 0), strAnswer, ComPort) then
        begin
          if Copy(strAnswer, 1, 2) = '01' then//指令执行成功
            Success := True;

          Result := True;
        end
        else begin
          Result := False;
          Success := False;
          break;
        end;
      end;
    end;
  except
    ShowMessage('副屏隐藏系统信息时出错!');
  end;
end;

function SetAddr(Addr: string; var Success: Boolean; ComPort: TComPort): Boolean; //设置终端序号
var
  strAnswer: string;
begin
  Result := False;
  Success := False;

  try
    if CommSend('00', '01', CmdFormat('00', '01', Chr(StrToInt(Addr)), 1), strAnswer, ComPort) then
    begin
      Success := True;

      Result := True;
    end;
  except
    ShowMessage('设置终端序号“' + Addr + '”时出错!');
  end;
end;

//设置系统日期
function SetDate(Year, Month, Day, Week: integer; var Success: Boolean; ComPort: TComPort): Boolean;
//要求Year:以四位的格式
//Week:周日为0,依次类推
var
  intHigh, intLow: integer;
  strTemp, strAnswer: string;
begin
  Result := False;
  Success := False;

  try
    intHigh := (Year div 256);
    intLow := (Year mod 256);
    strTemp := Chr(intHigh) + Chr(intLow) + Chr(Month) + Chr(Day) + Chr(Week);

    if CommSend('00', '02', CmdFormat('00', '02', Chr(intHigh) + Chr(intLow) + Chr(Month) + Chr(Day) + Chr(Week), 5), strAnswer, ComPort) then
    begin
      Success := True;

      Result := True;
    end;
  except
    ShowMessage('设置系统日期时出错!');
  end;
end;

//设置系统时间
function SetTime(Hour, Minute, Second: integer; var Success: Boolean; ComPort: TComPort): Boolean;
var
  strAnswer: string;
begin
  Result := False;

  try
    if CommSend('00', '03', CmdFormat('00', '03', Chr(Hour) + Chr(Minute) + Chr(Second), 3), strAnswer, ComPort) then
    begin
      Success := True;

      Result := True;
    end;
  except
    ShowMessage('设置系统时间时出错!');
  end;
end;

//查询下位机是否在线
function IsOnline(Addr: string; var Success: Boolean; ComPort: TComPort): Boolean;
var
  strAnswer: string;
begin
  Result := False;

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

      Result := True;
    end;
  except
    ShowMessage('查询下位机是否在线时出错!');
  end;
end;

//指定当前发言人,ED的值为0或1,当为0时,取消下位机的当前发言人;=1时,为当前发言人
function SetCurSpokesman(Addr, ED: string; var Success: Boolean; ComPort: TComPort): Boolean;
var
  strAnswer: string;
begin
  Result := False;
  Success := False;

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

      Result := True;
    end;
  except
    ShowMessage('指定当前发言人时出错!');
  end;
end;

//主屏显示LOGO
function ShowLogo(Addr, FileName: string; var Success: Boolean; ComPort: TComPort): Boolean;
var
  strAnswer: string;
begin
  Result := False;
  Success := False;
  
  try
    if CommSend(Addr, '23', CmdFormat(Addr, '23', StrToValid(FileName), Length(FileName)), strAnswer, ComPort) then
    begin
      if Copy(strAnswer, 1, 2) = '01' then//指令执行成功
        Success := True;

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

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

  try
    if CommSend(Addr, '22', CmdFormat(Addr, '22', 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 ShowName(Addr, Name: string; var Success: Boolean; ComPort: TComPort): Boolean;
var
  strAnswer: string;
begin
  Result := False;
  Success := False;

  try
    if CommSend(Addr, '21', CmdFormat(Addr, '21', 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 ShowText(Addr, Text: string; x, y: integer; var Success: Boolean; ComPort: TComPort): Boolean;
var
  strAnswer: string;
begin
  Result := False;
  Success := False;

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

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

//设置开机LOGO
function SetBootLogo(Addr, FileName: string; var Success: Boolean; ComPort: TComPort): Boolean;
var
  strAnswer: string;
begin
  Result := False;
  Success := False;

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

      Result := True;
    end;
  except
    ShowMessage('设置开机LOGO时出错!');
  end;
end;

⌨️ 快捷键说明

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