1、串行设备驱动,www.up- 博创科技 嵌入互动,主要内容,1、Windows CE.net串行设备简介 2、串口设备驱动 3、串行设备API简介 4、串口设备操作 5、红外设备简介,1、Windows CE.net串行设备简介,Windows CE.net串行设备,Windows CE.net的串行设备应用十分广泛 GPRS通信 智能数据终端 GPS定位系统 红外通讯设备,使用通用码流进行数据传输,与标准串口完全兼容 支持3线/9线串口方式 串口模型基本延续了桌面系统的风格和基本的API,但未封装成类,串口的7层结构,Netarm2410-S串行设备情况,UART0(3线) 标准格式化信息输
2、出串口;基本通讯串口 UART1(3线) 基本通讯串口(未使用) UART2(3线) 红外通讯串口;基本通讯串口,2、串口设备驱动,串口设备驱动,是一种流驱动 BSP中提供的串口驱动模型较为复杂,在结构上也分层为MDD和PDD层,3、串行设备API简介,串口的API,CreateFileOpens a serial port. GetCommStateFills in a device-control block DCB structure with the current control settings for a specified communication device. SetCo
3、mmStateConfigures 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 a specified communication device
4、. 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, which receives data from a device
5、 at the other end of a serial connection.,串口的API,SetCommMaskSpecifies 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 to occur for a specified communication device. The set o
6、f 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. ClearCommBreakRestores character transmission for a specified
7、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.,4、串口设备操作,打开串口,/ Open the serial port.hPort = CreateFile (lpszPortName, / Pointer to the name of the portGEN
8、ERIC_READ | GENERIC_WRITE,/ Access (read-write) mode0, / Share modeNULL, / Pointer to the security attributeOPEN_EXISTING,/ How to open the serial port0, / Port attributesNULL); / Handle to port with attribute/ to copy,配置串口,/ Initialize the DCBlength member. PortDCB.DCBlength = sizeof (DCB); / Get t
9、he default port setting information. GetCommState (hPort, ,设置超时值,/ Retrieve the time-out parameters for all read and write operations on the port. COMMTIMEOUTS CommTimeouts; GetCommTimeouts (hPort, ,写串口,DWORD dwError,dwNumBytesWritten;WriteFile (hPort, / Port handle,读串口,BYTE Byte; DWORD dwBytesTrans
10、ferred;ReadFile (hPort, / Port handle,使用通讯事件,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
11、(hPort, ,通讯事件简介,Event Description EV_BREAK A break occurred on input. EV_CTS The CTS signal changed state. EV_DSR The DSR signal changed state. EV_ERR A line-status error occurred. Line-status errors are CE_FRAME, CE_OVERRUN, and CE_RXPARITY. EV_RING A ring indicator was detected. EV_RLSDThe receive
12、-line-signal-detect signal changed state. EV_RXCHAR A character was received and placed in the input buffer. EV_RXFLAG The event character was received and placed in the input buffer. EV_TXEMPTY The last character in the output buffer was sent.,关闭串口,BOOL CloseHandle( HANDLE hObject ); 关闭一个已经打开的对象句柄,
13、使用这种方法来关闭串口 参数:待关闭的句柄 返回值:是否关闭成功,5、红外设备简介,红外通讯,红外线是波长在750nm至1mm之间的电磁波,其频率高于微波而低于可见光,是一种人的眼眼看不到的光线。 目前无线电波和微波已被广泛应用在长距离的无线通信中,但由于红外线的波长较短,对障碍物的衍射能力差,所以更适合应用在需要短距离无线通信场合点对点的直接线数据传输。,红外协议栈,各模块解释,物理层协议(Physical Layer) 制定了红外通信硬件设计上的目标和要求,包括红外的光特性、数据编码、各种波特率下帧的包括格式等。为达到兼容,硬件平台以及硬件接口设计必须符合红外协议制定的规范。 连接建立协议
14、层(IrLAP)制定了底层连接建立的过程规范,描述了建立一个基本可靠连接的过程和要求。 连接管理协议层(IrLMP)制定了在单位个IrLAP连接的基础上复用多个服务和应用的规范。在IrLMP协议上层的协议都属于特定应用领域的规范和协议。,各模块解释,流传输协议层(TingTP)在传输数据时进行流控制。制定把数据进行拆分、重组、重传等的机制。 对象交换协议层(OBEX)制定了文件和其他数据对象传输时的数据格式。 模拟串口层协议层(IrCOMM)允许已存在的使用串口通信的应用象使用串口那样使用红外进行通信。 局域网访问协议层(IrLAN)允许通过红外局域网络唤醒笔记本电脑等移动设备,实际远程摇控等功能。,红外在平台中的实现方式,普通串口与红外串口波形,和红外相关的串口控制寄存器,相关说明,因此,在串口驱动程序中,添加了红外相关的寄存器配置,就可以控制红外收发器,实现红外串口数据传输 同样,红外驱动程序也需要实现流驱动程序中必要的入口函数,文件配置,注册表配置等等,详细可以参看BSP中的相应文件,Thanks,