adtcommimpl.pas
来自「完成Linux下的串口程序,串口发送延时程序」· PAS 代码 · 共 1,221 行 · 第 1/3 页
PAS
1,221 行
begin
if Copy(strAnswer, 1, 2) = '01' then//指令执行成功
begin
Result := True;
Success := True;
continue;
end;
end
else begin
Result := False;
Success := False;
end;
end;
end
else begin
intHandle := FileOpen(FileName, fmOpenRead);//打开文件,获取文件句柄
while True do
begin
buf := '';
intNumRead := FileRead(intHandle, buf, High(buf) - Low(buf) + 1);//读取数据,获取读取数据的字节数
if intNumRead = 0 then//如果读取数据的字节数为0,则退出循环
Break;
if CommSend(Addr, '14', CmdFormat(Addr, '14', StrToValid(string(buf)), intNumRead), strAnswer, ComPort) then
begin
if Copy(strAnswer, 1, 2) = '01' then//指令执行成功
begin
Result := True;
Success := True;
continue;
end;
end
else begin
Result := False;
Success := False;
end;
end;
end;
finally
if (UpperCase(ExtractFileExt(FileName)) = '.BMP') then
CloseFile(F)
else
FileClose(intHandle);//关闭文件
end;
except
ShowMessage('连续写文件数据“' + FileName + '”时出错!');
end;
end;
}
//连续写文件数据
function WriteFlie(Addr, FileName: string; var Success: Boolean; ComPort: TComPort): Boolean;
var
i, j,k,m,n,intHandle, intNumRead, intBytes, intFileSize: Integer;
buf:array[0..30] of Char; //51
buf1:array[1..9] of Char;
strAnswer, strTemp: string;
strTail:integer;
strNewTail :char;
F: file of Byte;
debugstr:string;
begin
intHandle := 0;
Result := False;
Success := False;
intBytes := High(buf1) - Low(buf1) + 1;
strTail := 2;
strNewTail :=#0;
intHandle := FileOpen(FileName, fmOpenRead);//打开文件,获取文件句柄
while True do
begin
intNumRead := FileRead(intHandle, buf1, High(buf1) - Low(buf1) + 1);//读取数据,获取读取数据的字节数
if intNumRead = 0 then//如果读取数据的字节数为0,则退出循环
Break;
if CommSend(Addr, '14', CmdFormat(Addr, '14', StrToValid(string(buf1)), intNumRead), strAnswer, ComPort) then
begin
if Copy(strAnswer, 1, 2) = '01' then//指令执行成功
begin
Result := True;
Success := True;
continue;
end;
end
else
begin
Result := False;
Success := False;
end;
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;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?