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

Just starting out? Need help? Post your questions and find answers here.
PBJim
Enthusiast
Enthusiast
Posts: 296
Joined: Fri Jan 19, 2024 11:56 pm

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

Post 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
User avatar
NicTheQuick
Addict
Addict
Posts: 1527
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

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

Post by NicTheQuick »

What about more details?
You didn't even mention over which way you want to send the data.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
infratec
Always Here
Always Here
Posts: 7662
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

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

Post by infratec »

Use a binary buffer and use SendData()
PBJim
Enthusiast
Enthusiast
Posts: 296
Joined: Fri Jan 19, 2024 11:56 pm

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

Post 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.
User avatar
mk-soft
Always Here
Always Here
Posts: 6320
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

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

Post 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)
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply