该驱动适用于采用linux和android系统平台的C/C++开发。
用于配置串口相关参数:端口选择、阻塞非阻塞、波特率、停止位、数据位、校验位等。
注:需要系统开启串口操作权限,否则配置失败。
本驱动在MTK8735平台上验证测试,其它平台修改串口端口名称即可。
源代码:
serial.h
//
// Created by taxiang&xuezi on 2018/4/2.
//
#ifndef NDKAPPECG_SERIAL_H
#define NDKAPPECG_SERIAL_H
#ifdef SERIAL_GLOBALS
#define SERIAL_EXT
#else
#define SERIAL_EXT extern
#endif
#define SERIAL_DBG 1
SERIAL_EXT s32 uart_open(s32 fd,s32 port,s8 block);
SERIAL_EXT s32 uart_set(s32 fd, s32 nSpeed, s32 nBits, s8 nEvent, s32 nStop);
#endif //NDKAPPECG_SERIAL_H
serial.c/serial.cpp
//
// Created by taxiang&xuezi on 2018/4/2.
//
#define SERIAL_GLOBALS
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <errno.h>
#include <fcntl.h>
#include <termios.h>
#include <time.h>
#include <unistd.h>
#include <sys/stat.h>
#ifdef SERIAL_DBG
#define SERIAL_PRINT0(X) printf(X);
#define SERIAL_PRINT1(X,A) printf (X,A);
#define SERIAL_PRINT2(X,A,B) printf (X,A,B);
#define SERIAL_PRINT3(X,A,B,C) printf (X,A,B,C);
#define SERIAL_PRINT4(X,A,B,C,D) printf (X,A,B,C,D);
#else
#define SERIAL