📄 com_send.pas
字号:
receive_count : integer;
receive_int : integer; // receivebuf_first_flag : boolean;
ft:pbyte; //字节指针
i:integer;
p: integer;
k:variant;
j:integer;
phone_get : string;// by hs
phonenum : string;
phone_flag : boolean; // by hs
//通道号,通道类型
channel,channel_type:integer;
version1,version2 : variant;
version1_str,version2_str : string;
//奇偶校验
function checksumtest:boolean;
var
i,n:integer;
sum:integer;
begin
sum := 0;
for i := 0 to 15 do
sum := sum + receivebuf_first[i];
if ( sum mod 256 ) = 0 then result := true
else result := false;
end;
//奇偶校验
function checksumtest_1:boolean;
var
i,n:integer;
sum:integer;
begin
sum := 0;
for i := 0 to 15 do
sum := sum + receivebuf_first[i];
if ( sum mod 256 ) = 0 then result := true
else result := false;
end;
function localqueue : boolean;
var i,j,k : integer;
begin
result := false;
while receivebuf_i > 15 do
begin
if ( receivebuf_first[0] = $55 ) and ( receivebuf_first[15] = $AA ) then
begin
k := 0 ;
for j := 0 to 15 do
begin
k := k + receivebuf_first[j] ;
end;
k := k mod 256 ;
if k = 0 then
begin
result := true;
exit;
end;
end;
LeftShiftRQueue(1);
end;
end;
}
var
x :integer;
ft:pbyte; //字节指针
sum : integer;
s : string;
k : integer;
info : string;
count_h : string;
count_l : string;
count : integer;
count_variant : variant;
count_s : string;
i : integer;
len : integer;
s1 : string;
begin
s1 := '';
sum := 0;
if comm1.DataCount > 0 then
begin
x := comm1.ReadInputByte(ft);
lalen.Caption := inttostr(x+1);
for i := 0 to x do
begin
receivebuf_first[i] := ft^;
s1 := s1 + ' ' + inttohex(ft^,2);
inc(ft);
end ;
memo2.Clear;
memo2.Lines.Add(s1);
end;
PurgeComm(comm1.Handle, PURGE_RXCLEAR); // 清除COM 数据
for i := 0 to x-1 do
sum := sum + receivebuf_first[i];
if sum <= 255 then sum:= sum
else if sum > 255 then
begin
s := inttohex(sum,2);
len := length(s);
s := '$' + copy(s,len-1,2);
sum := strtoint(s);
end;
if (receivebuf_first[0]<>0) then
begin
showmessage('第一个字节不为零!!');
exit;
end;
if (receivebuf_first[1]<>0) then
begin
showmessage('第二 个字节不为零!!');
exit;
end;
{
if sum <> receivebuf_first[x] then
begin
showmessage('校验和不对!!');
exit;
end;
}
if info_type = $20 then
begin
memo1.Clear;
memo1.Lines.add('栋地址: ' + inttostr(receivebuf_first[2]));
memo1.Lines.add('长度: ' + inttostr(receivebuf_first[3]));
memo1.Lines.add('板地址: ' + inttostr(receivebuf_first[4]));
for i := 1 to 8 do
begin
k := i*2+3;
count_h := inttohex(receivebuf_first[k],2);
count_l := inttohex(receivebuf_first[k+1],2);
count_s:= '$'+ count_h + count_l;
count_variant := count_s;
count := strtoint(count_s);
info := '电量: ' + inttostr(count);
memo1.Lines.Add(info);
end;
memo1.Lines.Add('完毕');
PurgeComm(comm1.Handle, PURGE_RXCLEAR); // 清除COM 数据
end;
if info_type = $21 then
begin
memo1.Clear;
memo1.Lines.add('栋地址: ' + inttostr(receivebuf_first[2]));
memo1.Lines.add('长度: ' + inttostr(receivebuf_first[3]));
memo1.Lines.add('板地址: ' + inttostr(receivebuf_first[4]));
for i := 1 to 8 do
begin
info := '状态' + inttostr(i) + ': ' + inttostr(receivebuf_first[i+4]) ;
info := info + ' 功率' + inttostr(i) + ': ' + inttostr(receivebuf_first[i+12]) ;
memo1.Lines.Add(info);
end;
memo1.Lines.Add('完毕');
PurgeComm(comm1.Handle, PURGE_RXCLEAR); // 清除COM 数据
end;
if info_type = $22 then
begin
memo1.Clear;
memo1.Lines.add('栋地址: ' + inttostr(receivebuf_first[2]));
memo1.Lines.add('长度: ' + inttostr(receivebuf_first[3]));
memo1.Lines.add('板地址: ' + inttostr(receivebuf_first[4]));
for i := 1 to 8 do
begin
info := '功限' + inttostr(i) + ': ' + inttostr(receivebuf_first[i+4]) ;
info := info + ' 差' + inttostr(i) + ': ' + inttostr(receivebuf_first[i+12]) ;
memo1.Lines.Add(info);
end;
info := '角度: ' + inttostr(receivebuf_first[21]);
memo1.Lines.Add(info);
info := '阻性: ' + inttostr(receivebuf_first[22]);
memo1.Lines.Add(info);
memo1.Lines.Add('完毕');
end;
if info_type = $23 then
begin
memo1.Clear;
memo1.Lines.add('栋地址: ' + inttostr(receivebuf_first[2]));
memo1.Lines.add('长度: ' + inttostr(receivebuf_first[3]));
memo1.Lines.add('板地址: ' + inttostr(receivebuf_first[4]));
memo1.Lines.add('角度1: ' + inttostr(receivebuf_first[5]));
memo1.Lines.add('角度2: ' + inttostr(receivebuf_first[6]));
memo1.Lines.add('角度3: ' + inttostr(receivebuf_first[7]));
memo1.Lines.add('角度4: ' + inttostr(receivebuf_first[8]));
memo1.Lines.add('角度5: ' + inttostr(receivebuf_first[9]));
memo1.Lines.add('角度6: ' + inttostr(receivebuf_first[10]));
memo1.Lines.add('角度7: ' + inttostr(receivebuf_first[11]));
memo1.Lines.add('角度8: ' + inttostr(receivebuf_first[12]));
memo1.Lines.Add('完毕');
PurgeComm(comm1.Handle, PURGE_RXCLEAR); // 清除COM 数据
end;
if info_type = $24 then
begin
memo1.Clear;
memo1.Lines.add('栋地址: ' + inttostr(receivebuf_first[2]));
memo1.Lines.add('长度: ' + inttostr(receivebuf_first[3]));
memo1.Lines.add('板地址: ' + inttostr(receivebuf_first[4]));
memo1.Lines.add('通道号: ' + inttostr(receivebuf_first[5]));
count_h := inttostr(receivebuf_first[6]);
count_l := inttostr(receivebuf_first[7]);
if length(count_h) = 1 then count_h := '0' + count_h ;
if length(count_l) = 1 then count_l := '0' + count_l ;
count_s:= count_h + count_l;
// count := strtoint(count_s);
info := '房号: ' + copy(count_s,1,1) + '-' + copy(count_s,2,3) ;
memo1.Lines.add(info);
count_h := inttohex(receivebuf_first[8],2);
count_l := inttohex(receivebuf_first[9],2);
count_s:= '$'+ count_h + count_l;
count := strtoint(count_s);
info := '电量: ' + inttostr(count);
memo1.Lines.add(info);
memo1.Lines.add('功率: ' + inttostr(receivebuf_first[10]));
memo1.Lines.add('功限: ' + inttostr(receivebuf_first[11]));
memo1.Lines.add('电量差: ' + inttostr(receivebuf_first[12]));
memo1.Lines.add('用电状态: ' + inttostr(receivebuf_first[13]));
memo1.Lines.add('角度: ' + inttostr(receivebuf_first[14]));
memo1.Lines.Add('完毕');
end;
if (info_type = $26 ) or (info_type = $27 )
or (info_type = $28 ) or (info_type = $29 )
or (info_type = $2A ) or (info_type = $2B )
or (info_type = $2C ) or (info_type = $2D )
or (info_type = $2E ) or (info_type = $31)
or (info_type = $32) then
begin
{
memo1.Clear;
memo1.Lines.add('长度: ' + inttostr(receivebuf_first[0]));
memo1.Lines.add('标志: ' + inttostr(receivebuf_first[1]));
memo1.Lines.Add('完毕');
}
{
info := '栋地址: ' + inttostr(receivebuf_first[2]) + #13
+ '长度: ' + inttostr(receivebuf_first[3]) + #13
+ '板地址: ' + inttostr(receivebuf_first[4]) + #13
+ '标志: ' + inttostr(receivebuf_first[5])+ #13 ;
}
if receivebuf_first[5] = $AA then
showmessage('接收回执错误');
if receivebuf_first[5] = $55 then
showmessage('OK');
end;
{
lalen.Caption := inttostr(receivebuf_i);
if comm1.DataCount > 0 then
begin
x := comm1.ReadInputByte(ft);
if receivebuf_i + x + 1 <= 4095 then
begin
for i := 0 to x do
begin
receivebuf_first[ receivebuf_i + i ] := ft^;
inc(ft);
end ;
receivebuf_i := receivebuf_i + x + 1;
end
else
begin
for i := 0 to 4095 do
receivebuf_first[i] := $00;
receivebuf_i := 0;
end;
end;
lalen.Caption := inttostr(x);
if localqueue = false then
begin
// LeftShiftRQueue(16);
exit;
end;
channel := receivebuf_first[1];
if ( channel = 26 ) then
begin
if receivebuf_first[2] = $00 then
begin
lastate.Caption := '就绪,测试已完成';
// receivebuf_i := 0;
receive_count := 0;
buSave.Enabled := true;
bustart.Enabled := true;
cbclear.Enabled := true;
btnagain.Enabled := true;
n8.Enabled := true;
nporttest.Enabled := true;
budown.Enabled := true;
clicktrue;
end
else if receivebuf_first[2] = $01 then
begin
lastate.Caption := '正在测试中';
buSave.Enabled := false;
bustart.Enabled := false;
cbclear.Enabled := false;
btnagain.Enabled := false;
n8.Enabled := false;
nporttest.Enabled := false;
end;
LeftShiftRQueue(16);
exit;
end;
if ( channel > 24 ) then
begin
LeftShiftRQueue(16);
exit;
end;
channel_type := receivebuf_first[2];
infotype := channel_type;
if checkstate[channel+1].Color = clgreen then
checkstate[channel+1].Color := 15916757;
case channel_type of // statestype: array[1..25] of TImage;
// statetext : array[1..25] of TLabel;
0: begin
statestype[channel+1].Canvas.draw(0,0,green);
phonenum := '';
//===============================================
for i := 3 to $d do
begin
if (chr(receivebuf_first[i]) >= #48 ) and (chr(receivebuf_first[i]) <= #57 ) then
phonenum := phonenum + chr(receivebuf_first[i])
else break;
end;
if trim(phonenum) = '' then
statetext[channel+1].Caption:='限拨'
else statetext[channel+1].Caption:='普话 '+phonenum;
k25[channel]:=0;
end;
1: begin
statestype[channel+1].Canvas.draw(0,0,red);
statetext[channel+1].Caption:='普话忙';
k25[channel]:=1;
end;
2: begin
statestype[channel+1].Canvas.draw(0,0,blue);
phonenum := '';
for i := 3 to $d do
phonenum := phonenum + chr(receivebuf_first[i]);
statetext[channel+1].Caption:='ADSL普话 ' + phonenum;
k25[channel]:=2;
end;
3: begin
statestype[channel+1].Canvas.draw(0,0,orange);
statetext[channel+1].Caption:='ADSL普话忙'; // statetext[channel+1].Width:=statetext[channel_type+1].Width+3;
k25[channel]:=3;
end;
4: begin // blue,green,orange,purple,red,yellow:tbitmap;
statestype[channel+1].Canvas.draw(0,0,purple);
statetext[channel+1].Caption:='ADSL专线,等待';
k25[channel]:=4;
end;
5: begin
statestype[channel+1].Canvas.draw(0,0,red);
statetext[channel+1].Caption:='ADSL专线,忙';
k25[channel]:=5;
end;
6: begin
statestype[channel+1].Canvas.draw(0,0,green);
statetext[channel+1].Caption:='短路(远方/局端)';
k25[channel]:=6;
end;
7: begin
statestype[channel+1].Canvas.draw(0,0,green);
statetext[channel+1].Caption:='短路(中部)';
k25[channel]:=7;
end;
8: begin
statestype[channel+1].Canvas.draw(0,0,blue);
statetext[channel+1].Caption:='短路(现场/测试端)';
k25[channel] := 8;
end;
9: begin
statestype[channel+1].Canvas.draw(0,0,purple);
statetext[channel+1].Caption:='空端子';
k25[channel] := 9;
end;
10: begin
statestype[channel+1].Canvas.draw(0,0,blue);
statetext[channel+1].Caption:='断路/空线对';
k25[channel] := 10;
end;
11: begin
statestype[channel+1].Canvas.draw(0,0,green);
statetext[channel+1].Caption:='ISDN';
k25[channel] := 11;
end;
12: begin
statestype[channel+1].Canvas.draw(0,0,green);
statetext[channel+1].Caption:='DDN专线';
k25[channel] := 12;
end;
13: begin
statestype[channel+1].Canvas.draw(0,0,green);
statetext[channel+1].Caption:='单根电话断';
k25[channel] := 13;
end;
253: begin
statestype[channel+1].Canvas.draw(0,0,green);
statetext[channel+1].Caption:='待测';
k25[channel] := 253;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -