UNPKG

4.72 kBTypeScriptView Raw
1import { Observable } from 'rxjs/Observable';
2/**
3 * @name Bluetooth Serial
4 * @description This plugin enables serial communication over Bluetooth. It was written for communicating between Android or iOS and an Arduino.
5 * @usage
6 * ```typescript
7 * import { BluetoothSerial } from 'ionic-native';
8 *
9 *
10 * // Write a string
11 * BluetoothSerial.write("hello world").then(success, failure);
12 *
13 * // Array of int or bytes
14 * BluetoothSerial.write([186, 220, 222]).then(success, failure);
15 *
16 * // Typed Array
17 * var data = new Uint8Array(4);
18 * data[0] = 0x41;
19 * data[1] = 0x42;
20 * data[2] = 0x43;
21 * data[3] = 0x44;
22 * BluetoothSerial.write(data).then(success, failure);
23 *
24 * // Array Buffer
25 * BluetoothSerial.write(data.buffer).then(success, failure);
26 * ```
27 */
28export declare class BluetoothSerial {
29 /**
30 * Connect to a Bluetooth device
31 * @param {string} macAddress_or_uuid Identifier of the remote device
32 * @returns {Observable<any>} Subscribe to connect, unsubscribe to disconnect.
33 */
34 static connect(macAddress_or_uuid: string): Observable<any>;
35 /**
36 * Connect insecurely to a Bluetooth device
37 * @param {string} macAddress Identifier of the remote device
38 * @returns {Observable<any>} Subscribe to connect, unsubscribe to disconnect.
39 */
40 static connectInsecure(macAddress: string): Observable<any>;
41 /**
42 * Disconnect from the connected device
43 * @returns {Promise<any>}
44 */
45 static disconnect(): Promise<any>;
46 /**
47 * Writes data to the serial port
48 * @param {any} data ArrayBuffer of data
49 * @returns {Promise<any>} returns a promise when data has been written
50 */
51 static write(data: any): Promise<any>;
52 /**
53 * Gets the number of bytes of data available
54 * @returns {Promise<any>} returns a promise that contains the available bytes
55 */
56 static available(): Promise<any>;
57 /**
58 * Reads data from the buffer
59 * @returns {Promise<any>} returns a promise with data from the buffer
60 */
61 static read(): Promise<any>;
62 /**
63 * Reads data from the buffer until it reaches a delimiter
64 * @param {string} delimiter string that you want to search until
65 * @returns {Promise<any>} returns a promise
66 */
67 static readUntil(delimiter: string): Promise<any>;
68 /**
69 * Subscribe to be notified when data is received
70 * @param {string} delimiter the string you want to watch for
71 * @returns {Observable<any>} returns an observable.
72 */
73 static subscribe(delimiter: string): Observable<any>;
74 /**
75 * Subscribe to be notified when data is received
76 * @returns {Observable<any>} returns an observable
77 */
78 static subscribeRawData(): Observable<any>;
79 /**
80 * Clears data in buffer
81 * @returns {Promise<any>} returns a promise when completed
82 */
83 static clear(): Promise<any>;
84 /**
85 * Lists bonded devices
86 * @returns {Promise<any>} returns a promise
87 */
88 static list(): Promise<any>;
89 /**
90 * Reports if bluetooth is enabled
91 * @returns {Promise<any>} returns a promise
92 */
93 static isEnabled(): Promise<any>;
94 /**
95 * Reports the connection status
96 * @returns {Promise<any>} returns a promise
97 */
98 static isConnected(): Promise<any>;
99 /**
100 * Reads the RSSI from the connected peripheral
101 * @returns {Promise<any>} returns a promise
102 */
103 static readRSSI(): Promise<any>;
104 /**
105 * Show the Bluetooth settings on the device
106 * @returns {Promise<any>} returns a promise
107 */
108 static showBluetoothSettings(): Promise<any>;
109 /**
110 * Enable Bluetooth on the device
111 * @returns {Promise<any>} returns a promise
112 */
113 static enable(): Promise<any>;
114 /**
115 * Discover unpaired devices
116 * @returns {Promise<any>} returns a promise
117 */
118 static discoverUnpaired(): Promise<any>;
119 /**
120 * Subscribe to be notified on Bluetooth device discovery. Discovery process must be initiated with the `discoverUnpaired` function.
121 * @returns {Observable<any>} Returns an observable
122 */
123 static setDeviceDiscoveredListener(): Observable<any>;
124 /**
125 * Sets the human readable device name that is broadcasted to other devices
126 * @param {string} newName Desired name of device
127 */
128 static setName(newName: string): void;
129 /**
130 * Makes the device discoverable by other devices
131 * @param {number} discoverableDuration Desired number of seconds device should be discoverable for
132 */
133 static setDiscoverable(discoverableDuration: number): void;
134}