您当前的位置: 首页 >  硬件开发

命运之手

暂无认证

  • 1浏览

    0关注

    747博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

【Android智能硬件开发】【010】安卓读写串口

命运之手 发布时间:2022-02-11 12:03:00 ,浏览量:1

什么是串口

串口全称串行硬件通信接口,英文名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

关注
打赏
1654938663
查看更多评论
立即登录/注册

微信扫码登录

0.0414s