POS for .Net print formatting - can't use esca

2020-05-01 09:42发布

I figured out how to print basic text to our POS printer, but I can't figure out how to get the escape characters to work (for bold, text alignment, etc). For now I'm just testing with the Microsoft PosPrinter Simulator.

Here's what I'm trying

_printer.PrintNormal(PrinterStation.Receipt, (char)27 + "|bC" + printText + (char)13 + (char)10);

I'd expect that to print my printText in bold followed by a line break. When I take out (char)27 + "|bC" then it works fine.

The documentation for the escape codes is here

The error I get is

A first chance exception of type 'System.FormatException' occurred in Microsoft.PointOfService.ControlBase.dll Input string was not in a correct format.

I tried a bunch of variations but can't seem to wrap my head around it.

Edit. Here's the stack trace..

   at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
   at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
   at System.Int32.Parse(String s, IFormatProvider provider)
   at Microsoft.PointOfService.DeviceSimulators.PosPrinterSimulatorWindow.ProcessEscapes(String str)
   at Microsoft.PointOfService.DeviceSimulators.PosPrinterSimulatorWindow.DisplayText(String str)
   at Microsoft.PointOfService.DeviceSimulators.PosPrinterSimulator.PrintNormalImpl(PrinterStation station, PrinterState printerState, String data)
   at Microsoft.PointOfService.BaseServiceObjects.PosPrinterBase.OutputRequestHandler(OutputRequest Request)
   at Microsoft.PointOfService.Internal.PosCommonInternal.ProcessOutputRequest(OutputRequest request, Boolean asyncOperation)
   at Microsoft.PointOfService.BaseServiceObjects.PosPrinterBase.ProcessRequest(PrintOperation operation)
   at Microsoft.PointOfService.BaseServiceObjects.PosPrinterBase.PrintNormal(PrinterStation station, String data)
   at MyProjectNamespace) in MyFile.cs:line 74

7条回答
做个烂人
2楼-- · 2020-05-01 10:08

For me it worked to escape the string like this:

_printer.PrintNormal(PrinterStation.Receipt, "\x1B|bCYour Bold line\r\n");

Maybe you can still use it in the future.

查看更多
登录 后发表回答