请教COM口的设置问题(50分)

  • 主题发起人 主题发起人 xiaoyaozh
  • 开始时间 开始时间
X

xiaoyaozh

Unregistered / Unconfirmed
GUEST, unregistred user!
记得设置串口改变时要先将其关闭
下列事件被执行时提示错误
COMPORT IS ALREADY OPEN
哪里的问题?如何改?
procedure TForm1.ComboBox2Select(Sender: TObject);
var
Index:integer;//字符ASCII值
begin
index:=ComboBox2.ItemIndex+1;
if Mscomm1.PortOpen=true then Mscomm1.PortOpen:=false;
Mscomm1.CommPort:=index;
mscomm1.PortOpen:=true;
end;
 
调试跟踪一下就知道了
 
哦,注释;//字符ASCII值 是错误的,
INDEX代表COMBOBOX2被选的条目
TO Chenlili:
调过了,就是每到执行到mscomm1.PortOpen:=true;
的时候出错的
 
端口被其他程序占用或未能及时关闭,可延时再试一下
 
TO LGXing:
应该不会被其它程序占用,因为我就是在反复选择ComboBox2时提示的错误
为了调度这程序我专门做了一个小程序,上面只有COMM、ComboBox2
 
普通计算机上只有1和2口,你的index值为多少?
 
用下面的代码试一下吧,combox的itemindex输入1和2,我试了没问题
procedure TForm1.Button1Click(Sender: TObject);
var
Index:integer;//字符ASCII值
begin
index:=ComboBox2.ItemIndex+1;
if Mscomm1.PortOpen=true then
Mscomm1.PortOpen:=false;
showmessage(inttostr(index));
Mscomm.CommPort:=index;
mscomm.PortOpen:=true;

end;
 
应该是另外一个程序在用着你的串口,把其它程序都关了试试
 
接受答案了.
 
后退
顶部