串口调试成功 yeah SPCOMM

 

 

采用了虚拟串口软件  (已经上传到CSDN了)

 

 

 

 

 

 

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, SPComm, TeEngine, Series, ExtCtrls, TeeProcs, Chart;

type
  TForm1 = class(TForm)
    Comm1: TComm;
    ComboBox1: TComboBox;
    ComboBox2: TComboBox;
    ComboBox3: TComboBox;
    ComboBox4: TComboBox;
    ComboBox5: TComboBox;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Button1: TButton;
    Memo1: TMemo;
    procedure Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
      BufferLength: Word);
    procedure Button1Click(Sender: TObject);
  
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  Viewstring:string;

  i:integer;

  rbuf,sbuf:array[1..6] of byte;

 

implementation

{$R *.dfm}

 

procedure TForm1.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
  BufferLength: Word);
var
  i:integer;

begin
  viewstring:=' ';

  move(buffer^,pchar(@rbuf)^,bufferlength);

  for i:=1 to bufferlength do

    viewstring:=viewstring+inttohex(rbuf[i],2)+' ';

  viewstring:='接受'+viewstring;

  memo1.lines.add(viewstring);

  memo1.lines.add(' ');


end;

procedure TForm1.Button1Click(Sender: TObject);
begin
//判断按键的状态可以便面打开串口出错时,要按两次按键
  if Button1.Caption = '打开串口' then
    begin

      // 串口初始化
      //EnumComPorts(ComboBox1.Items);//得到串口列表

      Comm1.CommName := ComboBox1.Text;

      Comm1.BaudRate := StrToInt(ComboBox2.Text);

      Comm1.Parity := None;  //ComboBox3.Text

      Comm1.ByteSize := _8;  //ComboBox4.Text

      Comm1.StopBits := _1;  //ComboBox5.Text
      //###########################################
      Comm1.StartComm;//打开串口
      Button1.Caption := '关闭串口';
      ComboBox1.Enabled := false;
      ComboBox2.Enabled := false;
      ComboBox3.Enabled := false;
      ComboBox4.Enabled := false;
      ComboBox5.Enabled := false;
      //btnSend.Enabled := true;
      //ImageOff.Visible := false;
      //ImageOn.Visible := true;
    end
  else
    begin
      //##############################################
      Comm1.StopComm;  // 关闭串口
      Button1.Caption := '打开串口';
      ComboBox1.Enabled := true;
      ComboBox2.Enabled := true;
      ComboBox3.Enabled := true;
      ComboBox4.Enabled := true;
      ComboBox5.Enabled := true;
      //btnSend.Enabled   := false;
      //ImageOn.Visible   := false;
      //ImageOff.Visible  := true;
    end;
end;

end.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 8
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值