/******************************************************************* Module : /assets/js/pole-display.js Desc. : JS Class Tampil Data di Pole Display POS Created By : Siau Pheng (siaupheng@3fonia.com). Created Date : October 12th, 2025. Last Modified : November 1st, 2026. (c) 3FONIA Software; WWW.3FONIA.COM. *******************************************************************/ class PoleDisplay { constructor(port, options = {}) { this.port = port; this.pole = ''; this.options = Object.assign({ rx: { start: '\x02', end: '\x0D', width: null }, baudRate: 9600, dataBits: 8, stopBits: 1, parity: 'NONE', flowControl: 'NONE' }, options); } Open() { if (this.pole) return; qz.serial.openPort(this.port, this.options) .then(() => { this.pole = this.port; this.cd_Error(`${this.port} opened`); return qz.serial.sendData(this.pole, { type: 'HEX', data: 'x1Bx40' }, this.options); }) .catch(this.cd_Error); } Close() { if (!this.pole) return; qz.serial.closePort(this.port) .then(() => { this.pole = ''; this.cd_Error(`${this.port} closed`); }) .catch(this.cd_Error); } Send(txt) { if (!this.pole) return false; // Convert string to ASCII hex format const asciiToHex = str => Array.from(str, char => char.charCodeAt(0).toString(16).padStart(2, '0').toUpperCase()) .join('x'); let textToSend = txt; if (Array.isArray(txt)) { textToSend = txt.map(ele => this.cd_Text(ele.t, ele.a)).join(''); } const hexData = `x10C${asciiToHex(textToSend)}`; qz.serial.sendData(this.pole, { type: 'HEX', data: hexData }, this.options) .catch(this.cd_Error); } cd_Text(text, align = 'L') { const totWidth = 20; if (text.length >= totWidth) return text.substring(0, totWidth); const padding = totWidth - text.length; let lPadding = 0, rPadding = padding; if (align === 'C') { lPadding = Math.floor(padding / 2); rPadding = Math.ceil(padding / 2); } else if (align === 'R') { lPadding = padding; rPadding = 0; } return ' '.repeat(lPadding) + text + ' '.repeat(rPadding); } cd_Error(err) { console.error(err); } }