Coder Social home page Coder Social logo

android-serialport-485's Introduction

android 485协议通讯 示例

硬件端:

硬件为主控芯片为stm32的单片机,每块单片机上控制24路锁开关,可通过485外扩。

通讯协议为485标准协议,实现的功能有:某一路的开锁动作,监听某一路的锁关闭动作,查询某块板子的24路的所有锁的状态等

android端:

串口通讯库:https://github.com/cl-6666/serialPort

由于485半双工通讯模式的限制,必须保证同时只有一条指令下发给单片机

设想的实现结果是:在某条指令的响应帧到达android之后再进行下一条指令的下发,针对这一问题采用了当前的处理方案:

线程池newSingleThreadExecutor模式保证同时只有一个活动的线程,每一个指令的下发任务包装在一个线程类中,结合ArrayBlockingQueue阻塞队列实现对某条指令的响应监控,队列接收到消息后再进行下一个指令的下发

//UGSerialManager.java

//发送指令后
respQueue.poll(3000, TimeUnit.MILLISECONDS);//respQueue为ArrayBlockingQueue 3s内respQueue内接收到响应消息则视为下发指令正常,没收到则视为异常
//UGSerialManager.java

//串口监听数据回调
respQueue.add(bean); //相应数据进入到respQueue队列中

android-serialport-485's People

Contributors

jarvis4901 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.