📄 recethr.~pas
字号:
end;
postmessage(fowner,WM_MESSAGE1,Msg_Pen,Msg_Pen_PRESENT);
result:=1;
end;
function TCommPen.TestPenLed:integer;
var
i1:integer;
f1,f2:FrameType;
begin
f1.add:=byte($eb);
f1.command:=byte($21);
f1.len:=byte($0);
CalcCrc(f1);
i1:=SendFrame(f1);
if i1<>4+f1.len then begin result:=-1;exit;end;
i1:=ReceFrame(f2);
if i1<>1 then begin result:=-2;exit;end;
if f2.command<>byte($80) then begin result:=-2;exit;end;
result:=1;
end;
function TCommPen.TestPenBell:integer;
var
i1:integer;
f1,f2:FrameType;
begin
f1.add:=byte($eb);
f1.command:=byte($20);
f1.len:=byte($0);
CalcCrc(f1);
i1:=SendFrame(f1);
if i1<>4+f1.len then begin result:=-1;exit;end;
i1:=ReceFrame(f2);
if i1<>1 then begin result:=-2;exit;end;
if f2.command<>byte($80) then begin result:=-2;exit;end;
result:=1;
end;
function TCommPen.ReadPenClock(var ye,mo,da,ho,mi,se:byte):integer;
var
i1:integer;
f1,f2:frametype;
begin
f1.add:=byte($eb);
f1.command:=byte($31);
f1.len:=byte($0);
CalcCrc(f1);
i1:=SendFrame(f1);
if i1<>4+F1.LEN then begin result:=-1;exit;end;
i1:=ReceFrame(f2);
if i1<>1 then begin result:=-2;exit;end;
if f2.command<>byte($32) then begin result:=-3;exit;end;
ye:=ByteHexToDec(f2.buff[0]);
mo:=ByteHexToDec(f2.buff[1]);
da:=ByteHexToDec(f2.buff[2]);
ho:=ByteHexToDec(f2.buff[3]);
mi:=ByteHexToDec(f2.buff[4]);
se:=ByteHexToDec(f2.buff[5]);
result:=1;
end;
function TCommPen.WritePenClock(ye,mo,da,ho,mi,se:integer):integer;
var
i1:integer;
f1,f2:FrameType;
begin
f1.add:=byte($eb);
f1.command:=byte($33);
f1.len:=byte($06);
f1.buff[0]:=ByteDecToHex(byte(ye mod 100));
f1.buff[1]:=ByteDecToHex(byte(mo mod 100));
f1.buff[2]:=ByteDecToHex(byte(da mod 100));
f1.buff[3]:=ByteDecToHex(byte(ho mod 100));
f1.buff[4]:=ByteDecToHex(byte(mi mod 100));
f1.buff[5]:=ByteDecToHex(byte(se mod 100));
CalcCrc(f1);
i1:=SendFrame(f1);
if i1<>4+f1.len then begin result:=-1;exit;end;
i1:=ReceFrame(f2);
if i1<>1 then begin result:=-2;exit;end;
if f2.command<>byte($80) then begin result:=-2;exit;end;
result:=1;
end;
function TCommPen.Read24c01(add,len:integer;var buff:array of byte):integer;
var
i1:integer;
f1,f2:frametype;
begin
f1.add:=byte($eb);
f1.command:=byte($35);
f1.len:=byte($02);
f1.buff[0]:=byte(add mod 256);
f1.buff[1]:=byte(len mod 256);
CalcCrc(f1);
i1:=SendFrame(f1);
if i1<>4+F1.LEN then begin result:=-1;exit;end;
i1:=ReceFrame(f2);
if i1<>1 then begin result:=-2;exit;end;
if f2.command<>byte($36) then begin result:=-3;exit;end;
for i1:=0 to f2.len-1 do
buff[i1]:=f2.buff[i1];
result:=1;
end;
function TCommPen.Write24c01(add,len:integer;const buff:array of byte):integer;
var
i1:integer;
f1,f2:frametype;
begin
f1.add:=byte($eb);
f1.command:=byte($37);
f1.len:=len+2;
f1.buff[0]:=byte(add MOD 256);
f1.buff[1]:=byte(len MOD 256);
for i1:=1 to len do
f1.buff[i1+1]:=buff[i1-1];
CalcCrc(f1);
i1:=SendFrame(f1);
if i1<>4+F1.LEN then begin result:=-1;exit;end;
i1:=ReceFrame(f2);
if i1<>1 then begin result:=-2;exit;end;
if f2.command<>byte($80) then begin result:=-3;exit;end;
result:=1;
end;
function TCommPen.Read24c256(add,len:Cardinal;var buff:array of byte):integer;
var
i1:integer;
f1,f2:frametype;
begin
f1.add:=byte($eb);
f1.command:=byte($39);
f1.len:=byte($03);
f1.buff[0]:=byte(add div 256);
f1.buff[1]:=byte(add mod 256);
f1.buff[2]:=byte(len mod 256);
CalcCrc(f1);
i1:=SendFrame(f1);
if i1<>4+F1.LEN then begin result:=-1;exit;end;
i1:=ReceFrame(f2);
if i1<>1 then begin result:=-2;exit;end;
if f2.command<>byte($3A) then begin result:=-3;exit;end;
for i1:=0 to f2.len-1 do
buff[i1]:=f2.buff[i1];
result:=1;
end;
function TCommPen.Write24C256(add,len:integer;const buff:array of byte):integer;
var
i1:integer;
f1,f2:frametype;
begin
f1.add:=byte($eb);
f1.command:=byte($3B);
f1.len:=len+3;
f1.buff[0]:=BYTE(add div 256);
f1.buff[1]:=byte(add mod 256);
f1.buff[2]:=len;
for i1:=1 to len do
f1.buff[i1+2]:=buff[i1-1];
CalcCrc(f1);
i1:=SendFrame(f1);
if i1<>4+F1.LEN then begin result:=-1;exit;end;
i1:=ReceFrame(f2);
if i1<>1 then begin result:=-2;exit;end;
if f2.command<>byte($80) then begin result:=-3;exit;end;
result:=1;
end;
constructor TTestPen.create(owner:thandle;Com1:Integer;FStB:TStatusBar;f1:byte;fdatep:strpointer);
begin
FTestmode:=f1;
fdatepointer:=fdatep;
inherited Create(OWNER,com1,fstb);
end;
function TTestPen.DoComm:integer;
var
i1,i2,icnt,ib,ie:integer;
s1:array [1..20] of byte;
y,m,d,hour,min,sec:byte;
date1,time1:tdatetime;
filetext:string;
testtime:tdatetime;
begin
testtime:=now;
FComm.PurgeOut;
FComm.PurgeIn;
i1:=0;
while true do //connect pen
begin
i2:=WakeupPen;
if i2=1 then break;
// fstring[1]:=INTTOSTR(I2);
// FUpdateItem:=1;
// SynChronize(UpdateStatusBar);
if i2=-1 then
begin
postmessage(fowner,WM_MESSAGE1,Msg_Comm,Msg_Comm_DeviceErr);
exit;
end;
sleep(200);
inc(i1);
if i1>10 then begin
postmessage(fowner,WM_MESSAGE1,Msg_Comm,Msg_Comm_comerror);
result:=-1;exit;end;
end;
i1:=0;
while true do //get pen code
begin
i2:=Read24C01(0,4,s1);
if i2=1 then break;
postmessage(fowner,WM_MESSAGE1,Msg_Pen,Msg_Pen_Offline);
sleep(200);
i2:=WakeupPen;
if i2<>1 then begin
postmessage(fowner,WM_MESSAGE1,Msg_Comm,Msg_Comm_DeviceErr);
result:=-2 ;exit; end;
inc(i1);
if i1>10 then begin
result:=-2;exit;end;
end;
postmessage(fowner,WM_MESSAGE1,Msg_PCode,s1[1]);
if (ftestmode and Test_DataCnt)<>0 then
begin
postmessage(fowner,WM_MESSAGE1,Msg_Pen,Msg_Pen_testdatacnt);
// i1:=0;
while true do //get pen data_counter
begin
i2:=Read24c01(8,8,s1);
if i2=1 then break;
postmessage(fowner,WM_MESSAGE1,Msg_Pen,Msg_Pen_Offline);
sleep(200);
i2:=WakeupPen;
if i2<>1 then begin
postmessage(fowner,WM_MESSAGE1,Msg_Comm,Msg_Comm_DeviceErr);
result:=-3 ;exit; end;
end;
icnt:=byte(s1[1])*256+byte(s1[2]);
iB:=byte(s1[3])*256+byte(s1[4]);
iE:=icnt+ib;//byte(s1[5])*256+byte(s1[6]);
if ((icnt+ib) mod 4096)=ie then
postmessage(fowner,WM_MESSAGE1,Msg_PDataCount,icnt)
else
postmessage(fowner,WM_MESSAGE1,Msg_Pen,Msg_Pen_DatacntERR);
end;
if ((ftestmode and test_time)<>0) then
begin
postmessage(fowner,WM_MESSAGE1,Msg_Pen,Msg_Pen_readtime);
while true do //get pen data_counter
begin
i2:=ReadPenClock(y,d,m,hour,min,sec);
if i2=1 then break;
postmessage(fowner,WM_MESSAGE1,Msg_Pen,Msg_Pen_Offline);
sleep(200);
i2:=WakeupPen;
if i2<>1 then begin
postmessage(fowner,WM_MESSAGE1,Msg_Comm,Msg_Comm_DeviceErr);
result:=-3 ;exit; end;
end;
try
//d:=17;
date1:=encodedate(2000+y,d,m);
time1:=encodetime(hour,min,sec,0);
fdatepointer^:='巡更棒時間:'+inttostr(2000+y)+'-'+inttostrl(d,2)+'-'+inttostrl(m,2)
+' '+inttostrl(hour,2)+':'+inttostrl(min,2)+':'+inttostrl(sec,2);
if ABS((date1+time1-date-time)*86400000)<300000 then
postmessage(fowner,WM_MESSAGE1,Msg_Pen,Msg_Pen_SetTimeSucc)
else
postmessage(fowner,WM_MESSAGE1,Msg_Pen,Msg_Pen_SetTimeFale);
except
filetext:='測試時間:'+formatdatetime('yyyy-mm-dd hh:mmm:ss',testtime);
WriteLog(filetext);
filetext:='時間格式不正確:';
WriteLog(filetext);
filetext:='巡更棒時間:'+inttostr(2000+y)+'-'+inttostrl(d,2)+'-'+inttostrl(m,2)+' '+inttostrl(hour,2)+':'+inttostrl(min,2)+':'+inttostrl(sec,2);
WriteLog(filetext);
fdatepointer^:='巡更棒時間格式不正確!';
{filetext:='測試時間:'+formatdatetime('yyyy-mm-dd hh:mmm:ss',testtime)+
char(13)+'時間格式不正確'+
char(13)+'巡更棒時間:'+inttostr(2000+y)+'-'+inttostrl(d,2)+'-'+inttostrl(m,2)+' '+inttostrl(hour,2)+':'+inttostrl(min,2)+':'+inttostrl(sec,2);
fdatepointer^:='巡更棒時間格式不正確!';
WriteLog(filetext);}
postmessage(fowner,WM_MESSAGE1,Msg_Pen,msg_pen_settimeformatfale);
end;
{ fstring[2]:='棒上時間';
fstring[2]:=fstring[2]+inttostr(2000+y)+'-'+inttostrl(d,2)+'-'+inttostrl(m,2);
fstring[2]:=fstring[2]+' '+inttostrl(hour,2)+':'+inttostrl(min,2)+':'+inttostrl(sec,2);}
// FUpdateItem:=2;
// SynChronize(UpdateStatusBar);
// postmessage(cowner,WM_MESSAGE1,Msg_Pen,Msg_Pen_ReadTimeSucc);
end;
if ((ftestmode and test_led)<>0) then
begin
// i1:=0;
postmessage(fowner,WM_MESSAGE1,Msg_Pen,Msg_Pen_testled);
while true do //test led
begin
i2:=TestPenLed;
if i2=1 then break;
postmessage(fowner,WM_MESSAGE1,Msg_Pen,Msg_Pen_Offline);
// sleep(200);
i2:=WakeupPen;
if i2<>1 then begin
postmessage(fowner,WM_MESSAGE1,Msg_Comm,Msg_Comm_DeviceErr); result:=-3 ;exit; end;
end;
end;
if ((ftestmode and test_bell)<>0) then
begin
postmessage(fowner,WM_MESSAGE1,Msg_Pen,Msg_Pen_testbell);
i1:=0;
while true do //test bell
begin
i2:=TestPenBell;
if i2=1 then break;
postmessage(fowner,WM_MESSAGE1,Msg_Pen,Msg_Pen_Offline);
sleep(200);
i2:=WakeupPen;
if i2<>1 then begin
postmessage(fowner,WM_MESSAGE1,Msg_Comm,Msg_Comm_DeviceErr); result:=-3 ;exit; end;
inc(i1);
if i1>10 then begin
postmessage(fowner,WM_MESSAGE1,Msg_Comm,Msg_Comm_comerror);
result:=-3;exit; end;
end;
end;
SLEEP(120);
result:=1;
end;
function TTestPen.PostComm:integer;
begin
end;
//===========================================
constructor Twritepenclock.create(owner:thandle;Com1:Integer;FStB:TStatusBar;f1,f2:tdatetime);
begin
fdate:=f1;
FTime:=f2;
inherited Create(OWNER,com1,fstb);
end;
function Twritepenclock.DoComm:integer;
var
i1,i2,icnt,ib,ie:integer;
s1,s2:array [1..20] of byte;
y,m,d,hour,min,sec,msec:word;
y1,m1,d1,hour1,min1,sec1,msec1:BYTE;
date1,time1:tdatetime;
begin
FComm.PurgeOut;
FComm.PurgeIn;
i1:=0;
while true do //connect pen
begin
i2:=WakeupPen;
if i2=1 then break;
if i2=-1 then
begin
postmessage(fowner,WM_MESSAGE1,Msg_Comm,Msg_Comm_DeviceErr);
exit;
end;
sleep(200);
inc(i1);
if i1>10 then begin
postmessage(fowner,WM_MESSAGE1,Msg_Comm,Msg_Comm_comerror);
result:=-1;exit;end;
end;
postmessage(fowner,WM_MESSAGE1,Msg_Pen,Msg_Pen_SetTime);
decodedate(fdate,y,m,d);
decodetime(ftime,hour,min,sec,msec);
i1:=0;
while true do
begin
i2:=WritePenClock(y,m,d,hour,min,sec);
if i2=1 then begin result:=1;break;end;
postmessage(fowner,WM_MESSAGE1,Msg_Pen,Msg_Pen_Offline);
sleep(350);
i2:=wakeuppen;
if i2=1 then continue;
sleep(2000);
i2:=wakeuppen;
if i2<>1 then begin
postmessage(fowner,WM_MESSAGE1,Msg_Comm,Msg_Comm_DeviceErr); result:=-2;exit;end;
inc(i1);
if i1>10 then begin result:=-2;exit;end;
end;
postmessage(fowner,WM_MESSAGE1,Msg_Pen,Msg_Pen_readtime);
while true do //get pen data_counter
begin
i2:=ReadPenClock(y1,d1,m1,hour1,min1,sec1);
if i2=1 then break;
postmessage(fowner,WM_MESSAGE1,Msg_Pen,Msg_Pen_Offline);
sleep(200);
i2:=WakeupPen;
if i2<>1 then begin
postmessage(fowner,WM_MESSAGE1,Msg_Comm,Msg_Comm_DeviceErr);result:=-3;exit;end;
end;
try
date1:=encodedate(2000+y1,d1,m1);
time1:=encodetime(hour1,min1,sec1,0);
if ABS((date1+time1-fdate-ftime)*86400000)<3000 then
postmessage(fowner,WM_MESSAGE1,Msg_Pen,Msg_Pen_SetTimeSucc)
else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -