Код: Выделить всё
async connectPrinter(printerName) {
try {
console.log('Connecting to printer:', printerName);
const printers = await this.detectPrinters();
const exists = printers.some(p => p.name === printerName);
if (!exists) {
return {
success: false,
message: 'Printer not found',
error: `Printer "${printerName}" not found in system`
};
}
// Initialize thermal printer using node-thermal-printer
this.printer = new ThermalPrinter({
type: PrinterTypes.EPSON,
interface: printerName,
characterSet: CharacterSet.PC852_LATIN2,
lineCharacter: '═',
width: 42,
removeSpecialCharacters: false
});
// Test connection with a simple command
await this._testPrinterConnection();
this.connectedPrinterName = printerName;
console.log('✓ Successfully connected to:', printerName);
return {
success: true,
message: `Connected to: ${printerName}`,
printer: printerName
};
} catch (error) {
console.error('Printer connection error:', error);
this.printer = null;
return {
success: false,
message: 'Connection failed',
error: error.message
};
}
}
Подробнее здесь: https://stackoverflow.com/questions/798 ... t-printing