/******************************************************************* 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. (c) 3FONIA Software; WWW.3FONIA.COM. *******************************************************************/ var cPOLEDISPLAY = function(port, options){ var _cd_port = ''; var _cd_pole = ''; var _options = { rx: { start: '\x02', end: '\x0D', width: null }, baudRate: 9600, dataBits: 8, stopBits: 1, parity: 'NONE', flowControl: 'NONE' }; this.construct = function (port, options){ $.extend(_options, options); _cd_port = port; }; this.Open = function (){ if (_cd_pole === '') { qz.serial.openPort(_cd_port, _options).then(() => { _cd_pole = _cd_port; this.cd_Error(_cd_port+' opened'); }).then(() => { qz.serial.sendData(_cd_pole, {type:'HEX',data:'x1Bx40'}, _options).catch(this.cd_Error); }).catch(this.cd_Error); } }; this.Close = function (){ qz.serial.closePort(_cd_port).then(() => { _cd_pole = ''; this.cd_Error(_cd_port+' closed'); }).catch(this.cd_Error); }; this.Send = function (txt){ if (_cd_pole === '') return false; var ascii_to_hexa = function(str) { var arr1 = []; for (var n = 0, l = str.length; n < l; n++) { var hex = Number(str.charCodeAt(n)).toString(16); if (hex.length==1) hex = '0' + hex; arr1.push(hex.toUpperCase()); } return 'x' + arr1.join('x'); }; var _txt = txt; if (Array.isArray(txt)) { _txt = ''; txt.forEach((ele) => { _txt += this.cd_Text(ele['t'], ele['a']); }); } qz.serial.sendData(_cd_pole, {type:'HEX',data:'x10C'+ascii_to_hexa(_txt)}, _options).catch(this.cd_Error); }; this.cd_Text = function (text, align){ const totWidth = 20; const txtLength = text.length; if (txtLength >= totWidth) { return text.substring(0, totWidth); } const padding = totWidth - txtLength; var lPadding = 0; var rPadding = padding; if (align === null) align = 'L'; 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); }; this.cd_Error = function (err){ console.error(err); }; this.construct(port, options); };