vsi-capacitor-serial
v0.0.1
Published
Serial port communication
Downloads
77
Readme
capacitor-serial
Serial port communication
Install
npm install capacitor-serial
npx cap sync
API
getDevices()
selectDevice(...)
requestPort(...)
open(...)
close()
write(...)
addListener('connected', ...)
addListener('disconnected', ...)
addListener('read', ...)
- Interfaces
- Type Aliases
getDevices()
getDevices() => Promise<ISerialDevices>
Returns: Promise<ISerialDevices>
selectDevice(...)
selectDevice(deviceId: number) => Promise<void>
| Param | Type |
| -------------- | ------------------- |
| deviceId
| number |
requestPort(...)
requestPort(params?: SerialPortRequestOptions | undefined) => Promise<ISerialPort>
| Param | Type |
| ------------ | ----------------------------------------------------------------------------- |
| params
| SerialPortRequestOptions |
Returns: Promise<ISerialPort>
open(...)
open(params: SerialOptions) => Promise<void>
| Param | Type |
| ------------ | ------------------------------------------------------- |
| params
| SerialOptions |
close()
close() => Promise<void>
write(...)
write(data: SerialPortData) => Promise<void>
| Param | Type |
| ---------- | --------------------------------------------------------- |
| data
| SerialPortData |
addListener('connected', ...)
addListener(eventName: 'connected', listenerFunc: (response: ISerialConnectionEvent) => void) => Promise<PluginListenerHandle>
| Param | Type |
| ------------------ | ------------------------------------------------------------------------------------------------ |
| eventName
| 'connected' |
| listenerFunc
| (response: ISerialConnectionEvent) => void |
Returns: Promise<PluginListenerHandle>
addListener('disconnected', ...)
addListener(eventName: 'disconnected', listenerFunc: (response: ISerialConnectionEvent) => void) => Promise<PluginListenerHandle>
| Param | Type |
| ------------------ | ------------------------------------------------------------------------------------------------ |
| eventName
| 'disconnected' |
| listenerFunc
| (response: ISerialConnectionEvent) => void |
Returns: Promise<PluginListenerHandle>
addListener('read', ...)
addListener(eventName: 'read', listenerFunc: (response: ISerialReadDataEvent) => void) => Promise<PluginListenerHandle>
| Param | Type |
| ------------------ | -------------------------------------------------------------------------------------------- |
| eventName
| 'read' |
| listenerFunc
| (response: ISerialReadDataEvent) => void |
Returns: Promise<PluginListenerHandle>
Interfaces
ISerialDevices
| Prop | Type |
| ---------- | -------------------------- |
| list
| ISerialPort[] |
ISerialPort
| Prop | Type |
| ---------------------- | ------------------- |
| portId
| number |
| portName
| string |
| deviceInstanceId
| number |
| displayName
| string |
| productId
| number |
| vendorId
| number |
| usbDriverName
| string |
SerialPortRequestOptions
| Prop | Type | Description |
| ------------------------------------- | --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| filters
| SerialPortFilter[] | |
| allowedBluetoothServiceClassIds
| (string | number)[] | A list of BluetoothServiceUUID values representing Bluetooth service class IDs. Bluetooth ports with custom service class IDs are excluded from the list of ports presented to the user unless the service class ID is included in this list. {@link https://wicg.github.io/serial/#serialportrequestoptions-dictionary} |
SerialPortFilter
| Prop | Type |
| ----------------------------- | ----------------------------- |
| usbVendorId
| number |
| usbProductId
| number |
| bluetoothServiceClassId
| string | number |
Array
| Prop | Type | Description |
| ------------ | ------------------- | ------------------------------------------------------------------------------------------------------ |
| length
| number | Gets or sets the length of the array. This is a number one higher than the highest index in the array. |
| Method | Signature | Description | | ------------------ | ----------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | toString | () => string | Returns a string representation of an array. | | toLocaleString | () => string | Returns a string representation of an array. The elements are converted to string using their toLocalString methods. | | pop | () => T | undefined | Removes the last element from an array and returns it. If the array is empty, undefined is returned and the array is not modified. | | push | (...items: T[]) => number | Appends new elements to the end of an array, and returns the new length of the array. | | concat | (...items: ConcatArray<T>[]) => T[] | Combines two or more arrays. This method returns a new array without modifying any existing arrays. | | concat | (...items: (T | ConcatArray<T>)[]) => T[] | Combines two or more arrays. This method returns a new array without modifying any existing arrays. | | join | (separator?: string | undefined) => string | Adds all the elements of an array into a string, separated by the specified separator string. | | reverse | () => T[] | Reverses the elements in an array in place. This method mutates the array and returns a reference to the same array. | | shift | () => T | undefined | Removes the first element from an array and returns it. If the array is empty, undefined is returned and the array is not modified. | | slice | (start?: number | undefined, end?: number | undefined) => T[] | Returns a copy of a section of an array. For both start and end, a negative index can be used to indicate an offset from the end of the array. For example, -2 refers to the second to last element of the array. | | sort | (compareFn?: ((a: T, b: T) => number) | undefined) => this | Sorts an array in place. This method mutates the array and returns a reference to the same array. | | splice | (start: number, deleteCount?: number | undefined) => T[] | Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements. | | splice | (start: number, deleteCount: number, ...items: T[]) => T[] | Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements. | | unshift | (...items: T[]) => number | Inserts new elements at the start of an array, and returns the new length of the array. | | indexOf | (searchElement: T, fromIndex?: number | undefined) => number | Returns the index of the first occurrence of a value in an array, or -1 if it is not present. | | lastIndexOf | (searchElement: T, fromIndex?: number | undefined) => number | Returns the index of the last occurrence of a specified value in an array, or -1 if it is not present. | | every | <S extends T>(predicate: (value: T, index: number, array: T[]) => value is S, thisArg?: any) => this is S[] | Determines whether all the members of an array satisfy the specified test. | | every | (predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any) => boolean | Determines whether all the members of an array satisfy the specified test. | | some | (predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any) => boolean | Determines whether the specified callback function returns true for any element of an array. | | forEach | (callbackfn: (value: T, index: number, array: T[]) => void, thisArg?: any) => void | Performs the specified action for each element in an array. | | map | <U>(callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any) => U[] | Calls a defined callback function on each element of an array, and returns an array that contains the results. | | filter | <S extends T>(predicate: (value: T, index: number, array: T[]) => value is S, thisArg?: any) => S[] | Returns the elements of an array that meet the condition specified in a callback function. | | filter | (predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any) => T[] | Returns the elements of an array that meet the condition specified in a callback function. | | reduce | (callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T) => T | Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. | | reduce | (callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T) => T | | | reduce | <U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U) => U | Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. | | reduceRight | (callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T) => T | Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. | | reduceRight | (callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T) => T | | | reduceRight | <U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U) => U | Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. |
ConcatArray
| Prop | Type |
| ------------ | ------------------- |
| length
| number |
| Method | Signature | | --------- | ------------------------------------------------------------------ | | join | (separator?: string | undefined) => string | | slice | (start?: number | undefined, end?: number | undefined) => T[] |
SerialOptions
| Prop | Type |
| ----------------- | ----------------------------------------------------------- |
| baudRate
| number |
| dataBits
| number |
| stopBits
| number |
| parity
| ParityType |
| bufferSize
| number |
| flowControl
| FlowControlType |
SerialPortData
| Prop | Type |
| ---------- | ------------------- |
| data
| string |
PluginListenerHandle
| Prop | Type |
| ------------ | ----------------------------------------- |
| remove
| () => Promise<void> |
ISerialConnectionEvent
| Prop | Type |
| ---------------- | ------------------------------------------------------------- |
| action
| ConnectionAction |
| deviceName
| string |
ISerialReadDataEvent
| Prop | Type |
| ---------- | ------------------- |
| data
| string |
Type Aliases
ParityType
"none" | "even" | "odd"
FlowControlType
"none" | "hardware"
ConnectionAction
'DISCONNECTED' | 'CONNECTED'