繁体   English   中英

使用 tcp 网络应用程序打印到 pos 热敏打印机

[英]Print to pos thermal printer using tcp web-application

我的任务是在 javascript/typescript 上创建一个 web 应用程序,该应用程序可以使用 TCP 或其他一些协议直接打印到 pos 打印机。 一切都必须在不使用服务器的客户设备上进行。 客户应该能够在他的本地网络中打印

在 EPSON TM-T20III 上进行测试我尝试使用 WebSocket 进行测试,但它会将 header 发送到打印机

let ws = new WebSocket("ws://192.168.1.171:9100/");
    console.log(ws);ws.onopen = function (e) {
        console.log(e);
        ws.send('test test test');};

    ws.onclose = function(e) {
        console.log("Done");};
    ws.onerror = function(e) {
        console.log("Error");};
}

我从打印机得到这个:

GET / HTTP/1.1
Host: 192.168.1.171:9100
Connection: Upgrade
Pragma: no-cache
Cache-Control: no-cache
User-Agent: Mozilla/5.0 (Macintosh: Intel Mac OS
X 10 15 7) ApplewebKit/537.35 (KHTML, like Geck
o) Chrome/104.0.0.0 Safari/537.36
Upgrade: websocket
Origin: http://localhost:4300
Sec-WebSocket-Version: 13
Accept-Encoding: gzip, deflate
Accept-Language:en-US,en;q=0.9,lt;q=0.8,ru;q=0.
7
Sec-WebSocket-Key:YTtnLHd6T+4YEEzlyro16Q==
Sec-WebSocket-Extensions: permessage-deflate; cl
ent max _window _bits
GET / HTTP/1.
Host: 192.168.1.171:9100
Connection: Upgrade
Pragma: no-cache
Cache-Control: no-cache
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS
X 10 15 7) AppleWebKit/537.36 (KHTML, like Geck
0) Chrome/104.0.0.0 Safari/537.36
Upgrade: websocket
Origin: http://localhost: 4300
Sec-WebSocket-Version:13
Accept-Encoding: gzip, deflate
Accept-Language:en-US,en;q=0.9,1t;0=0.8,ru;q=0.
Sec-WebSocket-Key:4840Pq0V1LHpgLeZZadhEw==
Sec-WebSocket-Extensions: permessage-deflate; cl
ent max _window_bits

尝试使用 socket.net

const Net = require("net");

let name = this.host + ":" + this.port;
    let printer = Net.connect(
        {
            // host: this.host,
            host: '192.168.1.171',
            port: this.port || 9100,
            timeout: this.timeout || 3000
        },

    );
    
function execute (resolve) {
    printer.write('buffer', null, function () {
        resolve("Data sent to printer: " + name);
        printer.destroy();
    });
}
execute();

但是我需要在客户端的设备上启动一个节点服务器,这对客户端来说太复杂了。

我正在寻找其他选择,但找不到任何东西。 出于安全原因,很多东西都被阻止了。 有人可以帮忙吗?

您应该使用 javascrpt SDK https://download.epson-biz.com/modules/pos/index.php?page=soft&s .

我目前正在努力解决一些 CORS 的问题。 连接到 TM-T20IIIL 时我没有得到 access-control-allow-origin-header(使用 TM-T20II 我可以正常工作)

暂无
暂无

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

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