5

I have downloaded 2 javascript SDK for Epson printer that supports TM-U220, and both of them won't connect to my printer and won't print. But when I tried to use other SDK such as QZ Tray, it worked, but the QZ Tray must be turned on, I want this to work in android, so I use the javascript SDK from Epson.

The problem is when I use the printer sample that Epson provided in the javascript SDK and input the ip: 192.168.1.98, port: 9100, and device id: local_printer, I got this error :

connected to ePOS Device Service Interface is failed. [ERROR_TIMEOUT]

.
But the printer did a small printing, letter that I can't read, and at the very end of the print : 2http/1.1. And in the console :

OPTIONS https://192.168.1.98/cgi-bin/epos/service.cgi?devid=local_printer&timeout=10000 net::ERR_CONNECTION_REFUSED


and

OPTIONS https://192.168.1.98/cgi-bin/eposDisp/service.cgi?devid=local_display&timeout=10000 net::ERR_CONNECTION_REFUSED


I've also created my own simple code. This is my first code using epos-2.3.0.js :

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title>Print Test</title>

        <script type="text/javascript" src="epos-2.3.0.js"></script>

        <script type="text/javascript">
            // Retrieving Printer objects (printer selection)
            var printer = null;
            // Retrieving Printer objects (printer selection)

            // Creating ePOSDevice objects (device connection and communication)
            var ePosDev = new epson.ePOSDevice();

            function connect() {
                var ipAddress = '192.168.1.98'; var port = '9100';
                ePosDev.connect(ipAddress, port, callback_connect);
            }
            // Creating ePOSDevice objects (device connection and communication)

            // Retrieving Printer objects (printer selection)
            function callback_connect(resultConnect) {
                var deviceId = 'local_printer';
                var options = {'crypto' : false, 'buffer' : false};

                if ((resultConnect == 'OK') || (resultConnect == 'SSL_CONNECT_OK')) {
                    // Retrieves the printer object
                    alert("Success callback connect");
                    ePostDev.createDevice(deviceId, ePosDev.DEVICE_TYPE_PRINTER, options, callback_createDevice);
                }
                else {
                    // Displays error messages
                    alert("Error callback connect");
                }
            }

            function callback_createDevice(deviceObj, errorCode) {
                if (deviceObj === null) {
                    // Displays an error message if the system fails to retreive the printer object
                    return;
                }
                printer = deviceObj;

                // Registers the print complete event
                printer.onreceive = function(response) {
                    if (response.success) {
                        // Displays the successful print message
                        alert("Callback create device response success");
                    }
                    else {
                        // Displays error messages
                        alert("Callback create device response failed");
                    }
                }
            }
            // Retrieving Printer objects (printer selection)

            // Creating print data (data buffering)
            function createData() {
                printer.addTextAlign(printer.ALIGN_CENTER);
                printer.addText('Hello World\n');
            }
            // Creating print data (data buffering)

            // Sending print data (printing and disconnection)
            function send() {
                if (ePosDev.isConnected) {
                    printer.send();
                }
            }
            // Sending print data (printing and disconnection)
        </script>
    </head>
    <body>
        <input type="button" onclick="connect()" value="Connect" />
        <input type="button" onClick="send()" value="Print Hello World" />
    </body>
</html>


And this one I'm using epos-print-3.2.0.js :

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title>Print Test 2</title>
        <script type="text/javascript" src="epos-print-3.2.0.js"></script>
        <script type="text/javascript">
            function buildMessage() {
                // Create a print document
                var builder = new epson.ePOSBuilder();
                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);
                var request = builder.toString();

                var address = 'http://192.168.1.98/cgi-bin/epos/service.cgi?devid=local_printer&timeout=10000';

                // Create an ePOS-Print object
                var epos = new epson.ePOSPrint(address);
                //Send the print document
                epos.send(request);
            }
        </script>
    </head>
    <body>
        <button onclick="buildMessage()">Run</button> 
    </body>
</html>

When I run the second code, I got this error in my console :

OPTIONS http://192.168.1.98/cgi-bin/epos/service.cgi?devid=local_printer&timeout=10000


and

XMLHttpRequest cannot load http://192.168.1.98/cgi-bin/epos/service.cgi?devid=local_printer&timeout=10000. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 405.


But When I change the address from
http://192.168.1.98/cgi-bin/epos/service.cgi?devid=local_printer&timeout=10000
to
http://192.168.1.98:9100/cgi-bin/epos/service.cgi?devid=local_printer&timeout=10000
it printed me this :

