UNPKG

dynamixel

Version:

Node.js library for controlling DYNAMIXEL servo motors via U2D2 interface with Protocol 2.0 support

139 lines (138 loc) 4.25 kB
/** * Web Serial API Connection Handler * For use in Electron renderer processes and modern browsers */ export class WebSerialConnection extends EventEmitter<[never]> { /** * Get available serial ports (previously authorized) * @returns {Promise<WebSerialPortInfo[]>} - Array of port info objects */ static getAvailablePorts(): Promise<{ /** * - USB vendor ID */ usbVendorId?: number | undefined; /** * - USB product ID */ usbProductId?: number | undefined; }[]>; /** * Check if Web Serial API is supported * @returns {boolean} - Support status */ static isSupported(): boolean; /** * Get Web Serial API feature detection info * @returns {Object} - Feature support information */ static getFeatureSupport(): Object; constructor(options?: {}); port: any; reader: any; writer: any; timeout: any; baudRate: any; isConnected: boolean; receiveBuffer: Uint8Array<ArrayBuffer>; readPromise: Promise<void> | null; /** * Request and connect to a serial port using Web Serial API * @param {Object} filters - Optional filters for port selection * @returns {Promise<boolean>} - Success status */ connect(filters?: Object): Promise<boolean>; /** * Connect to a previously authorized port (if available) * @returns {Promise<boolean>} - Success status */ connectToPreviousPort(): Promise<boolean>; /** * Disconnect from the serial port */ disconnect(): Promise<void>; /** * Start receiving data from the serial port */ startReceiving(): Promise<void>; /** * Main read loop for processing incoming data */ readLoop(): Promise<void>; /** * Process received data buffer for complete packets */ processReceiveBuffer(): void; /** * Send data to the serial port * @param {Buffer|Uint8Array} data - Data to send * @returns {Promise<boolean>} - Success status */ send(data: Buffer | Uint8Array): Promise<boolean>; /** * Send instruction packet and wait for response * @param {Buffer} packet - Instruction packet to send * @param {number} expectedId - Expected response ID (null for any) * @param {number} timeout - Timeout in milliseconds * @returns {Promise<Object>} - Parsed status packet */ sendAndWaitForResponse(packet: Buffer, expectedId?: number, timeout?: number): Promise<Object>; /** * Ping a specific DYNAMIXEL device * @param {number} id - DYNAMIXEL ID * @param {number} timeout - Timeout in milliseconds * @returns {Promise<Object>} - Device information */ ping(id: number, timeout?: number): Promise<Object>; /** * @typedef {Object} DeviceInfo * @property {number} id - Device ID * @property {number} modelNumber - Device model number * @property {string} modelName - Device model name * @property {number} firmwareVersion - Firmware version */ /** * @typedef {Object} WebSerialPortInfo * @property {number} [usbVendorId] - USB vendor ID * @property {number} [usbProductId] - USB product ID */ /** * Discover all DYNAMIXEL devices on the bus * @param {Object} options - Discovery options * @returns {Promise<DeviceInfo[]>} - Array of discovered devices */ discoverDevices(options?: Object): Promise<{ /** * - Device ID */ id: number; /** * - Device model number */ modelNumber: number; /** * - Device model name */ modelName: string; /** * - Firmware version */ firmwareVersion: number; }[]>; /** * Set baud rate for serial communication * @param {number} baudRate - New baud rate */ setBaudRate(baudRate: number): void; /** * Get current baud rate * @returns {number} - Current baud rate */ getBaudRate(): number; /** * Get connection status * @returns {boolean} - Connection status */ getConnectionStatus(): boolean; } import { EventEmitter } from 'events';