⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 comm.h

📁 DOS和WINDOWS下的串口源代码
💻 H
字号:
// Comm.h : main header file for the Comm DLL
//


#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
#endif

#include "resource.h"		// main symbols
#include "string.h"
#include "stdio.h"

#define TIMEOUT						-1  /*超时*/
#define COM_OPEN_ERROR				-2	/*打开串口失败*/
#define COM_INIT_ERROR				-3	/*串口初始化失败*/
#define COM_CLOSE_ERROR				-4  /*串口关闭失败*/
#define COM_SEND_DATA_LENTH_ERROR	-5  /*数据发送大小错误*/
#define COM_ERROR_SET_BUFFER		-6  /*设置缓冲区大小失败*/
#define COM_ERROR_INVALID_COMM		-7	/*无效的设备*/
#define COM_INVALID_HANDLE			-8	/*设备句柄为空*/
#define COM_SEND_DATA_ERROR			-9	/*数据发送失败*/
#define COM_RECV_DATA_ERROR			-10	/*数据接收失败*/
#define	OK					0

/*
*函数功能:	初始化串口
*参数说明:	
*			int CommPort	串口号 默认Com1,1--Com1, 2--Com2, 3--Com3
*			int Baud		波特率 0---9600, 1--4800, 2--2400, 3--1200,
*			int Verifybit	0--8字节数据位, Parity = 0;
*							1--7字节数据位, Parity = 2;
*			void *PtrVoid	保存得到的设备句柄值
*/
extern "C"	__declspec(dllexport) int InitComm(int CommPort, int Baud, int VerifyBit);

/*
*函数功能:	关闭串口
*参数说明:	
*			void *PtrVoid	保存得到的设备句柄值
*/
extern "C"	__declspec(dllexport) int CloseComm();

/*
*函数功能:	发送数据
*参数说明:	
*			char *SendBuf	要发送的字符串
*			int SendLen		发送字符串的长度
*			void *PtrVoid	保存得到的设备句柄值
*返回说明:
*
*/
extern "C"	__declspec(dllexport) int SendData(char *SendBuf, int SendLen);

/*
*函数功能:	读取数据
*参数说明:	
*			char *RecvBuf	保存读到的数据
*			long outtime	读取超时设置
*			void *PtrVoid	保存得到的设备句柄值
*返回说明:
*
*/
extern "C"	__declspec(dllexport) int RecvData(char *RecvBuf, long outtime );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -