Giter Club home page Giter Club logo

cordova-plugin-serialport's Introduction

cordova-plugin-serialPort

Cordova 安卓串口插件


安装


cordova plugin add cordova-plugin-serialPort

支持平台

  • android

安装注意


  • 需要手动修改AndroidManifest.xml ,在application 节点加上android:name="Application"
 <application android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name" android:name="Application" android:supportsRtl="true">
  • 安装之前需要修改插件里面的plugin.xml Application.java 的位置,把$package.$dir 替换成app你的package 的目录
<source-file src="src/android/Application.java" target-dir="src/$package.$dir"/>
  • 手动修改 Application.java 的package 换成自己app的package
package $package;

JavaScript API


  • 获取串口列表
window.SerialPortActivity.getSerialPort(function success(data), function error());

data 返回的是个串口的device数组

  • 打开串口
window.SerialPortActivity.openSerialPort(device, baudRate, function success(data) , function error ());

device 是getSerialPort 中返回的device baudRate 串口设备波特率

  • 注册接收数据监听函数
window.SerialPortActivity.startNotify(receiveCallback,function error ())
  }
var receiveCallback=function(data){
// Decode the ArrayBuffer into a typed Array based on the data you expect
    var unit8 = new Uint8Array(data);
  }

receiveCallback 接收串口数据的函数,参数 data 是 ArrayBuffer,需要转成js对应的数组

  • 检测串口是否可用
window.SerialPortActivity.portDetect(function success(data),function error ())
  }

success 检测串口成功的回调函数,回调参数data = 1 ,则可用,为 data = 1 则不可用

  • 关闭串口
window.SerialPortActivity.closeSerialPort(function success(), function error())

最好是只有在程序退出的时候再去调用此接口

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.