UNPKG

dynamixel

Version:

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

269 lines (268 loc) 7.36 kB
/** * U2D2 USB to TTL connection handler (ES Module version) * Manages USB communication with DYNAMIXEL devices through U2D2 */ export class U2D2Connection extends EventEmitter<[never]> { /** * @typedef {Object} USBDeviceInfo * @property {number} vendorId - USB vendor ID * @property {number} productId - USB product ID * @property {number} busNumber - USB bus number * @property {number} deviceAddress - Device address on bus * @property {boolean} isU2D2 - Whether this is a U2D2 device */ /** * @typedef {Object} SystemInfo * @property {string} platform - Operating system platform * @property {string} arch - System architecture * @property {string} nodeVersion - Node.js version * @property {boolean} usbAvailable - Whether USB module is available * @property {string} usbVersion - USB module version info */ /** * @typedef {Object} USBDiagnostics * @property {boolean} usbModuleAvailable - Whether USB module is available * @property {USBDeviceInfo[]} u2d2Devices - Found U2D2 devices * @property {USBDeviceInfo[]} allDevices - All USB devices * @property {string[]} errors - Array of error messages * @property {number} totalDevices - Total number of USB devices * @property {SystemInfo} systemInfo - System information */ /** * List available USB devices * @returns {USBDeviceInfo[]} - Array of USB devices */ static listUSBDevices(): { /** * - USB vendor ID */ vendorId: number; /** * - USB product ID */ productId: number; /** * - USB bus number */ busNumber: number; /** * - Device address on bus */ deviceAddress: number; /** * - Whether this is a U2D2 device */ isU2D2: boolean; }[]; /** * Get system information * @returns {SystemInfo} - System information */ static getSystemInfo(): { /** * - Operating system platform */ platform: string; /** * - System architecture */ arch: string; /** * - Node.js version */ nodeVersion: string; /** * - Whether USB module is available */ usbAvailable: boolean; /** * - USB module version info */ usbVersion: string; }; /** * Perform USB diagnostics * @returns {USBDiagnostics} - Diagnostic results */ static performUSBDiagnostics(): { /** * - Whether USB module is available */ usbModuleAvailable: boolean; /** * - Found U2D2 devices */ u2d2Devices: { /** * - USB vendor ID */ vendorId: number; /** * - USB product ID */ productId: number; /** * - USB bus number */ busNumber: number; /** * - Device address on bus */ deviceAddress: number; /** * - Whether this is a U2D2 device */ isU2D2: boolean; }[]; /** * - All USB devices */ allDevices: { /** * - USB vendor ID */ vendorId: number; /** * - USB product ID */ productId: number; /** * - USB bus number */ busNumber: number; /** * - Device address on bus */ deviceAddress: number; /** * - Whether this is a U2D2 device */ isU2D2: boolean; }[]; /** * - Array of error messages */ errors: string[]; /** * - Total number of USB devices */ totalDevices: number; /** * - System information */ systemInfo: { /** * - Operating system platform */ platform: string; /** * - System architecture */ arch: string; /** * - Node.js version */ nodeVersion: string; /** * - Whether USB module is available */ usbAvailable: boolean; /** * - USB module version info */ usbVersion: string; }; }; constructor(options?: {}); device: any; interface: any; endpoint: any; timeout: any; isConnected: boolean; receiveBuffer: Buffer<ArrayBuffer>; /** * Find and connect to U2D2 device * @returns {Promise<boolean>} - Success status */ connect(): Promise<boolean>; inEndpoint: any; outEndpoint: any; /** * Disconnect from U2D2 device */ disconnect(): Promise<void>; /** * Start receiving data from the device */ startReceiving(): 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 (placeholder - U2D2 handles this automatically) * @param {number} baudRate - 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';