You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- We now only return a port object if it's open and list and open methods are now exported on an interface
- hardware tests now work and only require a loopback (no ready event)
- Test pass on darwin (not on mock - it's not up to date yet and coverage is going to drop)
- cleanup up tests with modern javascript
- Breaking - change the names of the exported types
- No more constructors, now all binding specicific open options are specificd on open
- Arduino test file for loopback
Copy file name to clipboardExpand all lines: README.md
+1Lines changed: 1 addition & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -31,6 +31,7 @@ The Bindings provide a low level interface to work with your serialport. It is p
31
31
1. Clone this repo `git clone [email protected]:serialport/bindings-cpp.git`
32
32
1. Run `npm install` to setup local package dependencies (run this any time you depend on a package local to this repo)
33
33
1. Run `npm test` to ensure everything is working properly
34
+
1. If you have a serial loopback device (TX to RX) you can run run `TEST_PORT=/path/to/port npm test` for a more comprehensive test suite. (Defaults to 115200 baud customize with the TEST_BAUD env.) You can use an arduino with the `test/arduino-echo` sketch.
Copy file name to clipboardExpand all lines: lib/binding-interface.ts
+45-40Lines changed: 45 additions & 40 deletions
Original file line number
Diff line number
Diff line change
@@ -14,24 +14,28 @@ export interface PortInfo {
14
14
}
15
15
16
16
exportinterfaceOpenOptions{
17
+
/** The path of the port */
18
+
path: string
17
19
/** The baud rate of the port to be opened. This should match one of the commonly available baud rates, such as 110, 300, 1200, 2400, 4800, 9600, 14400, 19200, 38400, 57600, or 115200. Custom rates are supported best effort per platform. The device connected to the serial port is not guaranteed to support the requested baud rate, even if the port itself supports that baud rate. */
18
20
baudRate: number
19
-
/** Must be one of these: 8, 7, 6, or 5 */
20
-
dataBits: 8|7|6|5
21
-
/** Prevent other processes from opening the port. Windows does not currently support `false`. */
22
-
lock: boolean
23
-
stopBits: 1|2
24
-
parity: 'none'|'event'|'mark'|'odd'|'space'
25
-
/** Flow control Setting */
26
-
rtscts: boolean
27
-
/** Flow control Setting */
28
-
xon: boolean
29
-
/** Flow control Setting */
30
-
xoff: boolean
31
-
/** Flow control Setting */
32
-
xany: boolean
33
-
/** drop DTR on close */
34
-
hupcl: boolean
21
+
/** Must be one of these: 8, 7, 6, or 5 defaults to 8 */
22
+
dataBits?: 8|7|6|5
23
+
/** Prevent other processes from opening the port. Windows does not currently support `false`. Defaults to true */
24
+
lock?: boolean
25
+
/** defaults to 1 - TODO should be a string */
26
+
stopBits?: 1|2|3
27
+
/** Device parity defaults to none */
28
+
parity?: 'none'|'event'|'mark'|'odd'|'space'
29
+
/** Flow control Setting. Defaults to false */
30
+
rtscts?: boolean
31
+
/** Flow control Setting. Defaults to false */
32
+
xon?: boolean
33
+
/** Flow control Setting. Defaults to false */
34
+
xoff?: boolean
35
+
/** Flow control Setting defaults to false*/
36
+
xany?: boolean
37
+
/** drop DTR on close. Defaults to true */
38
+
hupcl?: boolean
35
39
}
36
40
37
41
exportinterfaceUpdateOptions{
@@ -56,39 +60,28 @@ export interface PortStatus {
56
60
/**
57
61
* You never have to use `Binding` objects directly. SerialPort uses them to access the underlying hardware. This documentation is geared towards people who are making bindings for different platforms. This interface is implemented in all bindings.
58
62
*/
59
-
exportabstractclassBindingInterface{
60
-
/**
61
-
Retrieves a list of available serial ports with metadata. The `path` must be guaranteed, and all other fields should be undefined if unavailable. The `path` is either the path or an identifier (eg `COM1`) used to open the serialport.
62
-
*/
63
-
staticasynclist(): Promise<PortInfo[]>{
64
-
thrownewError('Method not implemented.')
65
-
}
66
-
63
+
exportinterfaceBindingPortInterface{
64
+
readonlyopenOptions: Required<OpenOptions>
67
65
/**
68
66
* Required property. `true` if the port is open, `false` otherwise. Should be read-only.
69
67
*/
70
-
abstractisOpen: boolean
71
-
72
-
/**
73
-
* Opens a connection to the serial port referenced by the path.
Request a number of bytes from the SerialPort. This function is similar to Node's [`fs.read`](http://nodejs.org/api/fs.html#fs_fs_read_fd_buffer_offset_length_position_callback) except it will always return at least one byte.
76
+
Request a number of bytes from the SerialPort. This function is similar to Node's [`fs.read`](http://nodejs.org/api/fs.html#fs_fs_read_fd_buffer_offset_length_position_callback) as it will attempt to read up to `length` number of bytes. This function has a guarantee that it will always return at least one byte. This leverages os specific polling or async reads so you don't have to.
84
77
85
78
The in progress reads must error when the port is closed with an error object that has the property `canceled` equal to `true`. Any other error will cause a disconnection.
86
79
87
80
* @param offset The offset in the buffer to start writing at.
88
81
* @param length Specifies the maximum number of bytes to read.
89
82
* @returns {Promise} Resolves with the number of bytes read after a read operation.
Retrieves a list of available serial ports with metadata. The `path` must be guaranteed, and all other fields should be undefined if unavailable. The `path` is either the path or an identifier (eg `COM1`) used to open the serialport.
133
+
*/
134
+
list(): Promise<PortInfo[]>
135
+
/**
136
+
* Opens a connection to the serial port referenced by the path.
0 commit comments