




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、串行设备驱动第1页,共35页,2022年,5月20日,6点1分,星期日主要内容1、Windows CE.net串行设备简介2、串口设备驱动3、串行设备API简介4、串口设备操作5、红外设备简介第2页,共35页,2022年,5月20日,6点1分,星期日1、Windows CE.net串行设备简介第3页,共35页,2022年,5月20日,6点1分,星期日Windows CE.net串行设备Windows CE.net的串行设备应用十分广泛GPRS通信智能数据终端GPS定位系统红外通讯设备第4页,共35页,2022年,5月20日,6点1分,星期日使用通用码流进行数据传输,与标准串口完全兼容支持3线/
2、9线串口方式串口模型基本延续了桌面系统的风格和基本的API,但未封装成类第5页,共35页,2022年,5月20日,6点1分,星期日串口的7层结构第6页,共35页,2022年,5月20日,6点1分,星期日第7页,共35页,2022年,5月20日,6点1分,星期日Netarm2410-S串行设备情况UART0(3线) 标准格式化信息输出串口;基本通讯串口UART1(3线) 基本通讯串口(未使用)UART2(3线) 红外通讯串口;基本通讯串口第8页,共35页,2022年,5月20日,6点1分,星期日2、串口设备驱动第9页,共35页,2022年,5月20日,6点1分,星期日串口设备驱动是一种流驱动BS
3、P中提供的串口驱动模型较为复杂,在结构上也分层为MDD和PDD层第10页,共35页,2022年,5月20日,6点1分,星期日第11页,共35页,2022年,5月20日,6点1分,星期日第12页,共35页,2022年,5月20日,6点1分,星期日3、串行设备API简介第13页,共35页,2022年,5月20日,6点1分,星期日串口的APICreateFileOpens a serial port.GetCommStateFills in a device-control block DCB structure with the current control settings for a spe
4、cified communication device.SetCommStateConfigures a communication device according to the specifications in a DCB structure. The function reinitializes all hardware and control settings, but does not empty I/O queues.GetCommTimeoutsRetrieves the time-out parameters for all read/write operations on
5、a specified communication device.SetCommTimeoutsSets the time-out parameters for all read/write operations on a specified communication device.WriteFileWrites data to a serial port, which transfers data to the device at the other end of a serial connection.ReadFileReads data from a serial port, whic
6、h receives data from a device at the other end of a serial connection.第14页,共35页,2022年,5月20日,6点1分,星期日串口的APISetCommMaskSpecifies a set of events to monitor for a communication device.GetCommMaskRetrieves the value of the event mask for a specified communication device.WaitCommEventWaits for an event t
7、o occur for a specified communication device. The set of events monitored by WaitCommEvent is contained in the event mask associated with the device handle.EscapeCommFunctionDirects a specified communication device to perform an extended function. Often used to set a serial port to IR mode.ClearComm
8、BreakRestores character transmission for a specified communication device and places the transmission line in a non-break state.ClearCommErrorRetrieves communication error data and reports the current status of a specified communication device.第15页,共35页,2022年,5月20日,6点1分,星期日4、串口设备操作第16页,共35页,2022年,5月
9、20日,6点1分,星期日打开串口/ Open the serial port. hPort = CreateFile (lpszPortName, / Pointer to the name of the port GENERIC_READ | GENERIC_WRITE, / Access (read-write) mode 0, / Share mode NULL, / Pointer to the security attribute OPEN_EXISTING,/ How to open the serial port 0, / Port attributes NULL); / Han
10、dle to port with attribute / to copy第17页,共35页,2022年,5月20日,6点1分,星期日配置串口/ Initialize the DCBlength member. PortDCB.DCBlength = sizeof (DCB); / Get the default port setting information.GetCommState (hPort, &PortDCB);/ Change the DCB structure settings.PortDCB.BaudRate = 9600; / Current baud PortDCB.fBi
11、nary = TRUE; / Binary mode; no EOF check PortDCB.fParity = TRUE; / Enable parity checking PortDCB.fOutxCtsFlow = FALSE; / No CTS output flow control PortDCB.fOutxDsrFlow = FALSE; / No DSR output flow control PortDCB.fDtrControl = DTR_CONTROL_ENABLE; / DTR flow control type PortDCB.fDsrSensitivity =
12、FALSE; / DSR sensitivity PortDCB.fTXContinueOnXoff = TRUE; / XOFF continues Tx PortDCB.fOutX = FALSE; / No XON/XOFF out flow control PortDCB.fInX = FALSE; / No XON/XOFF in flow control PortDCB.fErrorChar = FALSE; / Disable error replacement PortDCB.fNull = FALSE; / Disable null stripping PortDCB.fRt
13、sControl = RTS_CONTROL_ENABLE; / RTS flow control PortDCB.fAbortOnError = FALSE; / Do not abort reads/writes on errorPortDCB.ByteSize = 8; / Number of bits/byte, 4-8 PortDCB.Parity = NOPARITY; / 0-4=no,odd,even,mark,space PortDCB.StopBits = ONESTOPBIT; / 0,1,2 = 1, 1.5, 2 / Configure the port accord
14、ing to the specifications of the DCB structure.if (!SetCommState (hPort, &PortDCB) / Could not configure the serial port. dwError = GetLastError (); MessageBox (hMainWnd, TEXT(Unable to configure the serial port), TEXT(Error), MB_OK); return FALSE;第18页,共35页,2022年,5月20日,6点1分,星期日设置超时值/ Retrieve the ti
15、me-out parameters for all read and write operations on the port. COMMTIMEOUTS CommTimeouts;GetCommTimeouts (hPort, &CommTimeouts);/ Change the COMMTIMEOUTS structure settings.CommTimeouts.ReadIntervalTimeout = MAXDWORD; CommTimeouts.ReadTotalTimeoutMultiplier = 0; CommTimeouts.ReadTotalTimeoutConsta
16、nt = 0; CommTimeouts.WriteTotalTimeoutMultiplier = 10; CommTimeouts.WriteTotalTimeoutConstant = 1000; / Set the time-out parameters for all read and write operations on the port. if (!SetCommTimeouts (hPort, &CommTimeouts) / Could not set the time-out parameters. MessageBox (hMainWnd, TEXT(Unable to
17、 set the time-out parameters), TEXT(Error), MB_OK); dwError = GetLastError (); return FALSE;第19页,共35页,2022年,5月20日,6点1分,星期日写串口DWORD dwError, dwNumBytesWritten;WriteFile (hPort, / Port handle &Byte, / Pointer to the data to write 1, / Number of bytes to write &dwNumBytesWritten, / Pointer to the numbe
18、r of bytes / written NULL / Must be NULL for Windows CE);第20页,共35页,2022年,5月20日,6点1分,星期日读串口BYTE Byte;DWORD dwBytesTransferred;ReadFile (hPort, / Port handle &Byte, / Pointer to data to read 1, / Number of bytes to read &dwBytesTransferred, / Pointer to number of bytes / read NULL / Must be NULL for W
19、indows CE);第21页,共35页,2022年,5月20日,6点1分,星期日使用通讯事件BYTE Byte;DWORD dwBytesTransferred;/ Specify a set of events to be monitored for the port.SetCommMask (hPort, EV_RXCHAR | EV_CTS | EV_DSR | EV_RLSD | EV_RING);while (hPort != INVALID_HANDLE_VALUE) / Wait for an event to occur for the port. WaitCommEvent
20、 (hPort, &dwCommModemStatus, 0); / Re-specify the set of events to be monitored for the port. SetCommMask (hPort, EV_RXCHAR | EV_CTS | EV_DSR | EV_RING); if (dwCommModemStatus & EV_RXCHAR) / Loop for waiting for the data. do / Read the data from the serial port. ReadFile (hPort, &Byte, 1, &dwBytesTr
21、ansferred, 0); / Display the data read. if (dwBytesTransferred = 1) ProcessChar (Byte); while (dwBytesTransferred = 1); 第22页,共35页,2022年,5月20日,6点1分,星期日通讯事件简介EventDescriptionEV_BREAKA break occurred on input.EV_CTSThe CTS signal changed state.EV_DSRThe DSR signal changed state.EV_ERRA line-status erro
22、r occurred. Line-status errors are CE_FRAME, CE_OVERRUN, and CE_RXPARITY.EV_RINGA ring indicator was detected.EV_RLSDThe receive-line-signal-detect signal changed state.EV_RXCHARA character was received and placed in the input buffer.EV_RXFLAGThe event character was received and placed in the input
23、buffer.EV_TXEMPTYThe last character in the output buffer was sent.第23页,共35页,2022年,5月20日,6点1分,星期日关闭串口BOOL CloseHandle( HANDLE hObject ); 关闭一个已经打开的对象句柄,使用这种方法来关闭串口参数:待关闭的句柄返回值:是否关闭成功第24页,共35页,2022年,5月20日,6点1分,星期日5、红外设备简介第25页,共35页,2022年,5月20日,6点1分,星期日红外通讯红外线是波长在750nm至1mm之间的电磁波,其频率高于微波而低于可见光,是一种人的眼眼看不到的光线。目前无线电波和微波已被广泛应用在长距离的无线通信中,但由于红外线的波长较短,对障碍物的衍射能力差,所以更适合应用在需要短距离无线通信场合点对点的直接线数据传输。第26页,共35页,2022年,5月20日,6点1分,星期日红外协议栈第27页,共35页,2022年,5月20日,6点1分,星期日各模块解释物理层协议(Ph
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 心理健康教育与学生综合素质提升研究
- 教育技术在智慧城市中的应用与发展
- 技术促进教育与培训领域的均衡发展
- 心理资本对学习行为的影响研究
- 从教育大数据看未来人才培养趋势
- 教育信息化的视觉设计与传播效果分析研究报告
- 教育机器人技术的国际合作与交流
- 2025届湖北省鄂州市吴都中学物理高二下期末达标检测试题含解析
- 教育技术在增强全民数字素养中的作用和价值体现
- 中职护理老师课件下载
- 2025标准版的还建房买卖合同
- 有限空间监理实施细则
- s7-1200plc编程及应用第三版-廖常初-课后习题答案
- 晶体植入术的术后护理
- 劳动通论学习通超星期末考试答案章节答案2024年
- ISO56002-2019创新管理体系管理手册及程序文件
- 新教材北师大版必修第一册unit1 life choices单词短语句型写作知识点提炼
- 贵州省贵阳市2023-2024学年七年级下学期期末考试生物试题(无答案)
- 广东省湛江市2023-2024学年高二下学期7月期末考试化学试题
- 江苏省盐城市2023-2024学年高一下学期6月期末 数学试题【含答案】
- 黑龙江省哈尔滨市2024年七年级下学期生物期末试卷附答案
评论
0/150
提交评论