龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > VC开发 >

VC学习:Windows CE下的串口通讯类(7)

时间:2009-12-30 15:42来源:未知 作者:admin 点击:
分享到:
//根据DCB结构配置端口 if (!SetCommState (hPort, PortDCB)) { //不能配置串行端口 MessageBox (NULL, TEXT("Unable to configure the serial port"), TEXT("Error"), MB_OK); dwError = GetLastEr
  //根据DCB结构配置端口

  if (!SetCommState (hPort, &PortDCB))
    
  {
    
  //不能配置串行端口

  MessageBox (NULL, TEXT("Unable to configure the serial port"),
  
  TEXT("Error"), MB_OK);
  
  dwError = GetLastError ();
  
  return FALSE;
  
  }
  
  return TRUE;
  
  }
  
  BOOL CSerial::InitCommTimeouts()
    
  {
  
  COMMTIMEOUTS CommTimeouts;
  
  DWORD dwError;
  
  //得到超时参数
  
  GetCommTimeouts (hPort, &CommTimeouts);
  
  //改变COMMTIMEOUTS结构设置

  CommTimeouts.ReadIntervalTimeout = MAXDWORD;
  
  CommTimeouts.ReadTotalTimeoutMultiplier = 0;
  
  CommTimeouts.ReadTotalTimeoutConstant = 0;
  
  CommTimeouts.WriteTotalTimeoutMultiplier = 10;
  
  CommTimeouts.WriteTotalTimeoutConstant = 1000;
  
  //设置端口超时值
  
  if (!SetCommTimeouts (hPort, &CommTimeouts))
  
  {
  
  //不能设置超时值
  
  MessageBox (NULL, TEXT("Unable to set the time-out parameters"),

  TEXT("Error"), MB_OK);
  
  dwError = GetLastError ();
  
  return FALSE;
  
  }
  
  return TRUE;
  
  }
  
  以上类代码在eMbedded Visual C++4.0和基于ARM9的三星S3C2410开发板(运行Windows CE.NET 4.1)上测试通过。

收藏文章
表情删除后不可恢复,是否删除
取消
确定
图片正在上传,请稍后...
评论内容为空!
还没有评论,快来抢沙发吧!
按钮 内容不能为空!
立刻说两句吧! 查看0条评论
精彩图集

赞助商链接