1. 动机
应用程序开发语言
为C# 应用程序要求既能在PDA上运行,又能在PC上运行,具备良好的兼容性
应用程序要求尽可能多的兼容不同PDA上的红外线设备
.net自带的SerialPort在HP某型号PDA上操作红外线设备时,只能接受,不能发射
2. 目标
具备良好的兼容性,既能够在PC上运行也能够在PDA上运行。
挡在PDA上运行时,尽可能多的兼容红外设备。
3. 局限性
单线程
仅提供send/receive模式的接口,无事件驱动机制
4 . 关键技术问题及典型测试案例
最关键的是对EscapeCommFunction的调用,当串口为红外设备时,必须调用此函数才能确保串口 工作正常。当串口为一般的COM口时,出于兼容性的考虑,切勿调用此函数。
在HP某PDA上测试时,不管串口是否为红外设备,均调用此函数启用红外功能,均能够工作正常。
在SIEMENS某PDA上测试时,如果串口为一般COM接口,并且调用了此函数,那么串口不能正常工作,屏蔽此函数后,一切正常。
5. 源码
SerialPort Source Code
using System;
using System.Runtime.InteropServices;
namespace NativeDll
{
public class SerialPort
{
serial port api#region serial port api
//for ir control
private const int SETIR = 10;
private const int CLRIR = 11;
//win32 api constants
private const uint GENERIC_READ = 0x80000000;
private const uint GENERIC_WRITE = 0x40000000;
private const int OPEN_EXISTING = 3;
private const int INVALID_HANDLE_VALUE = -1;
private const int MAXBLOCK = 4096;
private const uint PURGE_TXABORT = 0x0001;
// Kill the pending/current writes to the comm port.
private const uint PURGE_RXABORT = 0x0002;
// Kill the pending/current reads to the comm port.
private const uint PURGE_TXCLEAR = 0x0004;
// Kill the transmit queue if there.
private const uint PURGE_RXCLEAR = 0x0008;
// Kill the typeahead buffer if there.
[StructLayout(LayoutKind.Sequential)]
private struct DCB
{
相关图文阅读
频道图文推荐
健 康 咨 询
时 尚 咨 询
相关专题
- .NET移动与嵌入式技术 (5969篇文章)
- .NET开发手册 (5670篇文章)
- .NET基础介绍 (717篇文章)
- 基于VC.NET的GDI+图像处理 (1412次浏览)
- 基于VC.NET的GDI+编程之CImage (862次浏览)
- 提供一个.NET平台通用串口操作类 (754次浏览)
- Viusal C++.NET 2003 的优化代码 (682次浏览)
- 用Visual C++ 2005编写更快的代码 (668次浏览)
- Visual C++.NET编程讲座之三 (613次浏览)
- Visual C++.NET编程讲座之八 (596次浏览)
- VC.Net定义和使用MFC DLL (586次浏览)
- VC.NET开发OpenGL应用入门 (577次浏览)
- Visual C++.NET编程讲座之六 (574次浏览)



