Giter Site home page Giter Site logo

tmk-cordova-plugin-usb's Introduction

tmk-cordova-plugin-usb

min SDK version: 27 Android >= 8.1 Oreo

folders and files

  • /android-usb - android studio project - contains java files for the plugin; based on sample project USBEnumerator. Only some classes are taken from here(see: plugin.xml)
  • /www - cordova plugin js
  • plugin.xml - plugin config and mapping

info

Cordova Plugin Development Guide

Plugin Specification

Cordova Hello World Plugin

cordova-plugin-usb-event

How to Create a Cordova Plugin from Scratch

How to create an Android Cordova plugin for showing Toast popups

Usage

SSH

cordova plugin add [email protected]:kaizentmk/tmk-cordova-plugin-usb.git

HTTPS

cordova plugin add https://github.com/kaizentmk/tmk-cordova-plugin-usb.git

Edit www/js/index.js and add the following code inside onDeviceReady

    var success = function(message) {
        alert(message);
    }

    var failure = function() {
        alert("Error calling TmkUsb Plugin");
    }

    window.cordova.plugins.tmkusb.greet("World", success, failure);

Cordova dependency in android studio

maven cordova framework for gradlew build.gradlew (Module:app)

dependencies {
   implementation group: 'org.apache.cordova', name: 'framework', version: '8.0.0'
}

Issues

building

/home/tmk/projs/tmk-cordova-plugin-usb/android-usb/app/src/main/java/com/example/androidthings/usbenum/UsbActivity.java:55: Error: Call requires API level 23 (current min is 21): android.content.Context#getSystemService [NewApi] mUsbManager = getSystemService(UsbManager.class);

WIP

usbSerialDevice.open()

TODO

  1. Init broadcast receiver in initialize method. You can make it so the app will start automatically by adding an IntentFilter to the MainActivity. The IntentFilter triggers when any new device is attached. To explicitly specify the type of device by providing the vendor ID and/or product ID in an XML file.

  2. Query for all connected devices. All USB slave devices have a vendor and product ID.

  3. Check for matching vendor id. An Arduino’s vendor ID is always 0x2341 or 9025.

  4. Request user permission to access the device

  5. If permission granted open the device

  6. Create serial connection and set parameters

  7. Begin thread to continuously check for incomming data

  8. Display/write data. Take note that reading from the device is asynchronous, so it will continuously run in the background, receiving data as soon as possible. All data received is in the form of raw bytes, so it needs to be re-encoded into a readable format such as UTF-8.

Development

git add . && git commit -am"Tmkcordovapluginusb" && git push --force origin master

tmk-cordova-plugin-usb's People

Contributors

kaizentmk avatar

Stargazers

 avatar

Watchers

James Cloos 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.