Skip to content

Commit

Permalink
README.md: Add GUI Howto and update protocol
Browse files Browse the repository at this point in the history
As the phomemo backed allows CUPS to detect and use the printer,
explain the user how to configure it.

Signed-off-by: Laurent Vivier <[email protected]>
  • Loading branch information
vivier committed Dec 11, 2020
1 parent e9fa4bf commit ae5543f
Show file tree
Hide file tree
Showing 11 changed files with 122 additions and 11 deletions.
Binary file added Pictures/Bluetooth-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Pictures/Bluetooth-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Pictures/Bluetooth-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Pictures/Menu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Pictures/Printers-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Pictures/Printers-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Pictures/Printers-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Pictures/Printers-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Pictures/Printers-5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Pictures/Printers-6.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
133 changes: 122 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,93 @@ You need to be root or in the lp group
```

### 2.2. Configuration
#### 2.2.1. Bluetooth
#### 2.2.1. GUI
##### 2.2.2.1.1. Pre-requisite

The CUPS backend (phomemo) uses the Python pyBluez to connect to the printer, so
be sure to install the required dependencies, for instance with Fedora:

```
$ sudo dnf install python3-devel
$ sudo pip install pybluez
```

SELinux seems to prevent the backend to create a bluetooth socket.
If you have such error message in your syslog:

```
localhost.localdomain cupsd[2659]: Can\'t open Bluetooth connection: [Errno 13] Permission denied
```
You might need to disable SELinux enforcement to allow the backend to run correctly:

```
$ sudo semanage permissive -a cupsd_t
```

I didn't find a way to define correctly the SELinux rules to allow the backend
to use bluetooth socket without to change the enforcement mode
(the couple ausearch/audit2allow doesn't fix the problem).

##### 2.2.2.1.1. Pair the printer

1. Switch on the printer
2. Open the "Settings" window:

![Settings Menu](Pictures/Menu.png)

3. Select the "Bluetooth" Panel:

![Bluetooth Panel](Pictures/Bluetooth-1.png)

4. Select your bluetooth printer (here "Mr.in_M02"):

![Bluetooth Printer](Pictures/Bluetooth-2.png)

5. Your printer must be paired but not connected ("Disconnected"):

![Bluetooth Printer](Pictures/Bluetooth-3.png)

6. Select the "Printers" Panel:

![Printers Panel](Pictures/Printers-1.png)

You'll probably need to unlock it to be able to add a new printer.

Click on "Add a Printer...".

8. Select your printer and click on "Add":

![Printers Panel](Pictures/Printers-2.png)

9. Your printer will appear in the printers list:

![Printers Panel](Pictures/Printers-3.png)

10. Click on the settings menu of the printer and select "Printing Options":

![Printers Panel](Pictures/Printers-4.png)

11. Select "Media Size Label 50mmx70mm" and click on "Test Page":

![Printers Panel](Pictures/Printers-5.png)

12. Check the result:

![Printers Panel](Pictures/Printers-6.jpg)

#### 2.2.2. CLI
##### 2.2.2.1. Bluetooth (Direct)

This definition will use the "phomemo" backend to connect to the printer:

```
$ sudo lpadmin -p M02 -E -v phomemo://DC0D309023C7 \
-P /usr/share/cups/model/Phomemo/Phomemo-M02.ppd.gz
```

##### 2.2.2.1. Bluetooth (RFCOMM)

This definition will use the /dev/rfcomm0 device to connect to the printer:

```
$ sudo lpadmin -p M02 -E -v serial:/dev/rfcomm0 \
Expand All @@ -90,7 +176,9 @@ You need to be root or in the lp group
Before starting to print, be sure the file /dev/rfcomm0 is present
(run "rfcomm connect" for that)

#### 2.2.2. USB
##### 2.2.2.2. USB

This definition will use the /dev/usb/lp0 device to connect to the printer:

```
$ sudo lpadmin -p M02 -E -v serial:/dev/usb/lp0 \
Expand All @@ -99,33 +187,56 @@ Before starting to print, be sure the file /dev/rfcomm0 is present

## 3. Protocol

After dumpping bluetooth packets, it appears to be EPSON ESC/POS Commands.

### 3.1. HEADER

```
0x1b 0x40 0x1b 0x61 0x01 0x1f 0x11 0x02 0x04
0x1b 0x40 -> command ESC @: initialize printer
0x1b 0x61 -> command ESC a: select justification
0x01 range: 0 (left-justification), 1 centered,
2 (right justification)
0x1f 0x11 0x02 0x04
```

### 3.2. BLOCK MARKER
```
0x1d 0x76
0x30 0x00
0x30 0x00 -> number of bytes in one line: 48 bytes * 8 bits = 384 points
0xff 0x00 -> number of lines in the block (255)
0x1d 0x76 0x30 -> command GS v 0 : print raster bit image
0x00 mode: 0 (normal), 1 (double width),
2 (double-height), 3 (quadruple)
0x30 0x00 16bit, little-endian: number of bytes / line (48)
0xff 0x00 16bit, little-endian: number of lines in the image (255)
```

Values seem to be 16bit little-endian

If the picture is not finished, a new block marker must be sent with
the remaining number of line (max is 255).

### 3.3. FOOTER
```
0x1b 0x64 0x02 0x1b 0x64 0x02 0x1f 0x11 0x08 0x1f 0x11 0x0e 0x1f 0x11
0x07 0x1f 0x11 0x09
0x1b 0x64 -> command ESC d : print and feed n lines
0x02 number of line to feed
0x1b 0x64 -> command ESC d : print and feed n lines
0x02 number of line to feed
0x1f 0x11 0x08
0x1f 0x11 0x0e
0x1f 0x11 0x07
0x1f 0x11 0x09
```
### 3.4. IMAGE

Each line is 48 bytes long, each bit is a point (384 pt/line).
size of a line is 48 mm (80 pt/cm or 203,2 dpi, as announced by Phomemo).
ratio between height and width is 1.
Don't send the byte "0x0a" to the printer, it breaks the rendering...

### 3.5. Printer message

```
1a 04 5a
1a 09 0c
1a 07 01 00 00
1a 08
51 30 30 31 45 30 XX XX XX XX XX XX XX XX XX -> Serial Numer: E05C0XXXXXX
```

0 comments on commit ae5543f

Please sign in to comment.