串口问题(6分)

  • 主题发起人 主题发起人 coolingxyz
  • 开始时间 开始时间
C

coolingxyz

Unregistered / Unconfirmed
GUEST, unregistred user!
打开串口:<br>&nbsp; &nbsp; ComHdl := Createfile(<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pTpPort, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//串口名称或设备路径<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Generic_Read or Generic_Write, &nbsp; //读写方式<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //共享方式:独占<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; nil, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //认的安全描述符<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; open_existing, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //创建方式<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //不需设置文件属性<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//不需参照模板文件<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; );<br><br><br>关闭串口:<br>closehandle(ComHdl );<br><br><br>程序运行中,打开串口成功,关闭串口,再打开同一串口,再关闭串口……<br>有时提示打开串口失败。<br><br>但程序退出,重新打开又好了。这是怎么回事?<br><br>在程序运行过程中,我跟踪closehandle返回的是true的。<br><br><br>全部家产了。 &nbsp;;(
 
留个EMAIL下来,有个DEMO你瞧瞧吧
 
串口没有关闭的原因。<br>使用SPCOMM试一试很不错的。
 
已经解决了。
 
后退
顶部