com口出错,求助(20分)

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

xxljishiben

Unregistered / Unconfirmed
GUEST, unregistred user!
串口通讯用的是creatfile 函数 打开串口.<br>可是经常出现 串口打开失败的情况. 重启程序不管用.重启电脑又可以打开了!!!!<br>begin<br> &nbsp; &nbsp;dwShareMode:=0;<br> &nbsp;end;<br><br> &nbsp;m_hComm := CreateFile( &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//创建文件(串口),取得操作句柄<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PChar(sCommPort), &nbsp; &nbsp;//文件名称<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //'//./COM10',<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;GENERIC_READ or GENERIC_WRITE, &nbsp; &nbsp;//操作方式(读或写)<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;dwShareMode, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//共享方式<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nil, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //SD<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;OPEN_EXISTING, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//文件创建方法<br> FILE_ATTRIBUTE_NORMAL, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //文件属性<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //handle to template file
 
端口打开后没有正确释放,或者根本就没有释放
 
我用了CloseHandle(self.m_hComm); <br>不知道是不是释放不成功啊!!<br>有什么好的建议吗?<br>我正在调试!
 
能不能在打开串口前, 先关闭一次串口?<br>可是打开串口前, 定义的句柄是空的,不知道如何取得某个串口的地址,比如com1,能否不用句柄,直接关闭com1口?
 
可以采用 try catch语句试试
 
问题解决了,我换了台电脑就好了,是电脑的故障吧!对everhappy表示感谢!
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
I
回复
0
查看
633
import
I
后退
顶部