控件spcomm
想法 :依次向串口1、2、3、4发测试数据
如果comm1收到回应比如:BB01000001dd 这时改一个全局就是havefound:='true'
但是明明收到了数也改了值,havefound还是说没变,就是:
if havefound<>;true' then
try
comm1.StopComm;
comm1.CommName:='com1';
comm1.StartComm;
sleep(100);
senddate('....');
except
end;
if havefound<>;true' then
try
comm1.StopComm;
comm1.CommName:='com2';
comm1.StartComm;
sleep(100);
senddate('....');
except
end;if havefound<>;true' then
try
comm1.StopComm;
comm1.CommName:='com3';
comm1.StartComm;
sleep(100);
senddate('....');
except
end;我明明连的com2上了,但是最后总是不能实现
想法 :依次向串口1、2、3、4发测试数据
如果comm1收到回应比如:BB01000001dd 这时改一个全局就是havefound:='true'
但是明明收到了数也改了值,havefound还是说没变,就是:
if havefound<>;true' then
try
comm1.StopComm;
comm1.CommName:='com1';
comm1.StartComm;
sleep(100);
senddate('....');
except
end;
if havefound<>;true' then
try
comm1.StopComm;
comm1.CommName:='com2';
comm1.StartComm;
sleep(100);
senddate('....');
except
end;if havefound<>;true' then
try
comm1.StopComm;
comm1.CommName:='com3';
comm1.StartComm;
sleep(100);
senddate('....');
except
end;我明明连的com2上了,但是最后总是不能实现
解决方案 »
- 请教:如何从一弹出窗体给另一窗体的ADOdataset或DBGRID赋值啊
- 调用部外部EXE程序.进度条????
- 循环问题.把我弄头晕了.
- 使用activex控件的程序,用户安装时,有什么特别要求,必须注册activex控件吗?
- 刚在网上下一套源码,2002年开发的, 可能是用D5写的吧,现在我用D7不能编译
- 在delphi中exe文件中调用delphi写的mydelphi.dll,mydelphi.dll调用vc写的myvc.dll出错
- 关于radiogroup控件
- 动态建立TADOQuery
- 组件代码中可以使用回调函数吗?
- 当我输入数据的位数超过9位的时候就出错,为什么????
- 向cgi提交数据
- Form如何获得焦点?
var
StartTick: Cardinal;if havefound <> true then
try
comm1.StopComm;
comm1.CommName:='com1';
comm1.StartComm;StartTick := GetTickCount;
while GetTickCount - StartTick < 200 do
Application.ProcessMessage;
senddate('....');
except
end;...
...
...
StartTick := GetTickCount;
while GetTickCount - StartTick < 200 do
Application.ProcessMessage;和sleep有不同的地方,我了不想了,我的代码:
procedure TMainForm.FormShow(Sender: TObject);
begin
writeini('comkou','');
setcom;
Comm1.StopComm;
end;procedure writeini(str,str1:string);
var
myinifile:tinifile;
comkou,version:string;
begin
MyIniFile := TIniFile.Create(ExtractFilePath(Application.ExeName )+'system.ini');
if str='comkou' then
MyIniFile.WriteString('system', 'comkou', str1);
if str='version' then
MyIniFile.WriteString('system', 'version', str1);
MyIniFile.Free;
end;procedure Setcom;
var
StartTick: Cardinal;
begin
if (readini('comkou') <> 'com1') and (readini('comkou') <> 'com2') and (readini('comkou') <> 'com3') and (readini('comkou') <> 'com4') then
try
mainform.comm1.StopComm;
mainform.comm1.CommName:='com1';
mainform.comm1.StartComm; sbuf[1]:=byte($EB); //帧头
sbuf[2]:=byte($06); //命令号
sbuf[3]:=byte($00);
sbuf[4]:=byte($00);
sbuf[5]:=byte($06);
sbuf[6]:=byte($BB);
sleep(100);
senddata(6);
StartTick := GetTickCount;
while GetTickCount - StartTick < 200 do
Application.ProcessMessages; except
end;
if (readini('comkou') <> 'com1') and (readini('comkou') <> 'com2') and (readini('comkou') <> 'com3') and (readini('comkou') <> 'com4') then
try
mainform.comm1.StopComm;
mainform.comm1.CommName:='com2';
mainform.comm1.StartComm; sbuf[1]:=byte($EB); //帧头
sbuf[2]:=byte($06); //命令号
sbuf[3]:=byte($00);
sbuf[4]:=byte($00);
sbuf[5]:=byte($06);
sbuf[6]:=byte($BB);
sleep(100);
senddata(6);
StartTick := GetTickCount;
while GetTickCount - StartTick < 200 do
Application.ProcessMessages;
except
end;if (readini('comkou') <> 'com1') and (readini('comkou') <> 'com2') and (readini('comkou') <> 'com3') and (readini('comkou') <> 'com4') then
try
mainform.comm1.StopComm;
mainform.comm1.CommName:='com3';
mainform.comm1.StartComm; sbuf[1]:=byte($EB); //帧头
sbuf[2]:=byte($06); //命令号
sbuf[3]:=byte($00);
sbuf[4]:=byte($00);
sbuf[5]:=byte($06);
sbuf[6]:=byte($BB);
sleep(100);
senddata(6);
StartTick := GetTickCount;
while GetTickCount - StartTick < 200 do
Application.ProcessMessages;
except
end;if (readini('comkou') <> 'com1') and (readini('comkou') <> 'com2') and (readini('comkou') <> 'com3') and (readini('comkou') <> 'com4') then
try
mainform.comm1.StopComm;
mainform.comm1.CommName:='com4';
mainform.comm1.StartComm; sbuf[1]:=byte($EB); //帧头
sbuf[2]:=byte($06); //命令号
sbuf[3]:=byte($00);
sbuf[4]:=byte($00);
sbuf[5]:=byte($06);
sbuf[6]:=byte($BB);
sleep(100);
senddata(6);
StartTick := GetTickCount;
while GetTickCount - StartTick < 200 do
Application.ProcessMessages;
except
end;
end;//这样就得到了一个System文件
[system]
comkou=com2
当下关comm1哪个窗体用时再开
procedure Tdaanform.FormShow(Sender: TObject);
var i:integer;
begin
Comm1.CommName:=readini('comkou');
Comm1.StartComm;
end;