我已经为爱普生打印机下载了 2 个 javascript SDK,支持 TM-U220,并且它们都不会连接到我的打印机,也不会打印。但是当我尝试使用其他 SDK(例如 QZ Tray)时,它可以工作,但是必须打开 QZ Tray id,我希望它在 android 中工作,因此我使用了来自 Epson 的 javascript SDK。
连接到 ePOS 设备服务接口失败。[ERROR_TIMEOUT]
。
但是打印机做了一个小打印,我无法阅读的字母,并且在打印的最后:2http / 1.1。而在控制台中:
选项https://192.168.1.98/cgi-bin/epos/service.cgi?devid=local_printer&timeout=10000net::ERR_CONNECTION_REFUSED
and
选项https://192.168.1.98/cgi-bin/eposDisp/service.cgi?devid=local_display&timeout=10000net::ERR_CONNECTION_REFUSED
我还创建了自己的简单代码。这是我使用epos-2.3.0.js的第一个代码:
<!DOCTYPE html>
<html>
<head>
<meta cht="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="on" onclick="connect()" value="Connect" />
<input type="on" onClick="send()" value="Print Hello World" />
</body>
</html>
这个我正在使用epos-print-3.2.0.js:
<!DOCTYPE html>
<html>
<head>
<meta cht="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>
<on onclick="buildMessage()">Run</on>
</body>
</html>
当我运行第二个代码时,我在控制台中收到此错误:
OPTIONShttp://192.168.1.98/cgi-bin/epos/service.cgi?devid=local_printer&timeout=10000and
XMLHttpRequest 无法加载http://192.168.1.98/cgi-bin/epos/service.cgi?devid=local_printer&timeout=10000。对预检请求的响应未通过访问控制检查:请求的资源上不存在“Access-Control-Allow-Origin”标头。因此,不允许访问源“null”。响应的 HTTP 状态代码为 405。
但是当我将地址从
http://192.168.1.98/cgi-bin/epos/service.cgi?devid=local_printer&timeout=10000
更改为
http://192.168.1.98:9100/cgi-bin/epos/service.cgi?devid=local_printer&timeout=10000
时,它向我打印了以下内容:
OPTIONS:/ cgi-bin / epos / service.cgi?devid = local-printer & amp;timeout = 10000 HTTP / 1.1
主机:192.168.1.98:9100
连接:保持活动状态访问控制请求方法:POST
源:null
用户代理:Mizilla / 5.0 (Windows NT 6.3;WOW64) AppleWebKit
对于新的 TM-T88VI,我收到了同样的错误。然后,我在 ePOS SDK 用户手册中看到,为了控制 TM 打印机,您需要从打印机上的 EpsonNet Config 中启用 ePOS-Print 设置。
查看手册为了直接控制 TM-U220(不使用 TM 智能打印机),您需要安装 UB-E04 或 UB-R04 网络接口。它说您可以通过打印状态表来检查安装了哪些接口。
从外观上看,这是一个跨源 HTTP 请求问题(CORS)。此 MDN 文章解释了这一点:https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS
我猜测 IP 92.168.1.98 是打印机 IP(位于本地网络上)。请参阅:http://trendblog.net/ever-wondered-use-192-168-x-x-ip-addresses-home/,您可以按照上面的帖子中所述通过端口 9100 访问它。
因此,由于您的实际 Web 应用程序驻留在与打印机 IP 和 Web 工作方式不同的 IP 上,因此当您调用不同的 IP / 主机时需要 CORS,以防止跨站点脚本攻击。
这是常识,如果打印机通过端口 9100 暴露自己,你应该有你的 URI 的一部分。这就是为什么http://192.168.1.98:9100/cgi-bin/epos/service.cgi?devid=local_printer&timeout=10000工作,而另一个没有。
至于试图通过 Android 设备访问此...问题是该设备是否已加入您的本地网络(192.168....)还是在 Internet 上?如果它已连接到 Internet,则我认为您无法访问可能不会暴露于 Internet(具有公共 IP)的打印机。只要它们属于同一网络,它们就应该能够连接到公司的 WIFI。如果没有,您将需要将其暴露给其他 Android 打印机(
我在 TM-T20III 上遇到了同样的问题。您必须使用爱普生的实用程序软件作为打印机。在高级网络设置中,有一个名为“过滤器”的菜单,我将 POS 的 IP地址添加为接受地址。

但是当我将地址从http://192.168.1.98/cgi-bin/epos/service.cgi?devid=local_printer&timeout=10000更改为http://192.168.1.98:9100/cgi-bin/epos/service.cgi?devid=local_printer&timeout=10000时,它打印了我这个:
端口 9100 是打印机的原始输入端口,它似乎可以打印整个输入请求而无需解释。ePOS 服务似乎在端口 80 / 443 上可用。
对于新的 TM-T88VI,我收到了同样的错误。然后,我在 ePOS SDK 用户手册中看到,为了控制 TM 打印机,您需要从打印机上的 EpsonNet Config 中启用 ePOS-Print 设置。
启用 ePOS 打印服务对我来说是正确的解决方案。为了做到这一点,我不得不更新打印机的固件 (TM-T88VI)。在出厂默认值中,没有打开 ePOS 服务的选项。
本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处
评论列表(54条)