receiptline / receiptline

Markdown for receipts. Printable digital receipts. Generate receipt printer commands and images.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Example that is printing?

Bilal-S opened this issue · comments

I am trying to make this work with a TM-T88v

While I am able to start the designer and create receipts there, I am still puzzled about how this library actually is able to send anything to a printer. In one terminal window I have this :

Virtual printer running at 127.0.0.1:19100
Server running at http://127.0.0.1:8080/

I also looked at example receiptes. Those render nicely in designer, but not sure how we would use them. Base templates?

Then I am copying the example code and running it in separate project and nothing seems to happen.

I modified the example code here with my printer IP as well as the Virtual Printer + port

const printer = {
        "host": "127.0.0.1",
        "port": 19100,   
    cpl: 42,
    encoding: 'cp437',
    upsideDown: false,
    gamma: 1.8,
    command: 'escpos'
};

When I run node testprint.js where testprint contains my code. Nothing happens.
Is this library supposed to send anything to the TM-T88v?

In short, is there a direct example that I can follow that show how I can send something to the printer via IP to print?

In contrast this library made this fairly easy:
https://www.npmjs.com/package/node-thermal-printer
I was able to run the example command and it printed an example directly to the printer
node examples/example.js tcp://x.x.x.x

Any insight is appreciated.

Thank you for using receiptline.

You can print with TM-T88V.
In order to print with the designer, please edit printer.json.
Then, type tm_series1 in the text box and send.

"tm_series1": {
    "host": "x.x.x.x",
    "port": 9100,
    ...
},

The following code is an example of printing.

const net = require('net');
const receiptline = require('receiptline');

const data= 'hello, world!';

const printer = {
    host: 'x.x.x.x',
    port: 9100,
    cpl: 42,
    encoding: 'cp437',
    upsideDown: false,
    gamma: 1.8,
    command: 'escpos'
};

const socket = net.connect(printer.port, printer.host, () => {
    socket.end(receiptline.transform(data, printer), 'binary');
});
socket.on('error', err => {
    console.log(err.message);
});

Thanks.
I can work with this.
What is the best way of using the printers.json file in the distribution?
Is this a list of example printers that can be supported with their settings?

Instructions for printer.json can be found in "ReceiptLine Designer" in README.md.

Most of the items are the same as the printer parameter of the receiptline.transform() method.

Thanks!

@receiptline thank you for clarifying.
I am trying to translate this for browser and also have looked into the example en.html file in this package.
I can render the receipt in browser but do not see a way to send to printer from browser.
The net module is not available in browser only in nodejs. Is there an alternate way to send it to printer via IP?
Is there a complete browser print example I have overlooked in the package?

How about the Web Serial API?
https://developer.mozilla.org/en-US/docs/Web/API/Web_Serial_API

TM Virtual Port Driver
https://download.epson-biz.com/modules/pos/index.php?page=single_soft&cid=6481

// receiptline
const command = receiptline.transform(text, printer);
// navigator.serial
const port = await navigator.serial.requestPort();
// open the port
await port.open(options);
// get the writer
const writer = port.writable.getWriter();
// convert command string to Uint8Array
const binary = ...
// write Uint8Array
await writer.write(binary);
// close the writer
await writer.close();
// close the port
await port.close();

Thanks.

Thanks.