spcomm 3.0 串口通信控件
使用示例: 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.
用户评论
XE10.2不能用
下来测试一下
很好用,可以在此基础上修改成自己需要的。谢谢
控件安装后能用,挺好的
控件装上了,没有环境测试,还不知道是否能用
TMD, 2.5既然欺骗3.0的,赚积分也不是这样的,
能接收,不能发送。。不知道问题出在什么地方了。。
接收数据后释放内存怎么有错误啊