简体   繁体   中英

Print to pos thermal printer using tcp web-application

I have a task to create a web application on javascript/typescript that could print to the pos printer directly using TCP or some other protocol. Everything has to happen on the customer's device not using the server. The customer should be able to print in his local network

Testing on EPSON TM-T20III I tried using WebSocket for that but it sends its header to the printer

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");};
}

I get this from the printer:

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

tried using 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();

But then I need to start a Node server on the client's device which is too complicated for the client.

I'm looking for other options, but can't find anything. A lot of things are blocked for security reasons. Can anybody help?

You Should use the javascrpt SDK https://download.epson-biz.com/modules/pos/index.php?page=soft&scat=57 .

I'm currently struggling with some CORS stuff. I'm not getting the access-control-allow-origin-header when connecting to TM-T20IIIL (with TM-T20II I have it working)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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