开发者

Send escape character to printer

开发者 https://www.devze.com 2023-02-21 17:07 出处:网络
I am developing an C# application to print labels from a thermal transfer printer from SATO (CG408 TT)

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 开发者_StackOverflow中文版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 Command

Thanks in advance.


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.


This should work

sb.AppendLine(((char)27).ToString());


For OPOS Drivers, I ended up using

string ESC = System.Text.ASCIIEncoding.ASCII.GetString(new byte[] { 27 }); 
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号