Send escape character to printer
Solution 1
const char ESC = '\x1B';
now you can use ESC like any other variable. Note that you can embed esc in a string as well: "\x1B"
but I suppose that would become unwieldy (especially with adjacent numbers).
Please do not ESC + "somestring" + ESC
etc. because it defeats the purpose of the StringBuilder
You could
StringBuilder sb = new StringBuilder();
sb.AppendLine();
sb.AppendLine("<ESC>A");
sb.AppendLine("H0050<ESC>V0100<ESC>L0303<ESC>XMSATO");
String output = sb.ToString().Replace("<ESC>", "\x1B")
e.g.
Solution 2
This should work
sb.AppendLine(((char)27).ToString());
Solution 3
For OPOS Drivers, I ended up using
string ESC = System.Text.ASCIIEncoding.ASCII.GetString(new byte[] { 27 });
Marshal
Desktop app developer (C# .NET), interested in Entity Framework 6, LINQ-to-SQL WPF and Winforms WCF Services Clean Code and Test Driven Development SQL Server database Productivity Tools: Ninject, Resharper, Caliburn. Micro Test Tools: NUnit, MSTest, and White UI Automation. RFID, Barcode, Healthcare and Medical Imaging Solutions
Updated on June 07, 2022Comments
-
Marshal almost 2 years
I am developing an C# application to print labels from a thermal transfer printer from SATO (CG408 TT)
For this I am using SBPL (Programming language for SATO). Which looks something like following:
<ESC>A <ESC>H0050<ESC>V0100<ESC>L0303<ESC>XMSATO <ESC>H0050<ESC>V0200<ESC>B103100*SATO* <ESC>H0070<ESC>V0310<ESC>L0101<ESC>XUSATO <ESC>Q1<ESC>Z
To communicate with Printer and send raw data to it I am following this technique. At first i am trying to build the escape sequences using StringBuilder Class.
StringBuilder sb = new StringBuilder(); sb.AppendLine(); sb.AppendLine("<ESC>A"); sb.AppendLine("H0050<ESC>V0100<ESC>L0303<ESC>XMSATO");
and so on....
But how can I replace
<ESC>
part in string builder argument. I know that character 27, but then how to use it with AppendLine CommandThanks in advance.