发送转义字符打印机 [英] Send escape character to printer
问题描述
我开发一个C#应用程序从SATO热转印打印机(CG408 TT)
打印标签有关此我使用SBPL(编程语言SATO)。它看起来像下面这样:
< ESC>将
< ESC> H0050< ESC> V0100< ESC> L0303< ESC> XMSATO
< ESC> H0050< ESC> V0200< ESC> B103100 *佐藤*
< ESC> H0070< ESC> V0310< ESC> L0101< ESC> XUSATO
< ESC> Q1< ESC> Z
要与打印机沟通,将原始数据发送给它我下面这技术。起初,我试图建立使用StringBuilder类的转义序列。
StringBuilder的SB =新的StringBuilder();
sb.AppendLine();
sb.AppendLine(< ESC> A);
sb.AppendLine(H0050&其中; ESC> V0100&其中; ESC> L0303&其中; ESC> XMSATO);
等等....
但我怎么能代替< ESC>
在字符串生成器参数的一部分。我知道这个角色27,但随后如何使用它与AppendLine命令
在此先感谢。
为const char ESC ='\ X1B;
现在你可以用ESC像任何其他变量。需要注意的是,你可以在一个字符串中嵌入ESC和:\ X1B
,但我想这会变得笨拙(特别是相邻号)
请做的没有的 ESC +somestring+ ESC
等,因为它违背了StringBuilder的目的
您可以
StringBuilder的SB =新的StringBuilder();
sb.AppendLine();
sb.AppendLine(< ESC> A);
sb.AppendLine(H0050&其中; ESC> V0100&其中; ESC> L0303&其中; ESC> XMSATO);
。字符串输出= sb.ToString()更换(< ESC>中,\ X1B)
例如。
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 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.
这篇关于发送转义字符打印机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!