UNPKG

dynamixel

Version:

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

149 lines (148 loc) 4.31 kB
/** * Node.js SerialPort Connection Handler (ES Module version) * For use in Node.js environments and Electron main process */ export class SerialConnection extends EventEmitter<[never]> { /** * @typedef {Object} SerialPortInfo * @property {string} path - Port path * @property {string} [manufacturer] - Manufacturer name * @property {string} [vendorId] - Vendor ID * @property {string} [productId] - Product ID * @property {string} [serialNumber] - Serial number * @property {boolean} isU2D2 - Whether this is a U2D2 device */ /** * List available serial ports * @returns {Promise<SerialPortInfo[]>} - Array of available ports */ static listSerialPorts(): Promise<{ /** * - Port path */ path: string; /** * - Manufacturer name */ manufacturer?: string | undefined; /** * - Vendor ID */ vendorId?: string | undefined; /** * - Product ID */ productId?: string | undefined; /** * - Serial number */ serialNumber?: string | undefined; /** * - Whether this is a U2D2 device */ isU2D2: boolean; }[]>; /** * Check if SerialPort is available * @returns {boolean} - True if available */ static isAvailable(): boolean; /** * Get SerialPort module information * @returns {Object} - Module information */ static getModuleInfo(): Object; constructor(options?: {}); port: any; timeout: any; baudRate: any; highWaterMark: any; isConnected: boolean; receiveBuffer: Buffer<ArrayBuffer>; portPath: any; /** * Find and connect to U2D2 device via serial port * @param {string} portPath - Optional specific port path * @returns {Promise<boolean>} - Success status */ connect(portPath?: string): Promise<boolean>; /** * Find U2D2 device port automatically * @returns {Promise<string|null>} - Port path or null if not found */ findU2D2Port(): Promise<string | null>; /** * Disconnect from serial port */ disconnect(): Promise<void>; /** * Process received data buffer */ processReceiveBuffer(): void; /** * Send data to the device * @param {Buffer|Array} data - Data to send */ send(data: Buffer | any[]): Promise<any>; /** * Send packet and wait for response * @param {Buffer} packet - Packet to send * @param {number} expectedId - Expected device ID in response * @param {number} timeout - Timeout in milliseconds * @returns {Promise<Buffer>} - Response packet */ sendAndWaitForResponse(packet: Buffer, expectedId?: number, timeout?: number): Promise<Buffer>; /** * Ping a device * @param {number} id - Device ID * @param {number} timeout - Timeout in milliseconds * @returns {Promise<Object>} - Ping response */ 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 */ /** * Discover 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 * @param {number} baudRate - Baud rate */ setBaudRate(baudRate: number): void; /** * Get current baud rate * @returns {number} - Current baud rate */ getBaudRate(): number; /** * Get connection status * @returns {Object} - Connection status */ getConnectionStatus(): Object; } import { EventEmitter } from 'events';