OPTIONS /cgi-bin/epos/service.cgi?devid=local-printer&timeout=10000 HTTP/1.1
Host: 192.168.1.98:9100
Connection: keep-alive Access-Control-Request-Method: POST
Origin: null
User-Agent: Mizilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36
Access-Control-Request-Headers: content-type, if-modified-since, soapaction
Accept: */*
Accept-Encoding: gzip, deflate,sdch
Accept=Language: en-US, en;q=0.8

4 Answers4

2

I was getting the same errors for a new TM-T88VI. Then I saw in the ePOS SDK User's Manual that in order to control a TM printer you need to enable the ePOS-Print setting from within the EpsonNet Config on the printer.

Looking at the manual in order to control a TM-U220 directly (without using a TM Intelligent printer) you'll need to have a UB-E04 or UB-R04 network interface installed. It says you can check which interfaces are installed by printing a status sheet.

1

From the look of it, this is a Cross Origin HTTP Request issue (CORS). This MDN article explains this: https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS

I am guessing that the IP 92.168.1.98 is the printer IP (which is on the local network). See: http://trendblog.net/ever-wondered-use-192-168-x-x-ip-addresses-home/ and you can access it via port 9100 as described in your post above.

So since your actual web application is residing on a different IP than the printer IP and the way the web work, CORS is required when you are calling to a different IP / host so to prevent cross site scripting attack.

It's common sense that if the printer is exposing itself via port 9100, you should have that as part of your URI. That is the reason why http://192.168.1.98:9100/cgi-bin/epos/service.cgi?devid=local_printer&timeout=10000 works and the other one did not.

As for trying to access this via an Android device... the question is does the device is joined to your local network (192.168....) or is it on the Internet? If it is joined to the internet, I don't think you can access the printer which is probably not going to be exposed to the internet (having public IP). As long as they belong to the same network, they should be able to talk. If not, you will need to expose it to the internet (bad idea) or make sure they can see each other (Android connecting to your corporate WIFI and the printer can be reached via the WIFI).

Jimmy Chandra
  • 6,472
  • 4
  • 26
  • 38
  • Hi @JimmyChandra, thankyou for your respond, actually I want to access my printer via local network, and yes my device is joined to my local network and it has the same segment 192.168.1.x, if it's not in the same segment it won't connect. So what do you think I should do? – Michael Reno Pratama Setyawan Sep 19 '16 at 02:48
  • I've followed the Cross Origin HTTP Request and I still can't connect to the printer. I've download an app called TM Utitlity in play store and when I connect it to my local network, it can connect to my printer and it can print a sample receipt from the TM Utility app. – Michael Reno Pratama Setyawan Sep 19 '16 at 04:16
  • I am not a networking expert, but I think it has something to do w/ routing You are trying to talk to a different subnet and if the routing is not configured correctly, you won't be able to I think. See http://superuser.com/questions/860949/communicating-with-devices-on-a-different-subnet Maybe it can give you hint on how to set this up or talk to your network IT person to get help. I suggest if this is too hard, configure everything in the same subnet... See if they can talk that way. If it can, then it is most likely network issue. – Jimmy Chandra Sep 20 '16 at 03:40
  • Not sure how that TM utility work but from what you described in the question it is definitely CORS related (your app is trying to communicate to a different address via AJAX and so you need to account fro all the CORS stuff). If the printer is CORS enabled, you shouldn't have too much issue. If it is not, then you will probably need to proxy your request to your server side and use HttpRequest from server side to that printer to avoid CORS issue. – Jimmy Chandra Sep 20 '16 at 03:43
0

I had the same problem with a TM-T20III. You have to use the utility software from Epson for your printer. In the advanced network settings, there is a menu which call "Filters" and I add the IP address of my POS as accept address.

desertnaut
  • 57,590
  • 26
  • 140
  • 166
0

But When I change the address from http://192.168.1.98/cgi-bin/epos/service.cgi?devid=local_printer&timeout=10000 to http://192.168.1.98:9100/cgi-bin/epos/service.cgi?devid=local_printer&timeout=10000 it printed me this :

Port 9100 is the raw input port of the printer, it seems to print the whole input request without interpreting it. ePOS Service seems to be available on ports 80 / 443.

I was getting the same errors for a new TM-T88VI. Then I saw in the ePOS SDK User's Manual that in order to control a TM printer you need to enable the ePOS-Print setting from within the EpsonNet Config on the printer.

Enabling the ePOS Print Service was the right solution for me. In order to do this, i had to update the firmware of the printer (TM-T88VI). In factory defaults, there was no option to switch on the ePOS Service.

b56
  • 48
  • 1
  • 4