Receipt Printer Raw Data

I have a Epson TM-T20II printer I’m trying to print graphics and rawdata to. I can print the graphics fine but I want to send the rawdata command to cut the paper and can’t get it to work. I know my codes are right because I have it working in a VB.net app and I copied it from that (below). . Can some one help with sending the codes to the printer. Below is my VB.net code and my what I have so far for Xojo. This is on Windows.

'VB.NET code that works
Private prn As New RawPrinterHelper
Dim PrintString As String
''sends 3 line breaks and then autocuts
PrintString = Chr(10) & Chr(10) & Chr(10) & Chr(27) & Chr(109)
prn.OpenPrint(PrinterName)
prn.SendStringToPrinter(PrinterName, PrintString)
prn.ClosePrint()

'XOJO code----works for printing my graphics but need to autocut at end.
Dim ps As New PrinterSetup
Dim page As Graphics
page = OpenPrinter(ps)
If page <> Nil Then
Dim p As New Picture(Rectangle1.Width, Rectangle1.Height)
Rectangle1.DrawInto(p.Graphics, 0, 0)
Dim scale As Double = 0.75
page.DrawPicture(p, 10, 0, p.Width * scale, p.Height * scale, 0, 0, p.Width, p.Height)
end if

This may help:

Although I would have been looking for a way to send codes to the printer in the way that the VB code does.

Xojo printing assembles a picture, and then prints the picture.
You will only get a cut if the printer driver cuts when it gets a new page (or end of page)

I used to enjoy sending actual codes to a Printer via the LPT1: port
Thats basically what the VB code is doing - it doesnt send a page full of pixels, it sends a handful of bytes.

Perhaps using an API call…

Thanks Jeff. That is helpful but it looks like that thread already has the autocut feature set in the printer preferences. I guess I was looking for how to send a “cut” command to the printer.

Don’t know if this helps, but here’s an old project that sends escape sequences to a printer. Xojo’s built-in printing cannot send escape sequences. You have to use declares. And it’s all of one or all of the other. You can’t mix them.

2 Likes

Thanks Tim, not sure if that will work for me but it’s worth a look.

It’s only for windows, is there the same for macOS ?

is there the same for macOS ?

In windows and in Mac, you might ‘fall back’ on sending a text file holding the right bytes, to a nominated port.
I found this on another forum showing how to use a bash script to do it on a Mac…

data="\x1Bia\x00"
data="${data}\x1B@"
data="${data}\x1BX\x32"
data="${data}Hello"
data="${data}\x0C"

# Check your own binary for debugging:
echo -ne $data | hexdump -C

# print the actual label
echo -ne $data | lp -d Brother_PT_P900W
```

\x1B is ‘escape’ (hex 1B = 27)

So what the above is doing is assembling a variable called data and pushing that to
lp (local printer)
-d described as …

You might also be able to create a simple text file with a LOT of bytes in it, and use cat to do it.
eg
sudo cat my-file-to-print.txt > /dev/lp

We have WindowsAddPrintJobMBS class in MBS Xojo Win Plugin.

It allows to send raw PostScript to laser printer, but may also work for label printers.

I’d like to add, when in doubt, use MBS. Christian will do you right.

2 Likes

Thanks everyone. I do have a license for MBS plugins so I’ll take a look at WindowsAddPrintJobMBS too.

1 Like

I took Christians suggestion and tried printing the raw PostScript to the thermal receipt printer and it worked! The only issue is that it prints the raw postscript first instead of after my “DrawPicture”. So it cuts the paper and then prints the DrawPicture and then doesn’t cut Not sure how to make it wait until the page.DrawPicture is done.

'prints rectangle
page.DrawPicture(p, 10, 0, p.Width * scale, p.height * scale, 0, 0, p.Width, p.height)

'creates the cutting of the paper
const PrinterName = “EPSON TM-T20II Receipt”
dim w as new WindowsAddPrintJobMBS

if not w.OpenPrinter(PrinterName) then
MsgBox “OpenPrinter failed. Is the printer name correct in the source code?”
Return
end if

const DocName = “My Document”

if not w.StartDocPrinter(“My Document”, w.kDataFormatRAW) then
MsgBox “StartDocPrinter failed.”
Return
end if

call w.StartPagePrinter

Dim PostScript as string = Chr(27) + Chr(109)

dim BytesSent as Integer = w.WritePrinter(PostScript)

call w.EndPagePrinter
call w.EndDocPrinter

w = nil // close printer

Hello ,

Does anyone has any working solution for this ? I need it for Windows and MacOS , apparently they bought for me a Receipt Thermal network printer Rocket 300 and it has a manual with some raw commands , so in my case how I can send those commands to the printer ?

From what I saw it seems that it emulates the Epson printer but no idea what to do next.

If I setup the printer on Mac and print something it prints an empty page and some weird characters in the end of the paper , after which it cuts it.

If it uses Epson codes, try installing an Epson 9pin dot matrix driver like the FX80 or FX-890II
If that works, install a 24 pin driver, such as the LQ350 and see if you get better resolution.

Unfortunately none of those are working, so far it is a thermal not a needle printer.

Here is the manual for it the weird part , and I have no idea how you could send those raw commands to the printer , maybe via terminal ? I don’t find anywhere in the XOJO docs where you could send raw commands to the printer.

I dealt with a similar situation 15 years ago with a customer that had thermal Zebra 300 printers. The easiest solution we found was to draw onto a picture that was set up to be 300 dpi, convert the image to a 1-bit GIF file and send that to the printer directly through the serial port.

Thanks Greg, It’s hard for me to believe that in 15 years nothing changed. But apparently everything is hard with XOJO those days, sadly

The Rocket printer drivers seem to be only Windows.
Maybe install Crossover, install the drivers in there, and run something like Wordpad to print from that?

I’m not sure that’s entirely fair. Thermal printers are a special thing and are not really meant to support gradients and antialiasing.

In my case, FedEx and UPS would send shipping labels in gif format which is why I went that route for the things we needed to print.

I believe Zebra is using a totally different protocol so that will not work.

And while installing the driver on windows and just simply putting anything in excel or notepad prints right away, I did write a test in XOJO and surprise, it does not even start and nothing prints .

And as you see it is a simple code.

Dim ps As New PrinterSetup
Dim g As Graphics

If Not ps.ShowPageSetupDialog Then Return

g = ps.ShowPrinterDialog

If g = Nil Then Return

g.DrawText("test", 5, 5)

So I guess I will doit in Excel which gets it done in no time rather than discover the universe with XOJO. Honestly I struggle lately to have something functional in XOJO but I guess hard to do that .

Can anyone confirm that the printing part does even work on Windows ? it seems that nothing happens with any printer and with any test that I do from XOJO examples .

Thanks