Once with Delphi wrote a host computer

Source: Internet
Author: User

based on the Spcomm control. Source:Unit unit1; interface uses  windows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms,  dialogs, Stdctrls, Spcomm, Extctrls; type  tform1 = Class (TForm)      Comm1:TComm;    GroupBox1:TGroupBox;    go:TButton;     left:TButton;    right:TButton;    back:TButton;     left30:tbutton;    right30:tbutton;    yuan90: tbutton;    yuan360:tbutton;    groupbox2:tgroupbox;     Label5:TLabel;    Label6:TLabel;    Label7:TLabel;     Memo4:TMemo;    Memo5:TMemo;    Memo6:TMemo;     groupbox3:tgroupbox;    opencom:tbutton;    lianjie:Tbutton;    xinxi:tmemo;    procedure SendHex (s:string);     procedure Left30click (sender:tobject);     procedure OpencomClick (Sender:tobject) ;     procedure GoClick (Sender:tobject);     procedure BackClick (Sender: TObject);     procedure Commreceivedata (Sender:tobject; Buffer:pointer;  bufferlength:word);     procedure LeftClick (Sender:tobject);     procedure RightClick (Sender:tobject);     procedure W (sender:tobject; var Key:word; shift:tshiftstate);     procedure Formkeydown (Sender:tobject; var key:word;  shift: tshiftstate);     procedure formkeyup (Sender:tobject; var key:word;       shift:tshiftstate);   private    {Private Declarations}   Public    {Public declarations}  end; var  form1:tform1;  buf: string;  implementation {$R *.dfm}function Strtohex (Mstr:string;stlen:word):string;var     i:integer;begin    result:= ';     for I: = 1 to Stlen do     begin        if mstr[i]= #0 then             result:=result+ ' xx '          else         result:=result+inttohex (Ord (MStr[I ]), 2) + ";     end;end;  procedure Tform1.sendhex (s:string); VAR&NBSP;&NBSP;S2: STRING;&NBSP;&NBSP;BUF1:ARRAY[0..50000] of char;  i:integer;begin  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);  end; procedure Tform1.left30click (Sender:tobject); Begin  sendhex (' AA ');   //Send hex end;   procedure tform1.opencomclick (sender:tobject); begin   buf:= ' 0 ';    sendhex (BUF); if opencom. Caption = ' Open port ' then  begin  comm1.startcomm;   opencom. Caption: = ' off Port ';   endelse//if button1.caption = ' Close serial port ' then  begin  comm1.stopcomm;& Nbsp; opencom. Caption: = ' open port ';   end;end; procedUre Tform1.goclick (sender:tobject); begin  buf:= ' one ';   sendhex (BUF); end; procedure Tform1.backclick (sender:tobject); begin  buf:= ';   sendhex (BUF); end; procedure Tform1.leftclick (sender:tobject); begin  buf:= ';   sendhex (BUF); end; procedure Tform1.rightclick (sender:tobject); begin  buf:= ';   sendhex (BUF); end; procedure Tform1.commreceivedata (Sender:tobject; Buffer:pointer;  bufferlength:word); Var  strrecv:string;begin  setlength (strRecv , bufferlength);   move (Buffer^,pchar (STRRECV) ^,bufferlength);   xinxi. Lines.add (' Received: ' +inttostr (bufferlength) + ' bytes of data ');   xinxi. Lines.add (STRRECV);   xinxi. Invalidate, End;   procedure tform1.w (Sender:tobject; var Key:word; shift:tshiftstate); begin  buf:= ' one ';   sendhex (BUF); End; procedure TForm1.FormKeyDown ( Sender:tobject; var Key:word;  shift:tshiftstate); begin  if key=87 then     buf:= ' one ';       sendhex (BUF);   if key=83 then     buf:= ' 12 ';      sendhex (BUF);   if key=68 then     buf:= ' 13 ';      sendhex (BUF);   if key=65 then    buf:= ';  '     sendhex (BUF);    end;procedure tform1.formkeyup (Sender:tobject; var Key: word;  shift:tshiftstate); Begin    if key=87 then       sendhex (' ff ');     if key=65 then      sendhex (' ff ');    if key=68 then       sendhex (' ff ');    if Key= Then      sendhex (' ff '); end; end.

A host computer that was written by Delphi

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.