javascript - Error connecting to TM-U220 -


i have downloaded 2 javascript sdk epson printer supports tm-u220, , both of them won't connect printer , won't print. when tried use other sdk such qz tray, worked, qz tray must turned on, want work in android, use javascript sdk epson.

problem when use printer sample epson provided in javascript sdk , input ip: 192.168.1.98, port: 9100, , device id: local_printer, got error :

connected epos device service interface failed. [error_timeout]

.
printer did small printing, letter can't read, , @ end of print : 2http/1.1. , in 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 created own simple code. 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 , 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 , 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 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 error message if system fails retreive printer object                     return;                 }                 printer = deviceobj;                  // registers print complete event                 printer.onreceive = function(response) {                     if (response.success) {                         // displays 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 , disconnection)             function send() {                 if (eposdev.isconnected) {                     printer.send();                 }             }             // sending print data (printing , disconnection)         </script>     </head>     <body>         <input type="button" onclick="connect()" value="connect" />         <input type="button" onclick="send()" value="print hello world" />     </body> </html> 


, 1 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 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 epos-print object                 var epos = new epson.eposprint(address);                 //send print document                 epos.send(request);             }         </script>     </head>     <body>         <button onclick="buildmessage()">run</button>      </body> </html> 

when run second code, got error in 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 preflight request doesn't pass access control check: no 'access-control-allow-origin' header present on requested resource. origin 'null' therefore not allowed access. response had http status code 405.


when change 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
printed me :

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, 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

from of it, cross origin http request issue (cors). mdn article explains this: https://developer.mozilla.org/en-us/docs/web/http/access_control_cors

i guessing ip 92.168.1.98 printer ip (which on local network). see: http://trendblog.net/ever-wondered-use-192-168-x-x-ip-addresses-home/ , can access via port 9100 described in post above.

so since actual web application residing on different ip printer ip , way web work, cors required when calling different ip / host prevent cross site scripting attack.

it's common sense if printer exposing via port 9100, should have part of uri. reason why http://192.168.1.98:9100/cgi-bin/epos/service.cgi?devid=local_printer&timeout=10000 works , other 1 did not.

as trying access via android device... question device joined local network (192.168....) or on internet? if joined internet, don't think can access printer not going exposed internet (having public ip). long belong same network, should able talk. if not, need expose internet (bad idea) or make sure can see each other (android connecting corporate wifi , printer can reached via wifi).


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -