Epson js SDK无法使用多台打印机
介绍 我们正在开发这个基于javascript的web应用程序,该应用程序应该使用 现在我们有了这个poc,可以在应用程序中添加多台打印机,每个打印机都可以打印收据 问题是,收据将仅由上次添加的打印机打印 进一步的调查告诉我们sdk只使用最后添加的连接打印机。这可以在以下图片中看到 在第一个图像中,有两个打印机设置。注意不同的ip地址。 在第二个图像中,我们记录打印时使用的EpsonPrinter实例。请注意,ip地址显然是第一台打印机。 在第三幅图中,我们跟踪了网络。请注意实际使用的ip地址忽略错误。 我们创建了自己的EpsonPrinter类,可以在下面找到 爱普生打印机 Poc 可以找到完整的工作poc 爱普生javascript sdk 2.9.0Epson js SDK无法使用多台打印机,epson,Epson,介绍 我们正在开发这个基于javascript的web应用程序,该应用程序应该使用 现在我们有了这个poc,可以在应用程序中添加多台打印机,每个打印机都可以打印收据 问题是,收据将仅由上次添加的打印机打印 进一步的调查告诉我们sdk只使用最后添加的连接打印机。这可以在以下图片中看到 在第一个图像中,有两个打印机设置。注意不同的ip地址。 在第二个图像中,我们记录打印时使用的EpsonPrinter实例。请注意,ip地址显然是第一台打印机。 在第三幅图中,我们跟踪了网络。请注意实际使用的ip地址忽
有没有人有使用爱普生sdk的经验?它应该能够同时支持多个连接吗?请告知用户。爱普生说,2.12.0版可以添加多台打印机。爱普生说,2.12.0版可以添加多台打印机。对于那些正在寻找使用此SDK处理多台打印机的方法的用户。我们提出了以下解决方案: 我们创建了一个独立的“打印机应用程序”,负责处理一个打印机连接,并将其在线托管。然后,我们使用iFrame将此打印机应用程序“加载”到需要多个连接的应用程序中。应用程序和打印机应用程序之间的通信通过window.PostMessage API完成,例如,使用正确的打印机连接初始化打印机,并提供必须打印的数据 这需要一些努力,但却是我们能够想出的处理多个连接的最稳定的解决方案 如果有人提出更好的方法,请告诉我
您可以查看我们的打印机应用程序,以获取灵感。检查应用程序,因为它不会显示太多内容。如果您想使用此SDK处理多台打印机,请访问它。。我们提出了以下解决方案: 我们创建了一个独立的“打印机应用程序”,负责处理一个打印机连接,并将其在线托管。然后,我们使用iFrame将此打印机应用程序“加载”到需要多个连接的应用程序中。应用程序和打印机应用程序之间的通信通过window.PostMessage API完成,例如,使用正确的打印机连接初始化打印机,并提供必须打印的数据 这需要一些努力,但却是我们能够想出的处理多个连接的最稳定的解决方案 如果有人提出更好的方法,请告诉我
您可以检查我们的打印机应用程序以获取灵感,检查应用程序,因为它不会显示太多访问内容。要使用您的类EpsonPrinter,我在您的类之后添加myPrinters类:
class myPrinters {
printers = null;
cantidad = 0;
constructor() {
console.log("Creo la coleccion de printers");
this.printers = [];
}
inicializarConeccionImpresora(idImpresora, ip, puerto, _deviceId) {
let ipAddress = ip;
let port = puerto;
let deviceId = _deviceId;
console.log("Agrego una impresora");
let myPrinter = new EpsonPrinter(ipAddress);
myPrinter.port = port;
myPrinter.deviceId = deviceId;
myPrinter.id = idImpresora;
console.log('Id impresora antes de connect es: ' + idImpresora);
myPrinter.connect();
this.printers[this.cantidad] = myPrinter;
this.cantidad ++;
}
imprimirPruebaJS(idImpresora) {
let printer = null;
let printerTemp = null
for(var i = 0; i < this.printers.length; i++) {
printerTemp = this.printers[i];
if (printerTemp.id == idImpresora) {
printer = printerTemp.printer;
}
}
if (printer == null) {
console.log("La impresora no esta iniciada en clase myPrinters");
return;
}
printer.addText('Hola mundo texto normal\n');
printer.addFeed();
printer.addCut(printer.CUT_FEED);
}
}
测试一下,告诉我。
Juan为了使用您的类EpsonPrinter,我在您的类之后还添加了myPrinters类:
class myPrinters {
printers = null;
cantidad = 0;
constructor() {
console.log("Creo la coleccion de printers");
this.printers = [];
}
inicializarConeccionImpresora(idImpresora, ip, puerto, _deviceId) {
let ipAddress = ip;
let port = puerto;
let deviceId = _deviceId;
console.log("Agrego una impresora");
let myPrinter = new EpsonPrinter(ipAddress);
myPrinter.port = port;
myPrinter.deviceId = deviceId;
myPrinter.id = idImpresora;
console.log('Id impresora antes de connect es: ' + idImpresora);
myPrinter.connect();
this.printers[this.cantidad] = myPrinter;
this.cantidad ++;
}
imprimirPruebaJS(idImpresora) {
let printer = null;
let printerTemp = null
for(var i = 0; i < this.printers.length; i++) {
printerTemp = this.printers[i];
if (printerTemp.id == idImpresora) {
printer = printerTemp.printer;
}
}
if (printer == null) {
console.log("La impresora no esta iniciada en clase myPrinters");
return;
}
printer.addText('Hola mundo texto normal\n');
printer.addFeed();
printer.addCut(printer.CUT_FEED);
}
}
测试一下,告诉我。
Juan只需创建多个对象即可打印,简单如下
this.eposdev = [];
let printersCnt = 3;
let self = this;
for(let i=1 ; i <= printersCnt ; i++){
this.eposdev[i] = new window.epson.ePOSDevice()
this.eposdev[i].onreconnecting = function (){
this.consoleLog('reConnecting')
}
this.eposdev[i].onreconnect = function (){
this.consoleLog('onReconnect')
}
this.eposdev[i].ondisconnect = function (){
this.consoleLog('onDisconnect')
}
}
function connect(printerKey) => {
this.consoleLog('connect')
this.eposdev.ondisconnect = null
this.eposdev.disconnect()
this.eposdev.connect(self.ipAddress[printerKey], self.port[printerKey], function(){
clearInterval(self.intervalID)
self.intervalID = null
self.eposdev[i].ondisconnect = self.ondisconnect
if (data === 'OK' || data === 'SSL_CONNECT_OK') {
console.log('create device, try: ' + self.restry)
const options = {
crypto: self.crypto,
buffer: self.buffer
}
self.eposdev[printerKey].createDevice(self.deviceId, self.eposdev[printerKey].DEVICE_TYPE_PRINTER, options, function(deviceObj, code){
this.restry++
if (code === 'OK') {
self.printer[printerKey] = deviceObj
self.printer.onreceive = function(){
console.log("onreceive");
}
} else if (code === 'DEVICE_IN_USE') {
if (self.restry < 5) {
setTimeout(() => self.createDevice(printerKey), 3000)
}
})
}
} else {
setTimeout(() => self.reconnect(printerKey), 5000)
}
})
}
只需创建多个对象即可打印,简单如下
this.eposdev = [];
let printersCnt = 3;
let self = this;
for(let i=1 ; i <= printersCnt ; i++){
this.eposdev[i] = new window.epson.ePOSDevice()
this.eposdev[i].onreconnecting = function (){
this.consoleLog('reConnecting')
}
this.eposdev[i].onreconnect = function (){
this.consoleLog('onReconnect')
}
this.eposdev[i].ondisconnect = function (){
this.consoleLog('onDisconnect')
}
}
function connect(printerKey) => {
this.consoleLog('connect')
this.eposdev.ondisconnect = null
this.eposdev.disconnect()
this.eposdev.connect(self.ipAddress[printerKey], self.port[printerKey], function(){
clearInterval(self.intervalID)
self.intervalID = null
self.eposdev[i].ondisconnect = self.ondisconnect
if (data === 'OK' || data === 'SSL_CONNECT_OK') {
console.log('create device, try: ' + self.restry)
const options = {
crypto: self.crypto,
buffer: self.buffer
}
self.eposdev[printerKey].createDevice(self.deviceId, self.eposdev[printerKey].DEVICE_TYPE_PRINTER, options, function(deviceObj, code){
this.restry++
if (code === 'OK') {
self.printer[printerKey] = deviceObj
self.printer.onreceive = function(){
console.log("onreceive");
}
} else if (code === 'DEVICE_IN_USE') {
if (self.restry < 5) {
setTimeout(() => self.createDevice(printerKey), 3000)
}
})
}
} else {
setTimeout(() => self.reconnect(printerKey), 5000)
}
})
}
爱普生在哪里这么说?如果2.12.0中添加了多台打印机,您能否提供一个链接或其他内容,并解释成功添加多台打印机的过程(如果不同的话)?如果你在这里下载sdk,你可以在版本历史中的文件readme.en.txt中看到:版本2.12.0-添加了Web浏览器版本支持-Microsoft Edge 39-44-Mozilla Firefox 50-66-Google Chrome 54-74-Safari 11-12-Safari iniOS 11-12-增加了TM打印机支持-TM-T20III-TM-T82III-条形码扫描仪现在可以连接到TM-T88VI。-Connect API可以用于一个应用程序中的多个设备。我正在寻找解决方案,如果我找到了,我会在这里编写。你好,胡安尼,让它工作起来。转到webconfig,默认用户为epson,传递epson。转到配置中的ePos设备版本2.70并启用它。告诉我这是否有效。转到配置-网络->ePos设备,我的源代码与您的非常相似。告诉我它是否有效。爱普生在哪里说的?如果2.12.0中添加了多台打印机,您能否提供一个链接或其他内容,并解释成功添加多台打印机的过程(如果不同的话)?如果你在这里下载sdk,你可以在版本历史记录中的文件readme.en.txt中看到:版本2.12.0-添加Web浏览器版本支持-Microsoft Edge 39-44-Mozilla Firefox 50-66-Google Chrome 54-74-Safari 11-12
-iOS 11-12中的Safari-增加了TM打印机支持-TM-T20III-TM-T82III-条形码扫描仪现在可以连接到TM-T88VI。-Connect API可以用于一个应用程序中的多个设备。我正在寻找解决方案,如果我找到了,我会在这里编写。你好,胡安尼,让它工作起来。转到webconfig,默认用户为epson,传递epson。转到配置中的ePos设备版本2.70并启用它。告诉我这是否有效。转到配置-网络->ePos设备,我的源代码与您的非常相似。告诉它是否有效。别忘了这一点:转到webconfig,默认用户是epson的ipaddress,传递epson。进入配置-网络->配置中的ePos设备,版本2.70并启用它。告诉我这是否有效。别忘了这一点:转到webconfig,默认用户为epson的ipaddress,传递epson。进入配置-网络->配置中的ePos设备,版本2.70并启用它。告诉我这是否有效。