rickyc81

Untitled

Oct 23rd, 2020
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. document.addEventListener("DOMContentLoaded", () => {
  2.  
  3. let btn = document.getElementById('btn-start');
  4.  
  5. function asynchronousProcess(index) {
  6.     new Promise( (resolve, reject) => {
  7.  
  8.     const protocol = "https:"
  9.     const ipAddress = "192.168.0.160";
  10.     const xmlHTTPRequestURLMain = `${protocol}${ipAddress}/cgi-bin/fpmate.cgi`;
  11.  
  12.     const dataCommand = `<printerCommand> <directIO command="4229" data="${index}" /> </printerCommand>`;
  13.     //const dataCommand = `<printerCommand> <directIO command="4229" data="255" /> </printerCommand>`;
  14.  
  15.     const epos = new epson.fiscalPrint();
  16.  
  17.         // 4 229 - SCAN CODE REF
  18.     // 4 229 - SCAN CODE REF | FUNCTION
  19.  
  20.     epos.onreceive = (result, tag_names_array, add_info, res_add) => {
  21.         if (result.success == true) {
  22.             resolve(add_info.responseData)
  23.             //console.log(add_info.responseData)
  24.             //fs.appendFileSync('message.json', add_info.responseData);
  25.             //console.log(`N${i}: add_info.responseData`)
  26.         }
  27.     };
  28.     epos.send(xmlHTTPRequestURLMain, dataCommand, 99000);
  29.     });
  30.   }
  31.  
  32.     btn.addEventListener('click', async () => {
  33.     console.log("click")
  34.    
  35.     const j = 255;
  36.         for (let i = 0; i < j; i++) {
  37.  
  38.             if ((i + "").length < 2) {
  39.                 index = "00" + i
  40.             } else if ((i + "").length < 3) {
  41.                 index = "0" + i
  42.             } else {
  43.                 index = i.toString()
  44.             }
  45.             await asynchronousProcess(i)
  46.         }
  47.  
  48.     });
  49. });
Add Comment
Please, Sign In to add comment