comm.h

来自「DOS和WINDOWS下的串口源代码」· C头文件 代码 · 共 61 行

H
61
字号
#ifndef _COMM_H
#define _COMM_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dos.h>
#include <bios.h>
#include <conio.h>
#include <time.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	保存得到的设备句柄值
*/
int InitComm(int CommPort, int Baud, int VerifyBit);

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

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

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

⌨️ 快捷键说明

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