|
1.png (7.36 KB, 下載次數(shù): 53)
下載附件
2022-7-5 15:04 上傳
指令集為:
實習(xí)期附件不能傳大,主要代碼
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, SPComm, StdCtrls;
const
sStatyArry :array [0..3] of string=('01 06 00 00 00 01 48 0A',
'01 06 00 00 00 02 08 0B',
'01 06 00 00 00 03 C9 CB',
'01 06 00 00 00 04 88 09') ;
sButtonArry :array [0..3] of string=('01 06 00 01 00 01 19 CA',
'01 06 00 01 00 02 59 CB',
'01 06 00 01 00 03 98 0B',
'01 06 00 01 00 04 D9 C9') ;
procedure TForm1.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
BufferLength: Word);
var
iTmp, I, StrLenght : Integer;
ViewString,ViewChar, sTmp, sTmp1 : string;
rbuf : array[1..1000] of byte;
rbufChar : array[1..1000] of Char;
MS : TMemoryStream;
begin
// BufferLength := Sizeof(rbuf);
ViewString := '';
Move(Buffer^, PChar(@rbuf)^, BufferLength);
for I := 1 to BufferLength do begin
ViewString := ViewString + IntToHex(rbuf[I-1],2)+'';
end;
ViewString:=Trim(ViewString);
if ViewString ='000101' then
begin
Memo1.Lines.Add('connect sucuss');
end
else
begin
Memo1.Lines.Add('receive data:'+#13#10+'----------------------'+#13#10+ViewString+#13#10+'----------------------'+#13#10+FormatDateTime('YYYY-MM-DD hh:mm:ss',Now));
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
SendHex(sStatyArry[0]);
end;
procedure TForm1.SendHex(S: String);
var
s2:string;
buf1:array[0..50000] of char;
i:integer;
begin
if not bOpen then
begin
Memo1.Lines.Add('send data failed!,pls connect;');
Exit;
end;
s2:='';
for i:=1 to length(s) do
begin
if ((copy(s,i,1)>='0') and (copy(s,i,1)<='9'))or((copy(s,i,1)>='a') and (copy(s,i,1)<='f'))
or((copy(s,i,1)>='A') and (copy(s,i,1)<='F')) then
begin
s2:=s2+copy(s,i,1);
end;
end;
for i:=0 to (length(s2) div 2-1) do
buf1[ i]:=char(strtoint('$'+copy(s2,i*2+1,2)));
Comm1.WriteCommData(buf1,(length(s2) div 2));
Memo1.Lines.Add('send data:'+#13#10+'----------------------'+#13#10+s+#13#10+'----------------------'+#13#10+FormatDateTime('YYYY-MM-DD hh:mm:ss',Now));
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
Comm1.StopComm;
Button1.Enabled:=True;
Button3.Enabled:=False;
bOpen:=False;
end;
|
評分
-
查看全部評分
|