我正在尝试从javascript打印到Epson TM-T88IV打印机 .
(这是热敏收据打印机 . )
状态:
-
打印机通过以太网连接到网络 .
-
我可以成功ping通打印机 .
-
我可以访问打印机Web配置页面 .
-
我重置了打印机 .
-
我可以使用Epson的Mac OS打印驱动程序打印到打印机 .
开发环境:
-
我正在运行Mac OS X 10.10
-
我使用Homebrew重新安装了Node和NPM .
-
Ran:brew更新... brew doctor ... brew符号链接...
问题:
我无法弄清楚如何解决我遇到的ECONNREFUSED错误 .
已经尝试过:
-
在Tonicdev.com上跑吧无法获得线索 . Link来到Tonic Notebook .
-
我在Stackoverflow上搜索并阅读了每个 ECONNREFUSED 问题 .
-
我尝试将此代码放在一个独立的 print.js 文件中并调用:
node print.js
错误:
{ Error: connect ECONNREFUSED 192.168.77.22:8008
at Object.exports._errnoException (util.js:1012:11)
at exports._exceptionWithHostPort (util.js:1035:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1080:14)
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect',
address: '192.168.77.22',
port: 8008 }
更新
我检查了设备上打开/可用的端口 . 事实证明,Epson的SDK文档不正确!为TCP /打印机请求打开的实际端口是515,而不是8008.好悲伤!
nc -z 192.168.77.22 1-6000
printer.init 未 Build 连接 . printer.isPrinterConnected 正在返回 false .
我用 correct port 重新尝试了爱普生的epos SDK . 我收到以下错误: ERROR_TIMEOUT
.
So, I think I might not be setting a TimeOut value correctly?
节点热敏打印机(代码)
var printer = require("node-thermal-printer");
printer.init({
type: 'epson',
interface: '/dev/usb/lp0',
ip: "192.168.77.22",
port: '515'
});
printer.isPrinterConnected(function(isConnected){
console.log(isConnected);
});
process.on('uncaughtException', function (err) {
console.log(err);
});
printer.alignCenter();
printer.println("Hello world");
printer.cut();
printer.execute(function(err){
if (err) {
console.error("Print failed", err);
} else {
console.log("Print done");
}
});
Epson SDK(代码)
var ePosDev = new epson.ePOSDevice();
function connect() {
var ipAddress = '192.168.77.22';
var port = '515';
ePosDev.connect(ipAddress, port, callback_connect);
}
function callback_connect(resultConnect){
alert('Callback Called');
var deviceId = 'local_printer';
var options = {'crypto' : false, 'buffer' : false};
alert(resultConnect);
if ((resultConnect == 'OK') || (resultConnect == 'SSL_CONNECT_OK')) {
alert('Connected!');
ePosDev.createDevice(deviceID,ePosDev.DEVICE_TYPE_PRINTER,options,callback_createDevice);
}
else {
alert('Not Connected!');
}
}
var printer = null;
function callback_createDevice(deviceObj, errorCode){
if (deviceObj === null) {
//Displays an error message if the system fails to retrieve the Printer object
return; }
printer = deviceObj;
//Registers the print complete event
printer.onreceive = function(response){
if (response.success) {
//Displays the successful print message
}
else {
//Displays error messages
} };
}
function createData(){
printer.addTextAlign(printer.ALIGN_CENTER);
printer.addText("Hello World\n");
}
function send(){
if (ePosDev.isConnected) {
printer.send();
}
}
2 回答
当我扩大搜索范围时,我发现打印机正在侦听另一个端口上的命令!
...重新调整了以下结果:
所以,我只是在代码的 init 部分将端口号更改为9100,瞧!
我不知道为什么我的Epson TM-M30 POS打印机的端口已经从官方'8008'变为'515' .
问题是epos-2.7.0.js已将连接端口声明为常量:
但真正的是515,所以你必须修改官方的js:
通过此更改,这是我的代码: