Page 1 of 1

Sending ESC/P escape codes to peripheral devices when the escape string contains Chr(0)

Posted: Mon Jul 15, 2024 12:36 pm
by PBJim
As PureBasic uses this as a string terminator, have any other developers found a good way to send a string in which it is embedded, to one of these devices? I know I can poke the 0 into a string location and somehow send the data, but how have others done this?

Printers such as in point-of-sale often require this and we can't always work through a driver. For instance, two of the below in our legacy system require Chr(0).

Code: Select all

03: Draft Mode                  : ESC "x" 0
04: NLQ Mode                    : ESC "x" 1
05: 10 CPI                      : 18 ESC "P" 0
06: 12 CPI                      : 18 ESC "M" 1
07: 15 CPI                      : 18 ESC "g"
08: Condensed Mode              : 15
09: Expanded Mode               : 14

Re: Sending ESC/P escape codes to peripheral devices when the escape string contains Chr(0)

Posted: Mon Jul 15, 2024 1:20 pm
by NicTheQuick
What about more details?
You didn't even mention over which way you want to send the data.

Re: Sending ESC/P escape codes to peripheral devices when the escape string contains Chr(0)

Posted: Mon Jul 15, 2024 4:21 pm
by infratec
Use a binary buffer and use SendData()

Re: Sending ESC/P escape codes to peripheral devices when the escape string contains Chr(0)

Posted: Mon Jul 15, 2024 5:00 pm
by PBJim
infratec wrote: Mon Jul 15, 2024 4:21 pm Use a binary buffer and use SendData()
Thanks very much Infratec, that's confirmed the approach I was thinking. I've started using WriteSerialPortData() for one of the printers, but wondered what others had done. Best, Jim.

Re: Sending ESC/P escape codes to peripheral devices when the escape string contains Chr(0)

Posted: Mon Jul 15, 2024 10:00 pm
by mk-soft
It feels like 100 years ago when I was still programming dot matrix printers on XT PC computers (DOS 16 bit and Pascal).

Should be something like that ...

Code: Select all

*buffer = Ascii(#ESC$ + "x0")
; -> to Printer
FreeMemory(*buffer)