怎样从串口COM1中读取字符串?

yjq2000 2002-11-30 11:01:34
怎样从串口COM1中读取字符串?
...全文
87 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
KingOf007 2002-11-30
  • 打赏
  • 举报
回复
所以随便找一个能读串口的程序去读就行了,关键是读到之后的格式处理
KingOf007 2002-11-30
  • 打赏
  • 举报
回复
...不管要读的是什么,从串口中过来的都是0,1吧
hansion3406 2002-11-30
  • 打赏
  • 举报
回复
呵呵...直接对'COM1'文件读写就可以了..呵呵..


深宇 2002-11-30
  • 打赏
  • 举报
回复
在onReceiveData事件中获得端口数据,下面是我程序中的一段代码:
procedure TNiuka_inform.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
BufferLength: Word);
var
str,str1:string;
i,state,postion:integer;
rbuf:array [1..1024] of char;
begin
inherited;
try
begin
str:='';
state:=0;
str1:='';
postion:=0;
move(buffer^,pchar(@rbuf)^,bufferlength);
for i:=1 to bufferlength do
str:=str+rbuf[i];
for i:=1 to length(str) do
begin
if copy(str,i,1)=' 'then
begin
state:=state+1;
if state<2 then
postion:=i;
end;
if state=2 then
begin
str1:=copy(str,postion,i-postion);
break;
end;
end;
if edit16.Focused then
edit16.Text:=inttostr(strtoint(str1));
if edit17.Focused then
edit17.Text:=inttostr(strtoint(str1));
end;
except
on e:exception do
begin
showmessage(e.message);
end;
end;
end;
深宇 2002-11-30
  • 打赏
  • 举报
回复
你如果没有,我这里有一个,已经做好了安装包的,留个mail我发给你
深宇 2002-11-30
  • 打赏
  • 举报
回复
你已经有安装包了吗?就象普通的控件一样!
yjq2000 2002-11-30
  • 打赏
  • 举报
回复
to lzf1010(深宇)
怎么安装spcomm控件。
深宇 2002-11-30
  • 打赏
  • 举报
回复
用spcomm控件可以很好的解决这个问题
darkeye 2002-11-30
  • 打赏
  • 举报
回复
这取决与发向串口的程序。

5,386

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