W
www.0o0.com
Unregistered / Unconfirmed
GUEST, unregistred user!
var Fcomm: TFcomm; ViewString: String; i: Integer; //rbuf,sbuf:array[16] of byte; rbuf,sbuf: array[1..6] of byte;implementation{$R *.dfm}procedure TFcomm.FormShow(Sender: TObject);begin Comm1.StartComm;end;procedure TFcomm.FormClose(Sender: TObject; var Action: TCloseAction);begin Comm1.StopComm;end;procedure TFcomm.SendData;var i: integer; commflag: Boolean;begin ViewString := ''; commflag := True; For i:= 1 to 6 do begin if Not Fcomm.Comm1.WriteCommData(@sbuf, 1) then begin commflag := False; Break; end; Sleep(2); ViewString := ViewString + IntToHex(sbuf, 2) + ' '; end; ViewString := '发送' + ViewString; Fcomm.Memo1.Lines.Add(ViewString); Fcomm.Memo1.Lines.Add(''); if not commflag then MessageDlg('发送失败!', mtError, [mbYes], 0);end;procedure TFcomm.btn_SendClick(Sender: TObject);begin sbuf[1] := byte($f0); sbuf[2] := byte($01); sbuf[3] := byte($ff); sbuf[4] := byte($ff); sbuf[5] := byte($01); sbuf[6] := byte($f0); SendData;end;procedure TFcomm.Comm1ReceiveData(Sender: TObject; Buffer: Pointer; BufferLength: Word);var i: integer;begin ViewString := ''; //Move(buffer^, (Pchar(@rbuf))^,bufferLength); move(buffer^,rbuf,bufferlength); for i := 1 to bufferLength do ViewString := ViewString + IntToHex(rbuf, 2) + ' '; ViewString := '接受' + ViewString; Fcomm.Memo1.Lines.Add(ViewString); Memo1.Lines.Add(''); Memo1.Invalidate;end;应该显示的结果 memo1上显示发送 F0 01 FF FF 01 F0和接收到 F0 01 FF FF 01 F0我执行 只显示 发送 F0 01 FF FF 01 F0 没有显示 :接收到 F0 01 FF FF 01 F0好心人帮忙看看~· 谢谢了~·