I am maintaining a program that outputs ZPL to a label printer. Today, the character sequence ~Ja came in as part of a string to be printed, which is ZPL's "cancel all" command. Needless to say, the label did not print.
Is there an easy way in ZPL to escape a tilde?
You can use ~CT or ^CT to change the tilde control character to any other ASCII character, and then you can print tildes normally. However, the new control character won't be printable. This is probably going to be quite a hassle to maintain.
An example changing the control command prefix to +, taken from page 165 of the ZPL II programming guide:
^XA
^CT+
^XZ
+HS
If your string is represented as field data with ^FD, ^FV, or ^SN, you can use ^FH to encode the tilde in the string with its hex value, 7E.
An example, taken from page 192 of the ZPL II programming guide:
^XA
^FO100,100
^AD^FH
^FDTilde _7e used for HEX^FS
^XZ
Output:
Tilde ~ used for HEX
~ can be printed by replacing to \7E
It seeems like replacing these three characters will allow any key on the keyboard to print fine. I figured this out using ZebraDesigner, printing to a file and seeing what characters they escape.
\ to \1F - do this first or it will break the two below
~ to \7E
^ to \5E
Here is the code in C#
private static string escapeChars(string working)
{
working = working.Replace(#"\", #"\1F");
working = working.Replace(#"~", #"\7E");
working = working.Replace(#"^", #"\5E");
return working;
}
Related
In the past, we've used ZPL to create Code39 barcodes with a TAB character encoded in the middle using something similar to the following:
*USERNAME$IPASSWORD*
The $I in the middle gets translated to a TAB by the barcode scanners we use.
Now we have a need to do the same thing, but using Code128. With Code39, all the text needs to be uppercase (unless you're using Code39Extended, which supports lowercase letters). Because some of the data that is going to be encoded will be lowercase, we need to use Code128 B for most of the barcode, switching to Code128 A in the middle to encode the TAB character, then back to Code128 B for the final part.
Looking through the "ZPL II Programming Guide", it should be as easy as:
>:username>7{TAB}>6PA55w0rd
The >: at the beginning sets the subset to B, the >7 changes the subset to A, and the >6 changes the subset back to B. The problem I'm having (and haven't found a solution after almost a week of searching) is: How do I encode a TAB character using only text?
Use the ^FH (field hexidecimal encoding) command immediately prior to your field data. Based on your example:
^FH_^FD>:username>7_09>6PA55w0rd^FS
Where the underscore '_' is used as the escape character and 09 is the hex value for tab.
Also note that if the chosen escape character appears in the user name or password, you will need to escape it as well.
I tried what Mark Warren suggested, but unfortunately, it didn't work. It did, however, get me looking back through the ZPL II Programming Guide and I found the following, which I had overlooked before:
Code 128, Subsets A and C are programmed in pairs of digits, 00 to 99, in the field data string.
...
In Subset A, each pair of digits results in a single character being encoded in the bar code...
So, since 73 equates to a TAB in Subset A, I tried the following:
>:username>773>6PA55w0rd
And it worked!
I found this commit from facebook infer, and I have no idea what \027[0K and \027[%iA means.
What does these special string mean? And (I think) if there are more strings like this, where can I find the full documentation about this?
Those are escape sequences to tell your terminal what to do.
For example, the sequence of characters represented by \027[0K (where \027 is ASCII decimal value for Esc character) tells the terminal to "clear line from cursor to the end."
One helpful document/guide on this subject can be found at https://shiroyasha.svbtle.com/escape-sequences-a-quick-guide-1
The facebook code is copied from another source here, which uses hard-coded formatters imitating termcap (this page gives some background). The original has comments indicating where its information came from.
The formatter uses "%i" for integers. That's a repeat-count for the cursor movement "cursor-up" \033[A
In most languages, \033 (octal) is used for the ASCII escape character. But this source (according to the github analysis) is written in OCaml, and is using the decimal value for the ASCII escape character. According to the OCaml syntax, you could use an octal value like this: \o033
Once you see that the formatting parts (how the escape character is represented, the use of %i to format a number), the rest of this is documented in several places.
The relevant standard is ECMA-48
the termcap (or analogous terminfo) information is in the terminal database.
I've been trying to get ZPL working with a combination of ^FH and new lines. For some reason when I use the following code
^FH\^FD<RECEIVERNAME>\&<RECEIVERSTREET>\&<RECEIVERHOUSENUMBER>^FS
It ends up as
<RECEIVERNAME>&<RECEIVERSTREET>&<RECEIVERHOUSENUMBER>
I cannot seem to figure out how to stop ^FH from converting the new line to a symbol.
Hex for a new line is 0a, and hex for carriage return is 0d.
Neither of them work with http://labelary.com/ so I'm guessing that they are not supported for what you are using them for.
Line break characters (0x0d and/or 0x0a) like any other nonprintable characters are not supported in the commands ^FD, ^FV and ^SN, as stated in the ZPL Programming Guide. See the description of the ^FD command for reference.
I'm trying to find a solution to print superscript using ZPL.
Example, if I have this string of ZPL:
string ZPLString =
"^XA" +
"^FO50,50" +
"^A0N50,50" +
"^FDHello, World!^FS" +
"^XZ";
sendToZebraPrinter(ZPLString);
Since there aren't any superscript characters, I could send this to my printer without issue. But if I wanted to use this string:
string ZPLString =
"^XA" +
"^FO50,50" +
"^A0N50,50" +
"^FDe = mc²^FS" +
"^XZ";
sendToZebraPrinter(ZPLString);
The superscript won't print natively. I think I need to access an international character set or something but I'm not sure how to do this, especially if I only need it for the one character. Do I need to change my entire character set, or do some sort of "replace" on it?
Note, we are generating ZPL code manually and shooting it directly at the printers (unfortunately this is our system), bypassing any drivers or 3rd party dev components of any kind.
Mark's answer gave me exactly what I needed to solve my issue. Here is additional information to further clarify the solution:
To use the hex code in your data you need to prefix the ^FD command with ^FH_ (where ^FH tells the printer the data in ^FD will contain hex values and the _ defines the hex code identifier so it knows which data is or is not defined as a hex code instead of standard text)
I got this to work immediately exactly as you mentioned. Then testing against additional printers I found (but not sure why) that I didn't need to actually send in the ^CI13 to specify code page 850. The ² appeared on all printers even when I didn't send the ^CI13
In my .NET application, for some reason the ² didn't map to the correct hex code that the ZPL code page expected (the .NET app converted ² to hex code b2 instead of fd, but for most standard characters converted to the same code as the ZPL map) so in my application I created a conversion table where any character I defined in my table I mapped to the ZPL hex code and any character I didn't define I allowed to remain as converted by the application).
I'd never used information from the non default code page and I didn't realize when using ^FH that you could mix standard text with hex (I thought if you used ^FH that "all" of the information in ^FD had to be hex). So the information Mark provided let me right down the correct path.
The final example to solve the problem, using the information Mark provided, is:
string ZPLString =
"^XA" +
"^FO50,50" +
"^A0N50,50" +
"^FH_" +
"^FDe = mc_fd^FS" +
"^XZ";
sendToZebraPrinter(ZPLString);
Try using ^CI13 to select code page 850, then use _fd in your string for the superscripted 2. The underscore is used to designate a hex character.
I am maintaining a printing program that now requires printing both a ~ and an * in a code128 barcode in zpl.
Currently, I am using the code below that uses the ^FH to represent the tilde in hex:
^BCN,120,Y,N,N,N^FH^FDSPECIAL*MAKE_7e123456^FS
The barcode prints excluding the * and ~ as 'SPECIALMAKE123456'. Is it possible to print the tilde and asterisk in a zpl code128 barcode?
As a quick guess, since I don't have a ZPLII printer immediately available, I'd try
^BCN,120,Y,N,N,A^FH^FDSPECIAL*MAKE_7e123456^FS
(note A before the ^FH = Auto-select codeset)
Perhaps also forcing a codeset by ...^FH^FD>:SPECIAL*... may work, but subset B is the default in any case...
I located my old A300 printer, and was able to produce the required interpretation line using each of
^BCN,120,Y,N,N,A^FH^FDSPECIAL*MAKE_7E123456^FS
^BCN,120,Y,N,N,A^FH^FDSPECIAL_2AMAKE_7E123456^FS
Can't find my scanner to verify at present - but the computer room is a mite tidier...
It may depends on type of barcode.
For example, to print in 'barcode 128', you have to change code to code B, by signs >:
And: to print tilde ~, type >=. To print ^, type ><. To print >, type >0.
Look to zpl documentation, to table with Code 128 Invocation Characters.
My sample zpl code:
^XA
^BY2,3,95^FT0,206^BCN,,Y,N
^FD>:caret >< bigger >0 tilde >= end^FS
^PQ1,1,1,Y^XZ