Send evacuation symbol to printer

I am developing a C # application for printing tags from a printer to transfer heat from SATO (CG408 TT)

For this I use SBPL (programming language for SATO). Which looks like this:

<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 contact the printer and send the raw data, I follow this technique. First I try to build escape sequences using the StringBuilder Class.

 StringBuilder sb = new StringBuilder(); sb.AppendLine(); sb.AppendLine("<ESC>A"); sb.AppendLine("H0050<ESC>V0100<ESC>L0303<ESC>XMSATO"); 

etc....

But how can I replace the <ESC> part in the string builder argument. I know this character 27, but then how to use it with the AppendLine team

Thanks in advance.

+2
source share
2 answers
 const char ESC = '\x1B'; 

Now you can use ESC, like any other variable. Note that you can also embed esc in the string: "\x1B" , but I suppose this will become cumbersome (especially with adjacent numbers).

Please do not ESC + "somestring" + ESC , etc., because it defeats the purpose of 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") 

eg.

+7
source

This should work

 sb.AppendLine(((char)27).ToString()); 
+1
source

Source: https://habr.com/ru/post/1386399/


All Articles