⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.pas

📁 交个朋友. 质量越高得到的下载个数越多(一般为200:上载5个
💻 PAS
字号:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, OleCtrls, MSCommLib_TLB,mscomdlg_tlb;

type
  TForm1 = class(TForm)
    Comm1: TMSComm;
    Edit1: TEdit;
    Button1: TButton;
    Button2: TButton;
    Timer1: TTimer;
    Edit2: TEdit;
    flatmemo1: TMemo;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
   senddata:array[1..10] of char;
  reData:array of Variant;
  sendstr:string;
  restr:string;
  i:integer;
  bzw:boolean ;
implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin


begin
  comm1.CommPort := 1;                    //指定端口
  comm1.Settings := '9600,N,8,1';        //其它参数
  comm1.InBufferSize := 1024;             //接收缓冲区
  comm1.OutBufferSize := 1024;            //发送缓冲区
  comm1.InputMode := comInputModeBinary;  //接收模式
  comm1.InputLen := 0;                    //一次读取所有数据
  comm1.SThreshold := 0;                  //一次发送所有数据
  comm1.InBufferCount := 0;               //清空读取缓冲区
  comm1.OutBufferCount := 0;              //清空发送缓冲区
  comm1.PortOpen:=true;                     //打开端口
  comm1.RThreshold := 16;               //设置接收多少字节开产生oncomm事件
  senddata[1]:=chr($06);                          //要发送的数据
  senddata[2]:=chr($03);
  senddata[3]:=chr($00);
  senddata[4]:=chr($03);
  senddata[5]:=chr($10);
  sendstr:='';
  for i:=1 to 5   do
  sendstr:=sendstr + senddata[i];
  comm1.output:=sendstr;                       //发送数据
  i:=0;
  bzw:=false;

  repeat
     sleep(10);
    Application.ProcessMessages;
    i := i + 1;
    If i > 30000 Then
      begin
        showmessage('发送超时!');
        break;
      end;
  Until bzw = true;
  redata:=comm1.Input;      // 接收数据
  restr:='';
  for i:=0 to vararrayhighbound(redata,1) do
      restr:=restr + inttohex(redata[i],2)+' ';
  comm1.PortOpen:=false;
  flatmemo1.Text:=restr;
end;
//procedure TForm1.msComm1Comm(Sender: TObject);
//begin
  //case Comm1.CommEvent of
    //comEvReceive: bzw := true;
  //end;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -