How do I send ASCII text to printer (over USB)?

I managed to install a raw printer driver and print to it from the command line.

Using CUPS/Gutenprint's web interface at http://localhost:631/ I added a printer with device URI

usbtb://Generic%00%00%06/Generic%20Bulk%20Device?serial=1234567890

and selected "Raw" as the make for the printer. (Please note that the serial URI parameter corresponds to the serial number for the USB device as listed in the question!)

I can now see the printer listed when issuing the command lpstat -p -d

printer Generic_usbtb is idle. enabled since Tue Jul 16 23:04:11 2013

To print the text file text.txt I write lp -d Generic_usbtb test.txt


Theory

We are talking about a line printer. This type of printer accepts raw text and prints it. They typically support 255 characters and must be configured to on of a few supported character sets, such as ASCII or CP437.

These printers accept "raw" input - meaning characters, spaces, line breaks, etc. They sometimes support images also.

Basically you'll need to

  1. Add a raw printer through CUPS (common unix printing interface)
  2. Send raw text, PDF, or PS to the printer

Steps

1) Turn on CUPS web administration

  1. Open a Terminal
  2. Enter the command $ sudo cupsctl WebInterface=yes

That will enable a feature that lets you add and remove printers from the CUPS localhost web administration site.

2) Find printer address

If it's a local printer:

  1. Run the command $ lpinfo -v | grep usb

You'll get a response that looks like:

direct usb:///80Series%20Receipt%20Printer%20200DPI?location=14200000

The usb:///<printer name>?location=<locationID> is your printer address on the USB hub. Copy that text.

If it's a network printer You'll want the IP address and port of that printer. The full address will be:

socket://<ip address>:<port>

For example:

socket://192.168.1.12:9100

3) Add printer

  1. Go to your CUPS Administration Page (http://localhost:631)

  2. Click Administration

  3. Click Add printer

  4. Click AppSocket/HP JetDirect (Don't click your existing printer if it shows up), click Continue

  5. Paste your printer address from Step 2 in the Connection input, click Continue

  6. Give the printer a name and description, click Continue

  7. Select Raw in the Make selection and click Continue. If you are super lucky you might see your manufacturer here. Good luck.

  8. Select Raw Queue (en) in the Model selection and click Add Printer

  9. Select printer options. For Raw Queue (en), you'll see a Starting Banner and Ending Banner. You'll probably want to select None for both of those.

4) Connect new printer to MacOS System Preferences

  1. Click Administration
  2. Click Add class
  3. Fill out the form. The Name field will be the human-readable name you want to appear in the Printers and Scanners section of System Preferences.
  4. Select the printer you just added from Members and click Add class
  5. Your printer should now appear in your Printers and Scanners
  6. (optional) - turn off CUPS web administration by issuing the command $ sudo sudo cupsctl WebInterface=no in your Terminal

5) Find your printer

  1. In your Terminal, issue the command $ lpstat -p. This will list your printers
printer HP_LaserJet_200_color_M251nw__0200B9_ is idle.  enabled since Tue Jan 15 00:24:06 2019
printer PDF_Printer is idle.  enabled since Sat Jan 11 14:00:23 2020
printer rongta is idle.  enabled since Sun Jan 10 14:37:44 2021
printer Rongta_80mm_Thermal_Printer is idle.  enabled since Sun Jan 10 14:42:19 2021

In my case I have a Rongta_80mm_Thermal_Printer

6) Print

Ok so here your mileage may vary.

  1. From your Terminal, issue the command $ lp -d <printer_name> file.txt to print file.txt to printer <printer_name>, and you'll get a print job ID in response.

In my case, I issued:

$ echo "hello" > file.txt
$ lp -d Rongta_80mm_Thermal_Printer file.txt
request id is rongta-61 (1 file(s))

Apparently you can print PDF and PostScript files this way as well, since MacOS's printing system is supposed to manage the translation between the system and the printer.