zoukankan      html  css  js  c++  java
  • AndroidSerialpPort

      Android串口通信

      一.集成AndroidSerialPort库:

        1.allprojects {
          repositories {
            ... maven { url 'https://jitpack.io' }
              }
             }
     
        2.compile 'com.github.kongqw:AndroidSerialPort:1.0.1'

      二、查看串口

        SerialPortFinder serialPortFinder = new SerialPortFinder();
        ArrayList<Device> devices = serialPortFinder.getDevices();

      三、初始化

        SerialPortManager mSerialPortManager = new SerialPortManager();

      四、打开串口监听

        mSerialPortManager.setOnOpenSerialPortListener(new OnOpenSerialPortListener() {
           @Override public void onSuccess(File device) {
              
            }
          @Override public void onFail(File device, Status status) {
            
            }
          });

      五、数据通信监听

        mSerialPortManager.setOnSerialPortDataListener(new OnSerialPortDataListener() {
          @Override public void onDataReceived(byte[] bytes) {

          } @Override public void onDataSent(byte[] bytes) {

          }
         });

      六、打开串口

        boolean openSerialPort = mSerialPortManager.openSerialPort(device.getFile(), 115200);
          参数1:串口
          参数2:波特率
               返回:串口打开是否成功

      七、发送数据

        boolean sendBytes = mSerialPortManager.sendBytes(sendContentBytes);
          参数:发送数据 byte[]
          返回:发送是否成功

      八、关闭串口

        mSerialPortManager.closeSerialPort();

  • 相关阅读:
    PHP SOAP
    PHP 笔记
    IIS PHP
    思途CMS
    HTML系列(2)基本的HTML标签(一)
    HTML系列(1)简介
    Python学习进程(14)异常处理
    Python学习进程(13)文件与IO
    Python学习进程(12)模块
    Python学习进程(11)日期和时间
  • 原文地址:https://www.cnblogs.com/leizz/p/11671436.html
Copyright © 2011-2022 走看看