EP44 on Windows 10 with a hardware serial port

Should be easy enough.

After plugging in the printer cable (a full null modem cable works, but so does a more minimal one — YMMV) and turning the printer on and switching the printer to ‘Terminal’, go into Windows printer dialog and add a printer:

Choose: The printer that I want isn’t listed

Choose “Add a local printer or …”

Choose the port (probably COM1)

Choose generic, text only as the driver and create the printer

Then go into printer properties and go to port and configure:

1200 bits per second (baud), 8 bit data, parity none (N), 1 stop bit, hardware flow control (if your cable allows hardware handshaking — see ‘Full handshaking’ at https://en.wikipedia.org/wiki/Null_modem).

On the printer, hit red C button and set 1200 baud, 8 bit data, N parity, Y for error and I’m not sure code type matters too much unless you want to print some interesting characters.

Then the test page prints all fine.

yer gonna be fine fine fine

SiPix A6 on Linux — works a treat

This is relatively simple. We set the serial port settings as per the SiPix instructions (see link below), we make a binary file according to the recipe at OpenPrinting (link below) and we send that binary file to the requisite device. That shows that it works. But then … then it turns out we can use CUPS, like a real printer.

We have a hardware serial port, and the user is in the dialout group so:

$ stty -F /dev/ttyS0 -a
$ stty -F /dev/ttyS0 115200 cs8 -cstopb -parenb
$ stty -F /dev/ttyS0 -ixon
$ stty -F /dev/ttyS0 crtscts

Then we follow the steps here to make a binary file then we cat it to the printer. Make a new file then print it. (Writer is my script that creates an empty ODT file then opens it.)

$ Writer newfile.odt

Make an A4 page of text, export to PDF from LibreOffice, then …

$ pdftops newfile.pdf
$ psresize -h14.8cm -w10.5cm -PA4 newfile.ps newfilea6.ps
$ gs @sipixa6.upp -sPAPERSIZE=a6 -sOutputFile=file-to-print.bin newfilea6.ps -c quit
$ cat file-to-print.bin > /dev/ttyS0

Note: psresize does not have an A6 size, so used the actual dimensions. The UPP file comes from http://openprinting.org/driver/sipixa6.upp and is used unmodified. We copy it to somewhere gs will find it.

In other words, it ‘just works’ with a real hardware serial port. Now, to set it up as a CUPS printer … we can ask openprinting.org to generate us a PPD file, and we have the serial port settings, because you can find a manual online (eg https://images-na.ssl-images-amazon.com/images/I/81kQgwUCBXL.pdf) so …

  1. CUPS is installed and the daemon is running, so … point Firefox at http://localhost:631/admin
  2. Click Add Printer and log in
  3. Choose Local Printers: Serial Port #1
  4. Choose settings: 115200 baud, no parity, 8-bit data, DTR/DSR hardware control (this was a guess, and turned out to be wrong)
  5. Name it (sipix)
  6. Choose the make and model — SiPix is in there! And this is the only model (can browse to the PPD from http://openprinting.org/driver/sipixa6.upp if it is not in the list of printers already)
  7. Do not change anything else. Leave input paper size as A4, to be scaled by the driver not the application
  8. Add printer
  9. Print test page
  10. Nope, printer just turns off
  11. Try RTS/CTS flow control
  12. Success!
The CUPS test page — looks fine (real size is on 1/4 of an A4 page).

The printer itself:

The printer -- image captured on the flatbed scanner

Can we print from the command line? Plain text:

$ lp -d sipix a-file-with-some-text.txt

Yep, fine, though it feeds some wasted paper through first. PDF file:

$ lp -d sipix newfile.pdf

Yep. All right.

Now, If I use a good-quality USB to serial dongle, I can print from a USB port. That means the SiPix is still a viable portable printer

Now, what next…?

EP-44 serial printer via USB adapter: Linux

Short story to save reading the rest: I did not get it to work and may have bricked the typewriter.

Long story…

First, need cables. From ebay — a USB to DB-9 (actually DE-9) cable ($4), plus a DB-9 to DB-25 adapter — to print from a modern machine like my NetBook. $4.

Photo of these components.
USB to serial cable plus driver disk and DB-9 to DB-25 adapter.

I can verify that using drivers that came on the CD, it works on Windows 10 — see this post. But it doesn’t work on Linux, making me wonder if there’s a problem with the drivers.

To use it as a terminal I expect I’ll need a null modem cable but for now one thing at a time.

Anyway, when I plug it into my Linux box, /dev/ttyUSB0 is created (good) and I can send characters to the printer but it does not work properly.

When I try to send characters to the serial device (just a thermal printer), I find that they’re all messed up. If I use GTKterm to send hex codes, I find that 0x19, 0x39, 0x59 etc up to 0xF9 all print ‘y’ (correct code, 0x79). Playing with the various options makes no difference. So something is going wrong.

Using lsusb, I get

vendor=0x1a86 product=0x7523

And lsmod | grep USB gives a bunch of stuff, including showing that usbserial and ch341 have been loaded.

$ modinfo ch341

confirms that it is the one that is associated with the vendor and product above, but the CD that came with the converter provides pl2303.c (a .c file that can only be compiled against outdated Linux kernel headers, so is no use).

If I use modprobe or rmmod to remove ch341 and insert (the modern version of) pl2303, the /dev/ttyUSB0 device vanishes. If I unplug and replug the USB device, ch341 is reloaded.

I am wondering if the vendor/product info should be associated with pl2303 instead of ch341. So I recompiled the two modules and moved the vendor and product ID information out of ch341 and into pl2303. Here is the compiling procedure — keeping in mind this is all new to me…

https://wiki.archlinux.org/index.php/Compile_kernel_module

1. Find kernel version (uname -r)

4.9.0-7-amd64

2. Get kernel source.

https://www.kernel.org/

https://packages.debian.org/stretch/linux-source

https://packages.debian.org/stretch/linux-source-4.9

OK, just install it.

$ apt-get install linux-source

will automatically pull down the right one.

$ sudo apt-get install linux-source

3. Copy the source into a working directory — don’t mess with the actual install!

Create a working directory, cd into it and copy the cached .deb file from the source install:

$ cp /var/cache/apt/archives/linux-source-4.9_4.9.110-3+deb9u2_all.deb .

4. explode the .deb

$ dpkg -x linux-source-4.9_4.9.110-3+deb9u2_all.deb /path/to/where/you/want/the/files

5. find the source inside that and copy to another working directory (‘build’)

$ mkdir build
$ cp usr/src/linux-source-4.9.tar.xz build
$ cd build

6. explode that

$ tar -xvJf linux-source-4.9.tar.xz

7. Preprocess

as per https://wiki.archlinux.org/index.php/Kernels/Traditional_compilation#Download_the_kernel_source (I am copying slavishly!)

$ cd linux-source-4.9/
$ make clean && make mrproper

8. Find the files within the build directory

$ find . -iname "pl2303.*"
./drivers/usb/serial/pl2303.h
./drivers/usb/serial/pl2303.c

$ find . -iname "ch341.?"
./drivers/usb/serial/ch341.c

9. Plug in the device and run lsusb to get vendor and product codes

$ lsusb

Bus 004 Device 004: ID 1a86:7523 QinHeng Electronics HL-340 USB-Serial adapter

OK, vendor=0x1a86 product=0x7523

10. Where does that show up?

$ cd drivers/usb/serial/
$ grep 0x1a86 *
ch341.c: { USB_DEVICE(0x1a86, 0x7523) },
ch341.c: { USB_DEVICE(0x1a86, 0x5523) },

11. OK, need to comment the device out in ch341.c and add it to pl2303.h (pl2303.c uses the .h file to store these IDs)

Add the lines:

#define QINHENG_VENDOR_ID 0x1a86
#define QINHENG_PRODUCT_ID_HL340 0x7523

near the top of pl2303.h

12. Add an entry to the struct in pl2303.c

static const struct usb_device_id id_table[] = {
… etc …
}

{ USB_DEVICE(QINHENG_VENDOR_ID, QINHENG_PRODUCT_ID_HL340) },

If the first try does not work, can try adding the ‘QUIRK’ switch to it.

13. Can we remove it from ch341.c?

Just comment it out:

/* { USB_DEVICE(0x1a86, 0x7523) }, DJG*/

14. OK, can we compile?

$ cd /whatever/path/to/linux-source-4.9 and

$ make oldconfig
$ make modules_prepare

Looks good.

15. Try the make step

$ make M=drivers/usb/serial

16. Seems to have worked.

Test.

First, lsmod | grep 341

$ lsmod | grep 341
ch341 16384 0
usbserial 49152 1 ch341
usbcore 253952 9 usbhid,usb_storage,ehci_hcd,usbserial,xhci_pci,uas,ch34,xhci_hcd,ehci_pci

OK, and is /dev/ttyUSB0 present?

$ ls /dev/ttyU*

Yep.

OK, if I remove module ch341

$ sudo modprobe -r ch341
[sudo] password for username:

$ ls /dev/ttyU*
ls: cannot access '/dev/ttyU*': No such file or directory

OK, it’s gone.

Now, manually insert the new pl2303.ko

(I’ve cd to the directory where it lives)

$ sudo modprobe usbserial
$ sudo insmod pl2303.ko
insmod: ERROR: could not insert module pl2303.ko: Invalid module format

uh-oh.

Hang on … version magic?

But that needs modprobe which needs the module to be in /lib/modules/$(uname -r). That’s the actual file system. OK, copy it there (after backing up the old one).

17. Go to actual modules dir

$ cd /lib/modules/4.9.0-7-amd64/kernel/drivers/usb/serial
$ sudo cp pl2303.ko pl2303.ko_bak

Copy in the old one

$ sudo cp /path/to/new/pl2303.ko .

18. modprobe with force

$ sudo modprobe --force pl2303

19. Does /dev/ttyUSB0 exist now?

Yes!

20. Check lsmod

Now, pl2303 is appearing where ch341 was previously. Now the real test — can I print?…

21. Nope!

Next, change module code to include the PL2303_QUIRK_UART_STATE_IDX0

22. Nope! OK.

OK, tried that, did not work, copied all the original modules back.

Since the device worked fine on Windows 10 through RealTerm, I am wondering if there’s something odd about the drivers on Linux. On the other hand, the drivers I used on Windows were off the disk that came with the device, whereas the Linux drivers come with the OS. If the chip in the device is a cheap knock-off, maybe they provide drivers that work with their chip but since the Linux ones would be developed for the original chip, they might not work with a knock-off. I really don’t know, this is way beyond my knowledge.

It’s unlikely that the Linux driver is really flaky.

So, for now, the converter does not work on Linux. This is not an uncommon issue with these cheap chips.

PS:

Tried using it via a Windows 7 VM on a Linux box; installed the driver for the converter and then RealTerm. Sent some text to the printer OK, then it started printing in a weirdly, ultra-compressed font and I cannot figure out how to switch the typewriter back to working properly. I must have written some weird command into it’s settings, and even ‘factory rest’ does not seem to work; I may have bricked it! Do’h.

Cheap as chips.

EP-44 serial printer via USB adapter: Windows 10

RS232 Serial printer on Windows 10 (current as of August 2018)

(1) Installed the Windows 10 driver from the CD that came with it  (file Pl2303_Prolific_DriverInstaller_v1.10.0.exe).

(2) Plugged in device, then plugged my home-made serial printer cable into the converter and connected that to the typewriter/printer.

<img class="size-medium wp-image-4508" src="https://darrengoossens.wordpress.com/wp-content/uploads/2018/07/usbtoserial.jpg?w=300" alt="Image of adapter, DB-9 (actually DE-9) to DB-25 converter and mini-CD with drivers” width=”300″ height=”225″ /> USB to serial adapter

(3) Installed RealTerm (https://sourceforge.net/projects/realterm/).

(4) Ran RealTerm. Selected Port 3, 1200 baud, other settings to match the typewriter. Did not change any other settings.

Screenshots showing the settings; 1 stop bit, 8 data bits, parity set to none, 1200 baud on port 3.
Screenshots showing the configuration.

The dialogue showing file being sent to printer. Image showing the pin functions. For DB-9, 1 is DCD, 2 is RSD, 3 is IXD, 4 is DTR, 5 is ground, 6 is DSR, 7 is RTS, 8 is CTS and 9 is RING. I don't know what all these mean!

(5) Started typing in the terminal and it echoed onto the printer perfectly.

(6) Grabbed some screenshots of the configuration (see above).

(7) So tried adding it as a printer — no luck.

(8) But, if we open RealTerm and then go to the Send tab, we can use the ‘Dump File to Port’ option and that works!

(9) Sort of — it works one line at a time, bit like on Linux. I think the buffer gets filled up. Add in some delays at EOL.

(10) Fiddled with some settings and got it to work. The trick was to lower the baud rate enough (both on printer and computer).

Configuration, modified to show a baud rate of 110 (that's very low!)

EOL (end of line) set to carriage return plus line feed. Like on DOS.
The RealTerm settings that worked for printing.

(11) Since RealTerm is scriptable, I am guessing this could be automated. Or a Python script.

(12) If RealTerm is not already open, a script can be used to use it to print from the Windows CMD line.

https://stackoverflow.com/questions/2161180/com-port-terminal-program

https://hw-server.com/constrc/domaci_automatizace/domaci_automatizace.html#Command Line

Create a batch file

Let’s call it ep44print.bat. To use it, put it in the path and type:

C:\> ep44print filename.txt

Here the batch file is typed out:

C:\> type ep44print.bat
@echo off
echo .
echo Set printer to 110 baud, 8 bit data
echo .
pause
"c:\Program Files (x86)\Bel\Realterm\realterm.exe" baud=110 port=3 sendquit=%1
echo .
echo %1 printed, I hope

the command ‘sendquit’ just sends the file then quits RealTerm.

It’s good to first format the document to be less than 80 cols wide. But there we go.

One important conclusion — the main reason for setting up on Windows was to test the USB to serial device, since I could not get it to work on Linux; and … the converter does seem to work. So its problems on Linux seem to be driver-related. That’s useful to know.

Appendix

First need cables. From ebay — a USB to DB-9 cable ($4), plus a DB-9 to DB-25 adapter — to print from a modern machine like my NetBook. $4.

Photo of these components.
USB to serial cable plus driver disk and DB-9 to DB-25 adapter.

44 44 44 44.

Printing to the Brother EP-44: Escape codes and ASCII symbols

The EP-44 is a thermal printing typewriter from around 1984. It also comes with an RS-232c port and the documentation sys it can be used as a printer and terminal.

I’ve been exploring how to use it as a printer.

Here’s some stuff about escape sequences and formatting text when printing to the EP-44.

The EP-44 can be set to expect text encoding as ‘7BIT’, ‘8BIT’ and ‘T/W’. 7 and 8 bit correspond to ASCII codes and T/W is a slightly different code table that includes a couple of escape sequences for controlling the typewriter.

T/W mode

If we set the typewriter in T/W mode, we can make it do superscripts, subscripts and underlines by entering escape sequences into the string of text sent to the machine. One can enter escape sequences in Vim by going into insert mode and typing Ctrl+v then Esc. In the editor screen it should look like ^[ (but typing caret then square bracket won’t work!). Then type the key. ^[D scrolls to give superscript; scroll back down with ^[U; reverse the order to do subscript. ^[E turns underline on, ^[R turns it off.

Here is a screenshot of a text file in Vim:

A screenshot of the file, showing escape codes.
A file, with escape codes, viewed in Vim.

Vim kindly syntax highlights the escape codes.

Here is the printout, printed by simply catting the file to /dev/ttyS1 (in this case):

A scan of the printout.
The printout.

So we can see that the escape codes do their job. Remember, this is with the typewriter in T/W mode; in 7BIT or 8BIT this does not work.

Quirks of T/W mode include: if you send a keyboard caret (^) it prints a raised 2 (like a squared). Left brace gives a one-quarter symbol, right brace gives pilcrow, back tick gives degree symbol, pipe gives one-half and tilde gives section mark. Actually, probably this is pretty useful.

So that’s T/W mode — ideal if super- and subscript and underline are important and the unaccented, first 128 ASCII characters are all you need. (Basically, the characters you can access using the keys with or without the shift key).

Also, for some reason ^[Y gives a plus/minus symbol.

8BIT mode

8BIT mode gives access to (some of) the ASCII characters up to FF (number 256). But if we set the typewriter to 8BIT and send the text file shown above, we get this:

Screenshot, showing how the escape codes don't work.
Same file, 8BIT mode.

So the escape codes don’t work. But we do get access to some more characters.

I fired up bvi and made a file consisting of hex values from 20 (a space) up to FF, plus a little trick in the second half. Here’s what it looks like in bvi (I love that VGA font):

Screenshot showing the bvi window.
Hex view of the file.

When we print this file, we get:

Scan of printout.
Printing to the typewriter using ASCII values up to 256 (FF).

First, we can see that the caret etc are correctly interpreted. Though I cannot see a pilcrow anywhere! So what’s the code for that?

Second, we see that (as the EP-44 manual shows) we get access to a lot more characters. Most can be entered from the EP-44 keyboard, though not all (I can’t see guillemets on the EP-44 keyboard, but I guess they’re in the ROM somewhere since they’d be used on French versions, for example).

The line shown as: 0000…///###.##

Actually consists of four O, three backspace characters (hex value 08), three slashes, three hashes, one tab character and two hashes.

We can see that the backspaces work, and give us three slashed O. This means in 8BIT mode we can superimpose characters; for example we could put a hat (caret) on top of a variable, or a degree symbol for an accent (though accented A and a are available elsewhere).

The last bit of the file shows that this lets us overcome the lack of underline escape codes in 8BIT mode — we can backspace and then print an underscore character. I’ve done it character-by-character, but based on the clattering of the typewriter that this engendered, it might be better to write the whole phrase then backspace and do the underline all in one go.

This would also allow strike-through, using a series of hyphens, though of course they would not meet, so it would be a dashed line.

Could be quite good for ASCII art.

Since the 8BIT codes include a superscript 2, if we were only typing stuff with squares that would be the way to go!

I think the tab character worked, but I’m not sure since the gap is only about 1 character wide — but that could reflect the tab stop, I’m not sure.

Useful references for this were: http://www.asciitable.com/.

and

The manual: http://munk.org/projects/Brother-EP44-User_manual.pdf.

Conclusion

The 8BIT mode is preferable unless superscript and subscript are important. 7BIT was just like 8BIT but limited to the first 128 characters.

 

Madness.

Brother EP-44 as a serial printer via serial port

The EP-44 is kind of fun. Here’s something rather nifty.

This is about using it to print from a DB-9 (actually DE-9) serial port on the back of an old desktop computer. First needed cables; a serial printer cable as discussed here. I made one up from bits from Jaycar. Total cost — about $4.

So, first I used an older computer (i386) that actually has a DB-9 serial port. I bought a male DB-25 plug and a female DB-9 from Jaycar and used some hook-up wire in the shed to solder up a cable.

I then plugged the cable into the computer and the printer.

Here is the story, typed up on the old computer and printed to the EP-44.

Printed using this command
$ cat testfile.txt > /dev/ttyS0

Typewriter settings
-------------------
Baud Rate:  1200
Bit Length: 8
Parity:     N
New Line:   CR
Code:       8bit
Er:         Y

Printing out ttyS0 configuration information
--------------------------------------------
$ stty -F /dev/ttyS0 -a

speed 1200 baud; rows 0; columns 0; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U, eof = ^D; eol = <undef>; 
eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; 
werase = ^W; lnext ^V; flush = ^O; min = 1; time = O; —parenb —parodd cs8 hupcl
-cstopb cread clocal -crtscts -ignbrk —brkint ~ignpar
—parmrk —inpck -istrip -inlcr —igncr icrnl ixon —ixoff
—iuclc -ixany -imaxbel -iutf8 opost -olcuc -ocrnl onlcr
-onocr -onlret -ofill -ofdel n10 cr0 tab0 bs0 vt0 ff0 isig 
icanon iexten echo echoe echok —echon1 ~noflsh 
-xcase -tostop -echoprt echoctl echoke

This is printed out but saved for input back into stty (later I was to find that this did not work)
---------------------------------------------------------------------------------------------------
$ stty —F /dev/ttyS0 --save 
500:5:cb9:8a3b:3:1c:7f:15:4:0:1:0:11:13:1a:0:12:f:17:16:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0

What I did was pretty simple
----------------------------
(1) Made up the cable as per the website.

(2) Booted up the old computer (old Ubuntu)
$ uname -r
Linux computername 3.0.0-32-generic #51-Ubuntu SMP Thu Mar 21 15:51:26 UTC 2013 1686 i686 i386 GNU/Linux 
$ cat /etc/debian_version 
wheezy/sid (Seems to be Oneric something-or-other)

(3) Made the tty agree with the typewriter:
$ stty -F /dev/ttyS0 speed 1200 
$ stty -F /dev/ttyS0 cs8

Note: I did all this as root.

Then catted the file to the device.

Notes

I did that as root, but regular user username can do it if I run:

$ sudo usermod -a -G dialout username

Output has empty lines in it — I think I should switch to CR + LF for the New Line setting (yes — fixed).

It is at least quite notionally possible to make up a script that would reformat a text file, add any appropriate codes, page the text sensibly, possibly including pauses or whatever, and send it to the printer. In fact, I have done this (link to post).

So … it works from an old-fashioned hardware serial port. Will it work using the USB converter (turns out Windows yes, Linux no, at least not for me)? Then I’II have a battery-powered printer to carry with my netbook.

It would be nice if it could be accessed like a proper printer, through a print dialogue, for example, but I do not think that is critical, given the limited capabilities of the machine. (No sheet feeder (though could set it up to use a fax roll), no fonts, only the possibility of underline, not many characters per line, and so on.)

I would also like to develop a serial plug for the HP 200LX. A handmade rectangular plug with a short cord to a male DB-9 (less than $2 at Jaycar) and no doubt I could print from the palmtop.

The type works well with OCR as long as the darkness is OK.

It would be able to cope with the output from dvi2tty if the column width is set correctly in dvi2tty.

To use it at a terminal I expect I’ll need a null modem cable but for now one thing at a time.

Here is part of the printout from the serial port to the EP-44, scanned. It can look better than this — this is thermally printed on a battered old fax roll that had creases and blotchy stains on it.

A scan of the text which has been included above in the post.
A scan of text output from the EP-44 via the serial port. I did have to make quite a few corrections after OCR.

I followed up by trying to print from my AlphaServer, running Debian 5.  It worked from COM2 (but not COM1), and all I had to do was set the baud rate.

I was also able to set it up to run through lp on the command line. Like this:

Open browser, go to localhost:631 (Cups web interface).

Administration: Add printer

Name: EP-44
Location: Mobile
Description: Print from the command line, send only ASCII text

Device

Serial port #2 (/dev/ttyS1)

Serial Port Settings for EP-44

Baud Rate: 1200
Parity: None
Data Bits: 8
Flow Control: None

Make

Raw

Model/Driver for EP-44

Raw Queue (en)

Note: Since this is my old AlphaServer, Cups version is 1.3.8.

This did not work for printing from gui, even from text editors like gedit — even though set to raw, gnome (gnome 2 in this case, since it is old Debian) still puts postscript wrappers around the files. Why, I don’t know. Could not be bothered chasing it up.

I tried printing from the terminal emulator. I found that no matter what New Line setting I put on the printer, I got that stepping down effect:

Where the text
              Does a line feed but not a newline
                                                at the end of each line of the text file.

but, if I used vim (or unix2dos) to make it a DOS file (:set ff=dos) then I could use

lp -d EP-44 filename.txt

in a terminal window and it worked!

Long files can be an issue — but see this post.

I don’t know why setting New Line to CR or CR+LF did not help, but I found I had to make it a DOS file.

So now I can print using cat or lp, but not from a GUI.

See newer post for some more details on printing control.

So far, so pointless.