尝试使用C#和RawPrinterHelper类打印到我的EPSON TM-T88IIIP打印机,到目前为止我只能打印文本,现在我需要的是打印图形,但EPSON文档并不清楚。
这是我打印文字的代码:
static string printerName = "Epson TM-T88III";
static string ESC = Convert.ToString((char)27);
static string LF = Convert.ToString((char)10);
static string GS = Convert.ToString((char)29);
static string cutCommand = $"{ESC}@{GS}V{(char)66}{(char)0}";
static void Main(string[] args)
{
PrintText();
//PrintGraphics();
}
private static void PrintText()
{
byte[] bytes = Encoding.Unicode.GetBytes($@"{ESC}COMPANYNAME.{LF}COMPANY ADDRESS{LF}RANDOM TEXT{LF}__________________________________________{LF}{(char)179}1234567890123456789012345678901234567890{(char)179}{LF}{(char)196}{LF}");
RawPrinterHelper.SendBytesToPrinter(printerName, bytes);
RawPrinterHelper.SendBytesToPrinter(printerName, Encoding.ASCII.GetBytes(cutCommand));
}
它工作得非常好,现在图形命令就像这样:
命令定义='// GS(L pL pH m fn a kc1 / Kc2 b xL xH yL yH c
命令执行= GS“(L”139 7 48 67 48“G1”1 128 0 120 0 49
这是问题,如何在ASCII中转义所有这些参数,我的代码到目前为止:。
public static void PrintGraphics()
{
byte[] commandBytes = Encoding.ASCII.GetBytes($"{ESC}@{GS}{(char)40}{(char)76}{(char)139}{(char)7}{(char)48}{(char)67}{(char)48}G1{(char)1}{(char)128}{(char)0}{(char)120}{(char)0}{(char)49}");
//byte[] commandBytes = Encoding.Unicode.GetBytes($"{ESC} (L 139 7 48 67 48 G1 1 128 0 120 0 49");
byte[] imageBytes = Example.GetExampleImageBytes();
byte[] commandEndBytes = Encoding.ASCII.GetBytes($"{ESC}@{GS}{(char)40}{(char)76}{(char)6}{(char)0}{(char)48}{(char)69}G1{(char)1}{(char)1}");
byte[] endBytes = commandBytes.Concat(imageBytes).Concat(commandEndBytes).ToArray();
RawPrinterHelper.SendBytesToPrinter(printerName, endBytes);
RawPrinterHelper.SendBytesToPrinter(printerName, Encoding.ASCII.GetBytes(cutCommand));
}