Skip to content

Commit a70bd73

Browse files
committed
Rename Device to Port and update related interfaces
Renamed the Device interface to Port, updated all references and documentation to use the new naming, and changed method names and example code accordingly. This improves clarity by aligning terminology with serial port conventions.
1 parent a9b142f commit a70bd73

4 files changed

Lines changed: 22 additions & 22 deletions

File tree

src/connection/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66

77
export { baudrates, type Baudrate } from './baudrates.ts';
88
export { dataBits, type DataBits } from './data_bits.ts';
9-
export { type Device } from './device.ts';
9+
export { type Port } from './port.ts';
1010
export { parities, type Parity } from './parities.ts'
1111
export { stopBits, type StopBits } from './stop_bits.ts'
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
/**
2-
* This interface represents a device object.
2+
* This interface represents a port object.
33
*/
4-
export interface Device {
4+
export interface Port {
55
/**
66
* The name of the port (ex. `ttyACM2`, `COM5`, ...)
77
*/
8-
port : string,
8+
name : string,
99

1010
/**
1111
* The full path to the port. (ex. `/dev/ttyACM2`, `\\\\?\\acpi#pnp0501#0#{86e0d1e0-8089-11d0-9ce4-08003e301f73}`, ...)
1212
*/
1313
path : string,
1414

1515
/**
16-
* The manufacturer of the device. (ex. `Arduino (www.arduino.cc)`, `Arduino LLC (www.arduino.cc)`, ...)
16+
* The manufacturer of the device, connected to the port. (ex. `Arduino (www.arduino.cc)`, `Arduino LLC (www.arduino.cc)`, ...)
1717
*/
1818
manufacturer : string | undefined,
1919

2020
/**
21-
* The serial number of the device. (ex. `698471028216477376C1`, ...)
21+
* The serial number of the device, connected to the port. (ex. `698471028216477376C1`, ...)
2222
*/
2323
serialNumber : string | undefined,
2424

2525
/**
26-
* The Plug and Play ID of the device. (ex. `usb-Arduino__www.arduino.cc__0043_698471028216477376-if00`,
26+
* The Plug and Play ID of the device, connected to the port. (ex. `usb-Arduino__www.arduino.cc__0043_698471028216477376-if00`,
2727
* `USB\\VID_5678&PID_1234\\698471028216477376`, ...)
2828
*/
2929
pnpId : string | undefined,
@@ -34,12 +34,12 @@ export interface Device {
3434
locationId : string | undefined,
3535

3636
/**
37-
* The product ID of the device. (ex. `1234`)
37+
* The product ID of the device, connected to the port. (ex. `1234`)
3838
*/
3939
productId : string | undefined,
4040

4141
/**
42-
* The vendor ID of the device. (ex. `5678`)
42+
* The vendor ID of the device, connected to the port. (ex. `5678`)
4343
*/
4444
vendorId : string | undefined
4545
}

src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
*
44
* @example
55
* ```ts
6-
* const devices = await Serial.getDevices();
6+
* const ports = await Serial.listPorts();
77
*
8-
* devices.forEach((device) => {
9-
* console.log(`Found device "${device.manufacturer}" on port "${device.port}".`);
8+
* ports.forEach((port) => {
9+
* console.log(`Found device "${port.manufacturer}" on port "${port.name}".`);
1010
* // Found device "Arduino (www.arduino.cc)" on port "COM5".
1111
* });
1212
*

src/serial.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { dataBits, parities, stopBits, type Device } from './connection/index.ts';
1+
import { dataBits, parities, stopBits, type Port } from './connection/index.ts';
22
import type { read, write } from './operations/index.ts';
33
import type { Options } from './options.ts';
44

@@ -8,10 +8,10 @@ import type { Options } from './options.ts';
88
*
99
* @example
1010
* ```ts
11-
* const devices = await Serial.getDevices();
11+
* const ports = await Serial.listPorts();
1212
*
13-
* devices.forEach((device) => {
14-
* console.log(`Found device "${device.manufacturer}" on port "${device.port}".`);
13+
* ports.forEach((port) => {
14+
* console.log(`Found device "${port.manufacturer}" on port "${port.name}".`);
1515
* // Found device "Arduino (www.arduino.cc)" on port "COM5".
1616
* });
1717
*
@@ -65,20 +65,20 @@ export class Serial {
6565
}
6666

6767
/**
68-
* Get a list of available serial devices.
68+
* List all available serial ports.
6969
*
7070
* @example
7171
* ```ts
72-
* const devices = await Serial.getDevices();
72+
* const ports = await Serial.listPorts();
7373
*
74-
* devices.forEach((device) => {
75-
* console.log(`Found device "${device.manufacturer}" on port "${device.port}".`);
74+
* ports.forEach((port) => {
75+
* console.log(`Found device "${port.manufacturer}" on port "${port.name}".`);
7676
* // Found device "Arduino (www.arduino.cc)" on port "COM5".
7777
* });
7878
* ```
79-
* @returns A list of available devices.
79+
* @returns A list of available ports.
8080
*/
81-
public static getDevices() : Promise<Device[]> {
81+
public static listPorts() : Promise<Port[]> {
8282
return new Promise((resolve) => resolve([]))
8383
}
8484

0 commit comments

Comments
 (0)