-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add cordovarduino serial plugin #952
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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', // npm package name, example: cordova-plugin-camera | ||
pluginRef: 'serial', // the variable reference to call the plugin, example: navigator.geolocation | ||
repo: 'https://github.com/xseignard/cordovarduino', // the github repository URL for the plugin | ||
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; } | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove the comments in the 3 lines above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed these, thank you for catching that!