Maybe these will help:
ASCII man page
ASCII wiki
ASCII Wiki: character groups (tables contain the same info as the ASCII man page)
For the protocol implemented by your printer, pay particular attention to the
ESC (escape) and GS (group separator) character.
See also the code tables starting on p. 463 of the printer manual.
For sending characters to the printer:
- The examples in the manual use conventions unique to the BASIC programming language;
- See below for interpretation of those conventions
- Specifically, you will likely never send the character strings "LPRINT" or "CHR$(" to the printer
- You will need to use different techniques i.e. those available to your brand and model of PLC
These three are all equivalent
- 1B2030AAAAHA - hexadecimal shorthand
- <1B>H<20>H<30>H<41>H<41>H<41>H<41>H<A>H - printer manual hexadecimal shorthand
- ESC SP 0 A A A A NL - ASCII shorthand
TL;DR
In the domain of your printer, the terms "character" and "byte" are somewhat interchangeable: they are two ways of referring to an 8-bit code.*
Character refers to the glyph for printables, or shorthand name for non-printables, the code represents e.g. "A" or "0" or "!" or "ESC" etc.
Byte refers to the numeric value of the code, which is in the hexadecimal range 00 to FF and in the decimal range 0 to 255.
The primary convention used in the printer manual
for codes is <h>H or <hh>H, where each h represents one hexadecimal digit.
The secondary convention used in the printer manual
for codes is &Hhh, where again each h represents on hexadecimal digit.
N.B. this secondary convention is only used in the context of BASIC program examples.
Common codes to note in the context of this printer are
- <1B>H = &H1B => ESC escape control character (27 decimal)
- <1D>H = &H1D => GS group separator control character (29 decimal)
- <A>H = &HA => NL new line control character (13 decimal)
The primary convention used in the printer manual for characters is the glyph (A or 0 or !) for 7-bit ASCII printable characters or the name (ESC or GS) for non-printable control characters
The secondary convention used in the printer manual for a sequence (i.e. string) of printable characters,
in the context of BASIC program examples, is one or more glyphs enclosed in quotes e.g. "AAAA" for four uppercase A characters.
The secondary convention used in the printer manual for non-printable control characters,
in the context of BASIC program examples, is CHR$(&Hhh) or CHR$(d), which is a function (CHR$) that converts the hexadecimal (&Hhh) or decimal (d) code to their single corresponding character.
Key concepts to understand
- A or "A" refers a character i.e. in this case the first letter of the western alphabet
- <A>H or &HA is a code (hexadecimal A = decimal 10) of a character
- CHR$(&HA) refers to the character with code A(hex) = 10(dec) i.e. NL newline.
- LPRINT is the BASIC command to send data to the printer; you will probably never send the string "LPRINT" to this printer.
On page 78 of that manual, which tells you how to set the inter-character spacing, the header is
This tells you that it takes three characters (bytes) sent in sequence to set the spacing:
- ESC is the escape control character
- SP is the space character
- n is a user-specified single character, the code for which will be the inter-character spacing
Further down, we see the same thing, but in hexadecimal form:
- <1B>h = 1B hex = 27 decimal = the code for ESCape
- <20>H = 20 hex = 32 decimal = the code for SPace
- <n> => n will be the code of the user-specified character sent, and that code will be the spacing use
And finally, in the example on p. 78, we see this line:
Code:
LPRINT CHR$(&H1B);" ";CHR$(0);
- LPRINT is the [send to printer] BASIC command
- CHR$(&H1B) is the ESCape character
- ; (semi-colon) ensures LPRINT does not send anything, e.g. spaces, between the characters on the line
- " " is a space; it could also be CHR$(&H20) or CHR$(32)
- ; another semi-colon
- CHR$(0) is the NUL character, so n is zero, and the inter-character spacing will be zero
- ; a final semi-colon ensures LPRINT does not append line termination to the characters sent to the printer
After that, we see this line:
- LPRINT is the [send to printer] BASIC command
- "AAAA" is a string of four uppercase A characters
- ; semi-colon to prevent LPRINT send spaces
- CHR$(&HA) is the NL newline character i.e. line termination
- ; a final semi-colon to prevent LPRINT from sending an automatic line terminator
After that we see line pairs, except that CHR$(1) and CHR$(12) are used to specify inter-character
spacings of 1 (decimal) and 12 (decimal).
Note that the following three statements would produce identical results
Code:
[LIST]
[*]LPRINT CHR$(&H1B);" ";CHR$(&H20);
[*] LPRINT CHR$(&H1B);" ";CHR$(32);
[*]LPRINT CHR$(&H1B);" ";
[/LIST]
because the third character is a SPace i.e. code 32 (decimal) = code 20 (hexadecimal).
* Technically ASCII codes are all 7-bits, but we conventionally send data 8 bits (one byte) at a time, so the ASCII codes are in the low 7-bits of the sent byte and the high bit is zero.