close
Need help upgrading to Ionic Framework 4.0? Get assistance with our Enterprise Migration Services EXPLORE NOW

Serial

Improve this doc

This plugin provides functions for working with Serial connections

Repo: https://github.com/xseignard/cordovarduino

Installation

  1. Install the Cordova and Ionic Native plugins:
    $ ionic cordova plugin add cordovarduino
    $ npm install --save @ionic-native/serial@4
    
  2. Add this plugin to your app's module

Supported platforms

Usage

import { Serial } from '@ionic-native/serial';

constructor(private serial: Serial) { }

...

this.serial.requestPermission().then(() => {
  this.serial.open({
    baudRate: 9800,
    dataBits: 4,
    stopBits: 1,
    parity: 0,
    dtr: true,
    rts: true,
    sleepOnPause: false
  }).then(() => {
    console.log('Serial connection opened');
  });
}).catch((error: any) => console.log(error));

Instance Members

requestPermission(options)

Request permission to connect to a serial device

Param Type Details
options SerialPermissionOptions

Options used to request serial permissions for an unknown device

Returns: Promise<any> Returns a promise that resolves when permissions are granted

open(options)

Open connection to a serial device

Param Type Details
options SerialOpenOptions

Options used to open serial connection

Returns: Promise<any> Returns a promise that resolves when the serial connection is opened

write(data)

Write to a serial connection

Param Type Details
data any

data to write to the serial connection

Returns: Promise<any> Returns a promise that resolves when the write is complete

writeHex(data)

Write hex to a serial connection

Param Type Details
data any

data to write to the serial connection

Returns: Promise<any> Returns a promise that resolves when the write is complete

read()

Read from a serial connection

Returns: Promise<any> Returns a promise that resolves with data read from the serial connection

registerReadCallback()

Watch the incoming data from the serial connection. Clear the watch by unsubscribing from the observable

Returns: Observable<any> Observable returns an observable that you can subscribe to

close()

Close the serial connection

Returns: Promise<any> Returns a promise that resolves when the serial connection is closed

API

Native

General