我编一个串口的发送和接收问题,下面是我编写的一个程序,但是它不能发送跟接收,
你们帮我看一下错在哪!
var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
begin
comm1.StartComm;
end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
comm1.StopComm;
end;
//从端口发送数据
procedure TForm1.senddataClick(Sender: TObject);
var
str:pchar;
count:integer;
begin
str:=pchar(memo1.Text );
count:=length(str);
if comm1.writecommData(str,count)then
Memo1.Lines.Add('已发送'+inttostr(count)+'个字节')
else
raise exception.create('发送错误');
end;
//从端口接收数据procedure TForm1.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
BufferLength: Word);
var
strReceiv:string;
begin
setlength (strReceiv,Bufferlength);
move(Buffer^,Pchar(strReceiv)^,Bufferlength);
memo1.Lines.Add('已接收'+inttostr(Bufferlength)+'字节数据');
memo1.Lines.Add(strReceiv);
memo1.Invalidate;
end;
你们帮我看一下错在哪!
var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
begin
comm1.StartComm;
end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
comm1.StopComm;
end;
//从端口发送数据
procedure TForm1.senddataClick(Sender: TObject);
var
str:pchar;
count:integer;
begin
str:=pchar(memo1.Text );
count:=length(str);
if comm1.writecommData(str,count)then
Memo1.Lines.Add('已发送'+inttostr(count)+'个字节')
else
raise exception.create('发送错误');
end;
//从端口接收数据procedure TForm1.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
BufferLength: Word);
var
strReceiv:string;
begin
setlength (strReceiv,Bufferlength);
move(Buffer^,Pchar(strReceiv)^,Bufferlength);
memo1.Lines.Add('已接收'+inttostr(Bufferlength)+'字节数据');
memo1.Lines.Add(strReceiv);
memo1.Invalidate;
end;
解决方案 »
- serversocket 与多个clientsocket信息互发的例子,谁有?多线程的例子
- 深圳关外制造企业招erp开发人员
- 请问如何获得汉字拼音首码? -- 急!
- 关于如何在treeview中打出结点下的所有子结点。
- 如何将byte类型的数组两个字节合并成一个integer字而成为integer类型的数组?
- 怎么实现打印预览功能?
- 奇怪:关于TADOQuery的Active属性问题 ,急!!!
- 请教一下数据库问题```
- 兄弟们,windows下刻有什么办法知道当前cpu利用率?如何编程实现?
- 请问在发邮件的时候怎么检查邮件地址真假!有无正确的发到!
- BDE连接数据库??
- 如何在程序运行时显示设计的AdoConnection控件的数据库连接对话框??
BufferLength: Word);
var
strReceiv:string;
begin
setlength (strReceiv,Bufferlength);
move(Buffer^,strReceiv,Bufferlength);
memo1.Lines.Add('已接收'+inttostr(Bufferlength)+'字节数据');
memo1.Lines.Add(strReceiv);
memo1.Invalidate;
end;