- 10
- 0
- 约3.58万字
- 约 42页
- 2017-12-12 发布于河南
- 举报
VC实现串口通信项目源码
VC实现串口通信例程
WIN95界面下的VC++串口通讯程序在WIN32下是不建议对端口进行操作的,在WIN32中所有的设备都被看成是文件,串行口也不例外也是作为文件来进行处理的。这是我的一份关于串口编程的读书笔记,对于使用VC进行编程的同行应该有一定的帮助。1.打开串口: 在Window 95下串行口作为文件处理,使用文件操作对串行口进行处理。使用CreateFile()打开串口,CreateFile()将返回串口的句柄。
HANDLE CreateFile( LPCTSTR lpFileName, // pointer to name of the file DWORD dwDesiredAccess, // access (read-write) mode DWORD dwShareMode, // share mode LPSECURITY_ATTRIBUTES lpSecurityAttributes, // pointer to security attributes DWORD dwCreationDistribution, // how to create DWORD dwFlagsAndAttributes, // file attributes HANDLE hTemplateFile // handle to file with attributes to copy );
lpFileName: 指明串口制备,例:COM1,COM2 dwDesiredAccess: 指明串口存取方式,例:GENERIC_READ|GENERIC_WRITE dwShareMode: 指明串口共享方式 lpSecurityAttributes: 指明串口的安全属性结构,NULL为缺省安全属性 dwCreateionDistribution: 必须为OPEN_EXISTIN dwFlagAndAttributes: 对串口唯一有意义的是FILE_FLAG_OVERLAPPED hTemplateFile: 必须为NULL2.关闭串口: CloseHandle(hCommDev);3.设置缓冲区长度: BOOL SetupComm( HANDLE hFile, // handle of communications device DWORD dwInQueue, // size of input buffer DWORD dwOutQueue // size of output buffer );4.COMMPROP结构: 可使用GetCommProperties() 取得COMMPROP结构,COMMPROP结构中记载了系统支持的各项设置。 typedef struct _COMMPROP {// cmmp WORD wPacketLength; // packet size, in bytes WORD wPacketVersion; // packet version DWORD dwServiceMask; // services implemented DWORD dwReserved1; // reserved DWORD dwMaxTxQueue; // max Tx bufsize, in bytes DWORD dwMaxRxQueue; // max Rx bufsize, in bytes DWORD dwMaxBaud; // max baud rate, in bps DWORD dwProvSubType; // specific provider type DWORD dwProvCapabilities; // capabilities supported DWORD dwSettableParams; // changeable parameters DWORD dwSettableBaud; // allowable baud rates WORD wSettableData; // allowable byte sizes WORD wSettableStopParity; // stop bits/parity allowed DWORD dwCurrentTxQueue; // Tx buffer size, in bytes DWORD dw
您可能关注的文档
最近下载
- ZXM10 EISU(V1.0)增强智能型采集单元用户手册.pdf VIP
- 政府机关物业管理服务保洁服务工作计划及操作规程服务方案.docx VIP
- 铜铝替代在电线电缆和家电行业的未来趋势展望.pdf
- 23J916-1 住宅排气道(一)图集.pdf VIP
- 油漆表面缺陷分类.pptx VIP
- ZXM10工程安装工艺规范-2012版.doc VIP
- 高清:2023年甘肃省高等职业教育分类考试招生中职升学考试财经商贸类专业基础试题及参考答案.docx VIP
- 2025 高新技术企业认定实操手册(含评分标准).docx VIP
- 商业综合体消防灭火疏散的应急预案范文(通用13篇).docx VIP
- 一种电动缸推拉力测试工装.pdf VIP
原创力文档

文档评论(0)