Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use ESC/POS command 'GS v 0'

please can someone explain the 'GS v 0' command? I want to print some Bitmap on my thermal printer. I can't understand the parameters xL xH yL ...

The following is in the programming guide, but until now I can't see solution.

ASCII: Gs v 0 Decimal: 29 118 48 m xL xH yL yH [d]k Hexadecimal: 1D 76 30 m xL xH yL yH [d]k

0 ≤ m ≤ 3, 48 ≤ m ≤ 51 0 ≤ xL ≤ 255 0 ≤ xH ≤ 255 0 ≤ yL ≤ 255 0 ≤ d ≤ 255 k = ( xL + xH × 256) × ( yL + yH × 256) ( k ≠ 0)

xL, xH specifies (xL + xH × 256) bytes in horizontal direction for the bit image. yL, yH specifies (yL + yH × 256) dots in vertical direction for the bit image. [d]k specifies the bit image data (raster format).

like image 909
Mexxchen Avatar asked Jun 14 '16 10:06

Mexxchen


People also ask

How do you send ESC POS commands?

ESC/POS usage Most modern printers support ESC/POS. All commands start with the ESC character (ASCII 27, HEX 1B) or GS (ASCII 29, HEX 1D), followed by another character that specifies the command. Normal text is simply sent to the printer, separated by line breaks.

What is ESC command?

1. Short for Escape, Esc is a key found on the top-left corner of a computer keyboard. It allows the user to abort, cancel, or close an operation.

What is ESC POS and how do I use it?

ESC/POS is designed to reduce the processing load on the host computer in POS environments. It comprises a set of highly functional and efficient commands that enables the full realization of the potential of printers.


1 Answers

First let me say that I know the question is old and this command is considered obsolete, but there is still a huge market out there with thermal printers that accept this command.

Don't have enough points on this account to write a comment on @Fewl 's answer.

He is right about yL and yH, but not about xL and xH.

xL, xH specifies (xL + xH × 256) bytes in horizontal direction for the bit image.

yL, yH specifies (yL + yH × 256) dots in vertical direction for the bit image.

Ref: https://www.epson-biz.com/modules/ref_escpos/index.php?content_id=94

So let's say that your bitmap is 384 pixels wide and 260 pixels tall, then:

xL = width % 2048 / 8;
xH = width / 2048;
// width = 384
// xL = 48
// xH = 0
// (xL + xH × 256) = 48 + 0 x 256 = 48 **bytes** in horizontal direction.


yL = height % 256;
yH = height / 256;
//height = 260
// yL = 4
// yH = 1
// (yL + yH × 256) = 4 + 1 x 256 = 260 **dots** in vertical direction

Explanation, example bit image has 384 / 8 = 48 bytes in the horizontal direction, since 48 < 256 you don't need to calculate xH (High byte) it will be 0. You would only need to calculate xH if your bitmap is wider than 8 * 256 = 2048 dots... Which is highly unlikely to happen with thermal pos printers but I've included even that scenario in the code above.

Important note! My example width (384) is divisible by 8. If it isn't you will have to account for that by rounding up the division and pad the bit data with zeroes... or simply resize the bitmap beforehand to have its width divisible by 8.

like image 120
Uroš Avatar answered Sep 21 '22 13:09

Uroš