Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Epson thermal printer javascript

I'm trying to use an Epson TM-T20II (thermal printer) via a web page. I've done the necessary configuration and the printer works fine on my network using the given software. So I downloaded the JS epos print SDK, and tried to run this sample code :

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
    <title>TITLE</title>
    <script type="text/javascript" src="../ePOS-Print_SDK/ePOS-Print_SDK_150729E/JavaScript/epos-print-5.0.0.js"></script>
    <script type="text/javascript">
         function buildMessage() {
             //Create an ePOS-Print Builder object
             var builder = new epson.ePOSBuilder();
             //Create a print document
             builder.addTextLang('en')
             builder.addTextSmooth(true);
             builder.addTextFont(builder.FONT_A);
             builder.addTextSize(3, 3);
             builder.addText('Hello,\tWorld!\n');
             builder.addCut(builder.CUT_FEED);
             //Acquire the print document
             var request = builder.toString();
             var address = 'http://192.168.1.65/cgi-bin/epos/service.cgi?devid=99&timeout=1000';
             //Create an ePOS-Print object
             var epos = new epson.ePOSPrint(address);
             epos.onreceive = function (res) {
             //When the printing is not successful, display a message
             if (!res.success) {
                alert('A print error occurred');
                }
             }
             //Send the print document
             epos.send(request);
         }
    </script>
    </head>
    <body>
     <button onclick='buildMessage()'>Run</button>
    </body>
</html>

For the devid parameter I tried 'local_printer' which is the name of the device, then I saw in the configuration panel that the printer id is 99. Still, it doesn't work, I got a 405 Method not allowed status code on the cgi request.

Any tips ? Thanks in advance.

EDIT :

So, after some research, it seems that the problem comes from a CORS request. The request is preflight for security matters, and this preflight request doesn't pass acces control cause the 'Access-Control-Allow-Origin' header is missing from the response. So how do I set this header ?

like image 829
elachere Avatar asked Jan 28 '16 15:01

elachere


1 Answers

With your edit mentioning a CORS issue, perhaps you can try running Chrome with web-security disabled. That should tell chrome to ignore the failing CORS header:

chromium-browser --disable-web-security

https://www.chromium.org/developers/how-tos/run-chromium-with-flags

like image 178
peterholcomb Avatar answered Sep 25 '22 14:09

peterholcomb