Android Question chr 27 and 16 what are mean

Status
Not open for further replies.

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

emexes

Expert
Licensed User
The end result of these characters, what is means?
It is a command to the printer to do something. There are several common printer control sets ("languages"), generally one from each of the major printer manufacturers. This command is from the Epson Standard Code for Printers (ESC/P). Two other major printer control languages are HP's Printer Command Language (PCL) and Adobe's Postscript (PS).

In ESC/P, most commands start with an Escape character (ASCII code 27) which is a control code that lets the printer know that what comes next should be interpreted as a command, rather than be printed. The next character indicates the command: your example is the letter "t" which is the "select character code page" command, per this randomly chosen reference from the internet:

upload_2019-7-12_9-19-32.png


I realised afterwards that this example also demonstrates that the internet makes mistakes: first I spotted that the Parameter range is supposedly 0 <= n <= 15 when clearly there are examples all the way up to 255, and second I spotted that the ASCII rendition of the command is ".t" (incorrect) rather than just "t" (correct). Usually it pays off to double-check information by finding multiple different sources that confirm each other. Added benefit is that the sources will be written in different styles, and one of those styles will align best with you. Often, extra time taken during searching is reclaimed during reading ;-)

So, in summary: your code:
B4X:
Chr(27) & "t" & Chr(16)
is a command to a printer, comprised of three characters:

1/ Escape = ASCII 27 = "this is a command"
2/ "t" = ASCII 116 = Epson printer command to select which set of characters to use for printing
3/ character# 16 = one-byte parameter to specify the character set; here it is WPC1252 "probably the most-used 8-bit character encoding in the world"

Ideally, the code fragment you supplied would have been part of something like:
B4X:
Dim PrinterCommand As String = Chr(27) & "t" & Chr(16)    'select character set Windows 1252
PrintString(SalesPrinter, PrinterCommand)
but sadly, writing readable code is a bit of a dying art, and more probably you had something like:
B4X:
posdevxmit(shared.default.outlocal[1], Chr(27) & "t" & Chr(16))
Sigh.
 
Last edited:
Upvote 0

klaus

Expert
Licensed User
Longtime User
What exactly are you looking for?
There exist different encoding pages, for a general explanation search on Google: CodePage.
B4X uses UTF-8 by default
You may have a look at the Text encoding chapter in the B4X Basic language booklet.
But, this thread is about specific character sequences for a given printer.
For this, only the documentation for the given printer gives a concrete answer.
 
Upvote 0
Status
Not open for further replies.
Top