Search code examples
node.jselectronthermal-printerepson

Print-Server written with Electron/Node.js


I'm trying to create a print-server written with electron and node js. My goal is to catch the body of a print-job from a POS to an Epson thermal printer. As I understood correctly from the documentations of Epson, the printer communicates on tcp port 9100 and on udp 3289 by default. So I created a websocket which is listening on the tcp port with the "Net" module. The socket is established successfully and I also recieve some Buffer data.

My Question for now is, how can I encode this buffer, as it isn't possible to encode this via the default encoding types from Node.js.

Or would you recommend to use a virtual printer which prints a file and afterwards to try reading the data from it? Which module or virtual printers are recommended? I've searched already for quite a while now without finding any positive results.

Here is my current code from the net server:

var server = net.createServer(function(socket) {
        socket.setEncoding('utf8')
        socket.on('data', function(buffer) {
                    var decoded = buffer
                    console.log(decoded)
                })
        socket.on('end', socket.end)
        });
server.on('connection', handleConnection);
server.listen(9100, function() {
        console.log('server listening to %j', server.address());
});
function handleConnection(conn) {  
        var remoteAddress = conn.remoteAddress + ':' + conn.remotePort;
        console.log('new client connection from %s', remoteAddress);
        conn.on('data', onConnData);
        conn.once('close', onConnClose);
        conn.on('error', onConnError);
}

Solution

  • Ok I've got this running. The Problem was, that the cashing system first made a request for the printerstatus "DLE EOT n". So I responded to the cashing system with the according status bits / byte (0x16). Afterwards the POS sended the printjob which I decoded from CP437 to UTF8 to capture and to be able to let my script read the incoming printrequest. Hope this post helps anyone who is developing anything similar like kitchen monitors, printservers etc. as I found very less informations in the web about this topic.