什么是串口
串口全称串行硬件通信接口,英文名SerialPort,用于硬件之间进行串行数据通信
准备
该功能用到c语言编写的so库,libserial_port.so
核心代码
	//设置串口地址
	File device = new File("/dev/ttyS2");
	//创建串口读写类
	SerialPort sp = new SerialPort(device, 57600);
	//订阅串口数据
	sp.onReceive = (buffer, length) -> {
	    String hex = Bytes.byteArrayToHex(buffer);
	};
	//开始读串口
	sp.startRead();
	//写串口
	sp.write(new byte[]{0x00, 0x00, 0x00, 0x00, 0x00, 0x00});
源码下载
安卓读写SerialPort串口.zip










