mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2025-03-17 09:01:07 +08:00
feat(serial): add Serial plugin (#952)
* style: fix whitespace lint issue * feat(serial): add serial plugin * docs(serial): remove unnecessary comments
This commit is contained in:
parent
1279114b73
commit
ac748abf78
@ -98,6 +98,7 @@ import { Rollbar } from './plugins/rollbar';
|
|||||||
import { SafariViewController } from './plugins/safari-view-controller';
|
import { SafariViewController } from './plugins/safari-view-controller';
|
||||||
import { Screenshot } from './plugins/screenshot';
|
import { Screenshot } from './plugins/screenshot';
|
||||||
import { SecureStorage } from './plugins/securestorage';
|
import { SecureStorage } from './plugins/securestorage';
|
||||||
|
import { Serial } from './plugins/serial';
|
||||||
import { Shake } from './plugins/shake';
|
import { Shake } from './plugins/shake';
|
||||||
import { Sim } from './plugins/sim';
|
import { Sim } from './plugins/sim';
|
||||||
import { SMS } from './plugins/sms';
|
import { SMS } from './plugins/sms';
|
||||||
@ -219,6 +220,7 @@ export * from './plugins/safari-view-controller';
|
|||||||
export * from './plugins/screen-orientation';
|
export * from './plugins/screen-orientation';
|
||||||
export * from './plugins/screenshot';
|
export * from './plugins/screenshot';
|
||||||
export * from './plugins/securestorage';
|
export * from './plugins/securestorage';
|
||||||
|
export * from './plugins/serial';
|
||||||
export * from './plugins/shake';
|
export * from './plugins/shake';
|
||||||
export * from './plugins/sim';
|
export * from './plugins/sim';
|
||||||
export * from './plugins/sms';
|
export * from './plugins/sms';
|
||||||
@ -339,6 +341,7 @@ window['IonicNative'] = {
|
|||||||
SafariViewController,
|
SafariViewController,
|
||||||
Screenshot,
|
Screenshot,
|
||||||
SecureStorage,
|
SecureStorage,
|
||||||
|
Serial,
|
||||||
Shake,
|
Shake,
|
||||||
Sim,
|
Sim,
|
||||||
SMS,
|
SMS,
|
||||||
|
111
src/plugins/serial.ts
Normal file
111
src/plugins/serial.ts
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
import { Plugin, Cordova } from './plugin';
|
||||||
|
import { Observable } from 'rxjs/Observable';
|
||||||
|
|
||||||
|
declare var serial: any;
|
||||||
|
|
||||||
|
export interface SerialPermissionOptions {
|
||||||
|
vid: string;
|
||||||
|
pid: string;
|
||||||
|
driver: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SerialOpenOptions {
|
||||||
|
baudRate: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @name Serial
|
||||||
|
* @description
|
||||||
|
* This plugin provides functions for working with Serial connections
|
||||||
|
*
|
||||||
|
* @usage
|
||||||
|
*
|
||||||
|
* ```
|
||||||
|
* import { Serial } from 'ionic-native';
|
||||||
|
*
|
||||||
|
* Serial.requestPermission({
|
||||||
|
* vid: '0403',
|
||||||
|
* pid: '6001',
|
||||||
|
* driver: 'FtdiSerialDriver'
|
||||||
|
* }).then(() => {
|
||||||
|
* Serial.open({
|
||||||
|
* baudRate: 38400
|
||||||
|
* }).then(() => {
|
||||||
|
* console.log('Serial connection opened');
|
||||||
|
* });
|
||||||
|
* }).catch((error: any) => console.log(error));
|
||||||
|
*
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
@Plugin({
|
||||||
|
pluginName: 'Serial',
|
||||||
|
plugin: 'cordovarduino',
|
||||||
|
pluginRef: 'serial',
|
||||||
|
repo: 'https://github.com/xseignard/cordovarduino',
|
||||||
|
platforms: ['Android']
|
||||||
|
})
|
||||||
|
export class Serial {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request permission to connect to a serial device
|
||||||
|
*
|
||||||
|
* @param options {SerialPermissionOptions} Options used to request serial permissions
|
||||||
|
* @return {Promise<any>} Returns a promise that resolves when permissions are granted
|
||||||
|
*/
|
||||||
|
@Cordova()
|
||||||
|
static requestPermission(options: SerialPermissionOptions): Promise<any> { return; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Open connection to a serial device
|
||||||
|
*
|
||||||
|
* @param options {SerialOpenOptions} Options used to open serial connection
|
||||||
|
* @return {Promise<any>} Returns a promise that resolves when the serial connection is opened
|
||||||
|
*/
|
||||||
|
@Cordova()
|
||||||
|
static open(options: SerialOpenOptions): Promise<any> { return; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write to a serial connection
|
||||||
|
*
|
||||||
|
* @param data {any} data to write to the serial connection
|
||||||
|
* @return {Promise<any>} Returns a promise that resolves when the write is complete
|
||||||
|
*/
|
||||||
|
@Cordova()
|
||||||
|
static write(data: any): Promise<any> { return; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write hex to a serial connection
|
||||||
|
*
|
||||||
|
* @param data {any} data to write to the serial connection
|
||||||
|
* @return {Promise<any>} Returns a promise that resolves when the write is complete
|
||||||
|
*/
|
||||||
|
@Cordova()
|
||||||
|
static writeHex(data: any): Promise<any> { return; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read from a serial connection
|
||||||
|
*
|
||||||
|
* @return {Promise<any>} Returns a promise that resolves with data read from the serial connection
|
||||||
|
*/
|
||||||
|
@Cordova()
|
||||||
|
static read(): Promise<any> { return; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
@Cordova({
|
||||||
|
observable: true
|
||||||
|
})
|
||||||
|
static registerReadCallback(): Observable<any> { return; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close the serial connection
|
||||||
|
*
|
||||||
|
* @return {Promise<any>} Returns a promise that resolves when the serial connection is closed
|
||||||
|
*/
|
||||||
|
@Cordova()
|
||||||
|
static close(): Promise<any> { return; }
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user