I am trying to print to an Epson TM-T88IV printer from javascript.
(This is a thermal receipt printer.)
Status:
- The printer is connected to the network via ethernet.
- I can successfully ping the printer.
- I can access the printer web configuration page.
- I have reset the printer.
- I can print to the printer using an Epson's Mac OS print driver.
Development Environment:
- I am running Mac OS X 10.10
- I reinstalled Node and NPM using Homebrew.
- Ran: brew update...brew doctor...brew symlink...
Issue:
I cannot figure out how to resolve the ECONNREFUSED error that I am encountering.
Already Tried:
- Ran it on Tonicdev.com to no avail for clues. Link to Tonic Notebook.
- I have searched and read every ECONNREFUSED question on Stackoverflow.
I have tried placing this code in a standalone print.js file and calling:
node print.js
Error:
{ 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 }
Update
I checked which ports were open/available on the device. It turns out that Epson's SDK documentation was incorrect! The actual port that is open for TCP/Printer requests is 515, not 8008. Good grief!
nc -z 192.168.77.22 1-6000
The printer.init isn't establishing a connection. The printer.isPrinterConnected is returning false.
I re-tried Epson's epos SDK with the correct port. I got the following error: ERROR_TIMEOUT
.
So, I think I might not be setting a TimeOut value correctly?
Node-Thermal-Printer (Code)
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 (Code)
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();
}
}