写一个程序从两台串口通讯机器中读取数据,读取完成后关闭两个串口时出现问题了,消息:Exception EAccessViolation in module ntdll.dll at 007c48A. Access violation at address 77D0C48A in module 'ntdll.dll'. Read of address C000011F.
这个问题有时出现,有时没有,如果脱离delphi运行,情况是程序死掉。
Spcomm3.1 的下载地址:http://dldx.csdn.net/fd.php?i=259265203397239&s=475d682705f35f6a39ac0366fe502f9e
部分程序代码:【两个串口的设置在开始时从ini文件中读取了】。
procedure TForm1.Button3Click(Sender: TObject);
Var
S:string;
begin
with COMPF9811 do
begin
try
OnReceiveError := PFReceiveError;
OnReceiveData := PFReceiveData;
StopComm;
StartComm;
except
on E: Exception do
begin
showmessage('PF9811'+E.Message)
end;
end;
end;
with COMMaynuo do
begin
try
OnReceiveError := MNReceiveError;
OnReceiveData := MNReceiveData;
StopComm;
StartComm;
except
on E: Exception do
begin
showmessage('Maynuo'+E.Message)
end;
end;
end;
if (COMMaynuo.Connected) then
begin
S:='01050500FF008CF6';
COMMaynuo.WriteCommData(@Hexstrtostr(S)[1],length(Hexstrtostr(S))); //PC1=1
sleep(20);
S:='01050501FF00DD36';
COMMaynuo.WriteCommData(@Hexstrtostr(S)[1],length(Hexstrtostr(S))); //PC2=1
Delay(20);
end;
end;
procedure TForm1.Button8Click(Sender: TObject);
Var
S:string;
begin
if ComPF9811.Connected then
COMPF9811.StopComm;
if COMMaynuo.Connected then
begin
S:=Hexstrtostr('010505000000CD06');
COMMaynuo.WriteCommData(@S[1],length(S)); //PC1=0
Delay(40);
S:=Hexstrtostr('0105050100009CC6');
COMMaynuo.WriteCommData(@S[1],length(S)); //PC2=0
Delay(200);
//commaynuo.free;
COMMaynuo.StopComm;
end;
end;