C
cjh_xf
Unregistered / Unconfirmed
GUEST, unregistred user!
使用Spcomm控件接受数据,代码如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, SPComm;
type
TForm1 = class(TForm)
Comm1: TComm;
ComboBox1: TComboBox;
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Button2: TButton;
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
BufferLength: Word);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
S:String;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
Comm1.StartComm; //创建form1是打开控件
Memo1.Clear; //清空memo的内容
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
Comm1.StopComm;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
S:=Edit2.Text;
Comm1.WriteCommData(Pchar(S),Sizeof(S)); //发送数据
end;
procedure TForm1.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;BufferLength: Word);
var
S:String;
begin
SetLength(S,BufferLength); //接收RS232的数据并显示Memo1上。
Move(Buffer^,PChar(S)^,BufferLength);
Memo1.Lines.Add(S);
Memo1.Invalidate;
end;
end.
用上面的代码,发送数据可以(用别人的程序接受到了)。但不能接受数据,我已经没辙了!
我的Spcomm的设置如下:
BandRate 115200
ByteSize _8
ComName COM2
DsrSensitivity False
DtrControl DtrDisable
IgnorNullChar False
InX_XonXoffFlow False
Name Comm1
OutX_CtsFlow False
OutX_DsrFlow False
OutX_XonXoffFlow False
Parity None
ParityCheck False
ReadlnTervaltimeout 100
ReadTotaltimeConsTant 0
ReadTotaltimeMultipler 0
ReplaceChar #0
ReplaceWhcnParityError False
RtnControl RtsDisable
StopBits -1
Tag 0
TxcontinueOnXoff False
WriteTotaltimeConsTant 0
WriteTotaltimeMultipler 0
XoffChar #19
XoffLimit 500
Xonchar #17
XonLimit 500
哪位对此比较熟悉的,敬请指教!!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, SPComm;
type
TForm1 = class(TForm)
Comm1: TComm;
ComboBox1: TComboBox;
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Button2: TButton;
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
BufferLength: Word);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
S:String;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
Comm1.StartComm; //创建form1是打开控件
Memo1.Clear; //清空memo的内容
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
Comm1.StopComm;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
S:=Edit2.Text;
Comm1.WriteCommData(Pchar(S),Sizeof(S)); //发送数据
end;
procedure TForm1.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;BufferLength: Word);
var
S:String;
begin
SetLength(S,BufferLength); //接收RS232的数据并显示Memo1上。
Move(Buffer^,PChar(S)^,BufferLength);
Memo1.Lines.Add(S);
Memo1.Invalidate;
end;
end.
用上面的代码,发送数据可以(用别人的程序接受到了)。但不能接受数据,我已经没辙了!
我的Spcomm的设置如下:
BandRate 115200
ByteSize _8
ComName COM2
DsrSensitivity False
DtrControl DtrDisable
IgnorNullChar False
InX_XonXoffFlow False
Name Comm1
OutX_CtsFlow False
OutX_DsrFlow False
OutX_XonXoffFlow False
Parity None
ParityCheck False
ReadlnTervaltimeout 100
ReadTotaltimeConsTant 0
ReadTotaltimeMultipler 0
ReplaceChar #0
ReplaceWhcnParityError False
RtnControl RtsDisable
StopBits -1
Tag 0
TxcontinueOnXoff False
WriteTotaltimeConsTant 0
WriteTotaltimeMultipler 0
XoffChar #19
XoffLimit 500
Xonchar #17
XonLimit 500
哪位对此比较熟悉的,敬请指教!!