- #include <stdio.h> /*标准输入输出定义*/
- #include <stdlib.h> /*标准函数库定义*/
- #include <unistd.h> /*Unix 标准函数定义*/
- #include <sys/types.h>
- #include <sys/stat.h>
- #include "string.h"
- #include <fcntl.h> /*文件控制定义*/
- #include <termios.h> /*PPSIX 终端控制定义*/
- #include <errno.h> /*错误号定义*/
- #define FALSE -1
- #define TRUE 0
- /*********************************************************************/
- int OpenDev(char *Dev)
- {
- int fd = open( Dev, O_RDWR | O_NOCTTY ); //| O_NOCTTY | O_NDELAY
- if (-1 == fd)
- {
- perror("Can't Open Serial Port");
- return -1;
- }
- else
- return fd;
- }
- /**
- *@brief 设置串口通信速率
- *@param fd 类型 int 打开串口的文件句柄
- *@param speed 类型 int 串口速度
- *@return void
- */
- int speed_arr[] = { B38400, B19200, B9600, B4800, B2400, B1200, B300,
- B38400, B19200, B9600, B4800, B2400, B1200, B300, };
- int name_arr[] = {38400, 19200, 9600, 4800, 2400, 1200, 300, 38400,
- 19200, 9600, 4800, 2400, 12