简体   繁体   English

用Electron / Node.js编写的打印服务器

[英]Print-Server written with Electron/Node.js

I'm trying to create a print-server written with electron and node js. 我正在尝试创建一个用电子和节点js编写的打印服务器。 My goal is to catch the body of a print-job from a POS to an Epson thermal printer. 我的目标是抓住从POS到Epson热敏打印机的打印作业的内容。 As I understood correctly from the documentations of Epson, the printer communicates on tcp port 9100 and on udp 3289 by default. 正如我从Epson文档中正确理解的那样,默认情况下,打印机在tcp端口9100和udp 3289上进行通信。 So I created a websocket which is listening on the tcp port with the "Net" module. 因此,我创建了一个Websocket,它正在使用“ Net”模块在tcp端口上进行监听。 The socket is established successfully and I also recieve some Buffer data. 套接字已成功建立,我也收到了一些Buffer数据。

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. 我现在的问题是,如何编码此缓冲区,因为无法通过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);
}

Ok I've got this running. 好的,我已经运行了。 The Problem was, that the cashing system first made a request for the printerstatus "DLE EOT n". 问题是,取款系统首先请求打印机状态为“ DLE EOT n”。 So I responded to the cashing system with the according status bits / byte (0x16). 因此,我用相应的状态位/字节(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. 之后,POS将我从CP437解码的打印作业发送到UTF8以进行捕获,并能够让我的脚本读取传入的打印请求。 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. 希望这篇文章对任何正在开发类似厨房监视器,打印服务器等类似东西的人有所帮助,因为我在网络上发现的有关该主题的信息很少。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM