GithubHelp home page GithubHelp logo

luckxiang / cordova-plugin-serial-port Goto Github PK

View Code? Open in Web Editor NEW
14.0 1.0 12.0 36 KB

ionic3 基于cordova编写的安卓串口通信插件 ionic3 serial port plugins for android

License: MIT License

Java 94.57% JavaScript 5.43%

cordova-plugin-serial-port's Introduction

cordova-plugin-serial-port

ionic3 基于cordova编写的安卓串口通信插件 ionic3 serial port plugins for android

support

  1. read string & hexString
  2. write string & hexString
  3. write data and wait response
  4. read is not block, you must check read data in you application. include response data.
  5. if you recive 2 or more message and do not read in time. you will get all in next read.
  6. UART device does not check data is complete & right. you should have a protocol for exchanging data between two devices.

how to use

  1. add the plugins to your project 'ionic cordova plugins add ./cordova-plugin-serial-port'
  2. 'declare let cordova: any;'before use api. this way not good. can anybody help me?
  3. enjoy

API

openDevice

param:

  • config
  • success callback
  • error callback

config:

  • dev: serial port device node
  • baudrate: serial port baud rate
  • flags: srdial port flags
  • isHex: if you want to use hexString you should set it to true.

example:

cordova.plugins.SerialPortPlugin.openDevice([{dev:'/dev/ttyS0',baudrate:115200, flags:0, isHex:false}],
    result=>alert(result),
    error=>alert(error));
}

closeDevice

example:

cordova.plugins.SerialPortPlugin.closeDevice(
    result=>alert(result),
    error=>alert(error)
);

read

example:

cordova.plugins.SerialPortPlugin.read(
  res=> {
        console.log(res);
        alert(res);
  },
  error=> {
      alert(error);
  });

write

example:

cordova.plugins.SerialPortPlugin.write('12345678900000000000000000000000123',
  res=> {
        console.log(res);
        alert(res);
  },
  error=> {
      alert(error);
  });

sendDataAndWaitResponse

response data maybe not complete,you can use read api to get the rest.

param:

  • arg1: data
  • arg2: timoutMs

example:

cordova.plugins.SerialPortPlugin.sendDataAndWaitResponse('12345678900000000000000000000000123',1000,
  res=> {
        console.log(res);
        alert(res);
  },
  error=> {
      alert(error);
  });

setHex

you can change the hexString | string after openDevice

example:

cordova.plugins.SerialPortPlugin.setHex(true);

cordova-plugin-serial-port's People

Contributors

luckxiang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

cordova-plugin-serial-port's Issues

OpenDevice give undefined result

The following code should work but it returns undefined for result. what would be a compatible es5 function since the example is uing es6 arrow functions?
cordova.plugins.SerialPortPlugin.openDevice([{dev:'/dev/ttyS8',baudrate:9600, flags:0, isHex:false}],
(function (result) {
return alert("result");
})(),
(function (error) {
return alert("error");
})()
);

can't Cut Paper

Hello,
i am able to print width this plugin but i still can't cut paper.

cordova.plugins.SerialPortPlugin.setHex(true);

  cordova.plugins.SerialPortPlugin.write('0x1D',

res=> {
console.log(res);
//alert(res);
},
error=> {
alert(error);
});

  cordova.plugins.SerialPortPlugin.write('0x56',

res=> {
console.log(res);
//alert(res);
},
error=> {
alert(error);
});

Can you help please

Problem with connect

Hello.

I have a problem with the connection to the device.

cordova.plugins.SerialPortPlugin.openSerialPort([{dev:'/dev/ttyS0',baudrate:115200, flags:0}],result=>alert(result),error=>alert(error))

My device connect to dev:'/dev/ttyS1'.

When I try connection to dev:'/dev/ttyS0' I get error with message null& It's good.
When I try connection to dev:'/dev/ttyS1' I get nothing. No error message. No success message. It's bad. But at the same time I expect to get success.

What is it CRC?

Hello.

In your example have CRC. What is it? How to look file ./crc/index.ts?

import  { CRC } from './crc';

several devices

I would like to establish communication with several devices at the same time. How to do it.
dev /dev/ttyS0 and /dev/ttyS1 addresses

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.