## AndroidAutomation
### 说明
AndroidAutomation 以安卓为控制器,实现了本地控制指令的Web化,以便借助浏览器的跨平台的特性,低成本实现各平台的用户交互。
本程序实现了对COM口的控制, 支持设置 su 路径、串口路径、波特率、校验位、数据位、停止位; 亦可作为串口调试工具。
<br>
### 样例
Android工控机为平台<br>
32路modbus协议继电器控制动作机构<br>
NPN光电管负责出货结果检测<br>
由以上元件构建智能售卖系统原型。
[点我观看视频](http://v.youku.com/v_show/id_XMzg5Mjg5OTY4NA==.html?spm=a2hzp.8253869.0.0)<br>
http://v.youku.com/v_show/id_XMzg5Mjg5OTY4NA==.html?spm=a2hzp.8253869.0.0
### 效果预览
<img src="https://github.com/ZengOwen/AndroidAutomation/blob/master/app/S1.jpeg" width="30%" /> <img src="https://github.com/ZengOwen/AndroidAutomation/blob/master/app/S2.jpeg" width="30%" /> <img src="https://github.com/ZengOwen/AndroidAutomation/blob/master/app/S3.jpeg" width="30%" />
<br>
### 使用
打开串口
```java
SerialPort mSerialPort = new SerialPort("/dev/ttyS1", 9600);
//获取串口文件的输入输出流,以便数据的收发
InputStream is = mSerialPort.getInputStream();
OutputStream os = mSerialPort.getOutputStream();
```
<br>
### API
#### 设置 su 路径
Android 主板在与其它硬件进行串口通信时,串口作为底层实现,Android 系统把设备作为一个文件,与其他设备进行串口通信就相当于读写此文件。
因此需要 root 权限来操作串口文件,默认的 su 文件路径在 `/system/bin/su` ,你可以重新设置 su 的文件路径,以便获取 root 权限,例如,设置路径`/system/xbin/su`
```java
//需要在打开串口前调用
SerialPort.setSuPath("/system/xbin/su");
```
<br>
#### 查看串口设备列表
Android 串口文件都在 ``/proc/tty/drivers`` 目录下,因此可以获取所有串口文件。
```java
SerialPortFinder serialPortFinder = new SerialPortFinder();
String[] allDevices = serialPortFinder.getAllDevices();
String[] allDevicesPath = serialPortFinder.getAllDevicesPath();
```
<br>
#### 打开串口
如果你需要设置更多参数,请使用以下构造函数
```java
/**
* 打开串口
* @param device 串口设备文件
* @param baudRate 波特率
* @param parity 奇偶校验,0 None(默认); 1 Odd; 2 Even
* @param dataBits 数据位,5 ~ 8 (默认8)
* @param stopBit 停止位,1 或 2 (默认 1)
* @param flags 标记 0(默认)
*/
public SerialPort(File device, int baudRate, int parity, int dataBits, int stopBit, int flags)
```
检验位一般默认是0(NONE),数据位一般默认为8,停止位默认为1。
<br>
#### 读写串口
##### 读数据
```java
// 配合 Rxjava2 ,处理异常更方便
mReceiveDisposable = Flowable.create((FlowableOnSubscribe<byte[]>) emitter -> {
InputStream is = mSerialPort.getInputStream();
int available;
int first;
while (!isInterrupted && mSerialPort != null
&& is != null && (first = is.read()) != -1) {
do {
available = is.available();
SystemClock.sleep(1);
} while (available != is.available());
byte[] bytes = new byte[is.available()+1];
is.read(bytes,1,is.available());
bytes[0] = (byte) (first & 0xFF);
emitter.onNext(bytes);
}
close();
}, BackpressureStrategy.MISSING)
```
##### 写数据
```java
//获取输出流
OutputStream os = mSerialPort.getOutputStream();
os.write(ByteUtils.hexStringToBytes("CCAA0300"));
```
<br>
#### 32路继电器应答模式 及 执行结果触发
使用Rxjava2接受数据时,为定时触发,触发周期太长,响应太慢,触发周期太短,会造成完整的返回数据被切割,改用FutureTask,但只能正常触发一次,于是自己实现带超时控制的快速响应, 解决了内容完整与高效的统一
```java
public boolean SendDataAndRcv(byte[] sData, int timeOut, ComRcvBean ackData) throws IOException, InterruptedException{
boolean Result = false;
// use Java new thread feature, but can't get expect result,may bug exist in it's future class
if (mLock.tryLock(100, TimeUnit.MILLISECONDS)){
try{
mMixModeThread.setQueryMode(true);
t_isReady = false;
mOutputStream.write(sData);
long startTime = System.currentTimeMillis();
while (!t_isReady && System.currentTimeMillis() - startTime < timeOut){
SystemClock.sleep(1);
}
if (t_isReady){
//mAckThread.setQueryMode(false);
mMixModeThread.setQueryMode(false);
ackData.Received = new byte[t_AckSize];
System.arraycopy(t_bytes, 0, ackData.Received, 0, t_AckSize);
ackData.Msg.append(String.format("Rcv: %s \r\n", ByteUtils.bytesToHexString(ackData.Received)));
Result = true;
}else{
ackData.Msg.append("串口接收超时\r\n");
Result = false;
}
}
finally{
mLock.unlock();
}
} else {
ackData.Msg.append("锁定超时\r\n");
}
return Result;
}
```
<br>
#### 通过对本Web框架路由的映射,实现Web请求与本地功能链接
```java
@ResponseBody
@RequestMapping("Sale")
public ResultBean Sale(@RequestParam("LNo") String LNo) {
ResultBean Result = null;
int PortNo = Integer.parseInt(LNo);
if (PortNo < 1 || PortNo > 64){
Result = new ResultBean(404,"货道编号超出范围",null);
return Result;
}
ComRcvBean ComRcv = dCom.Sale(Integer.parseInt(LNo),"Web");
if (ComRcv.State){
Result = new ResultBean(200,"OK",ComRcv);
}else{
Result = new ResultBean(500,"Error",ComRcv);
}
return Result;
}
```
没有合适的资源?快使用搜索试试~ 我知道了~
以安卓为控制器,实现了本地指令Web化,以借助浏览器的跨平台特性,低成本实现各平台的用户交互。.zip
![preview](https://csdnimg.cn/release/downloadcmsfe/public/img/white-bg.ca8570fa.png)
共202个文件
xml:84个
java:54个
png:27个
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
需积分: 5 1 下载量 177 浏览量
2024-08-17
09:24:37
上传
评论
收藏 5.09MB ZIP 举报
温馨提示
项目工程资源经过严格测试可直接运行成功且功能正常的情况才上传,可轻松copy复刻,拿到资料包后可轻松复现出一样的项目,本人系统开发经验充足(全栈开发),有任何使用问题欢迎随时与我联系,我会及时为您解惑,提供帮助 【资源内容】:项目具体内容可查看/点击本页面下方的*资源详情*,包含完整源码+工程文件+说明(若有)等。【若无积分,此资源可私信获取】 【本人专注IT领域】:有任何使用问题欢迎随时与我联系,我会及时解答,第一时间为您提供帮助 【附带帮助】:若还需要相关开发工具、学习资料等,我会提供帮助,提供资料,鼓励学习进步 【适合场景】:相关项目设计中,皆可应用在项目开发、毕业设计、课程设计、期末/期中/大作业、工程实训、大创等学科竞赛比赛、初期项目立项、学习/练手等方面中 可借鉴此优质项目实现复刻,也可基于此项目来扩展开发出更多功能 #注 1. 积分资源不提供技术指导/答疑 2. 本资源仅用于开源学习和技术交流。不可商用等,一切后果由使用者承担 3. 部分字体及插图等来自网络,若是侵权请联系删除,本人不对所涉及的版权问题或内容负法律责任。收取的费用仅用于收集和整理资料耗费时间的酬劳
资源推荐
资源详情
资源评论
![zip](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![exe](https://img-home.csdnimg.cn/images/20210720083343.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![thumb](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JAR.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JAR.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PNG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PNG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PNG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PNG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PNG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PNG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PNG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PNG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PNG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PNG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PNG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PNG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PNG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PNG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PNG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PNG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PNG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PNG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PNG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PNG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PNG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PNG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PNG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PNG.png)
共 202 条
- 1
- 2
- 3
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/309be5d44dcf405b95f4d68867656dba_qrsds.jpg!1)
专家大圣
- 粉丝: 1501
- 资源: 6298
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
最新资源
- FPGA入门系列实验教程-PWM输出控制LED显示.zip
- FPGA开发全攻略-下.zip
- FPGA开发全攻略-上-.zip
- 信息融合项目matlab仿真代码及说明 针对杂波环境多目标跟踪问题,设计目标稀疏的目标运动场景,分别采用PDA和JPDA方法,对
- 基于matlab的FFT分析和滤波程序,可对数据信号进行频谱分析,分析波形中所含谐波分量,并可以对特定频率波形进行提取 不需要
- 追剪,定长切割,跟随切割,PLC用的是西门子smart200,屏用的是smart700,是实际项目运行非常稳定,带堆放功能,报警
- cadance 1.8v LDO电路 cadance virtuoso 设计 模拟电路设计 LDO带隙基准电路设计 带设计报告(
- TSC,晶闸管投切电容器,无功补偿,静止无功补偿器,
- 联想SR650内存安装顺序说明
- 基于深度学习的磁共振超分辨率图像重建python源码(高分代码)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)