Telegram bot and Microsoft Office macro to automatically print text messages in Telegram on an IBM SureMark receipt printer. This version of the SureMark 4610 unfortunately only has USB and a proprietary protocol, so it doesn't work natively on Linux or any modern OS. Therefore, the only way to get it to print anything is using some windows 16-bit executable.
The printer | Samples |
---|---|
The SureMark is physically connected to a Raspberry Pi, which exposes the usb interface to an x86 Linux server using usbip.
On the Linux server, a virtual machine is running Windows XP.
The python code is also running on the Linux Server.
Whenever the user sends a text message, the bot creates a .docx
file in a shared folder with the VM.
On Windows, a batch script polls the folder every 500 ms. If it encounters the Word document, it starts Microsoft Word 2007 using a specific macro.
The macro loads the document file and appends it to an empty document which has the right page format and margins for the printer. The macro then prints the document, suppressing any errors or warnings (about margins). Lastly it deletes the file and terminates Word.
- Temporarily disable printing, using the
/sleep
command - Manage list of blocked and allowed users from telegram, as admin.
- Print unicode text. Including EMOJI 👁👅👁!!
- Print images (with captions), automatically converted to black and white bitmaps.
- Print Microsoft Office
.doc
and.docx
files. - Request a template Microsoft Office
.docx
file with the correct paper size. - Get notified when you receive a fax.
- Supports faxing stickers (remapping transparency to white)
- Print superfast using a resident font, using the <F> html-style tag
- Print numbers as EAN-13 barcode using the <BAR> tag
- Pipe any output from your terminal to the printer with
mark
! - Print png files without compression, ideal for extreme aspect ratios!
- Using Willus' pdf reflower you can print any pdf, such as two-column scientific publications. Just do
k2pdfopt input.pdf -w 400 -h 1620 -dpi 167 -idpi -2 && pdftoppm input_k2opt.pdf -r 250 out -png
and then send the resulting images to your bot (as files). Make sure you havek2pdfopt
andpdftoppm
in your path. - Automatically convert anything into a qr code using the
\qr
command - Directly put the bot in sleep mode using
ssh SERVER "pkill -USR2 suremark"
. Can be used with Apple's automation system to mute the SureMark while your phone is on Don't Disturb. - User help command
-
Review
src/linux/*.service
,src/opt/suremark.py
andsrc/config/config.ini
: replace>>>USERNAME<<<
with the username that will be running the bot on the server. -
In
config.ini
, also place your telegram bot token and user id. -
Verify you have
virtualenv
installed on your system, and runsource install
. -
Create a new machine in Virtualbox.
-
Uncheck Cable Connected in
Virtualbox settings>Network
to isolate the VM. -
Map
~/.config/suremark/shared
as a shared auto-mounting folder toZ:\
in the guest. -
Install the VirtualBox extension pack;
VBoxManage extpack install Oracle*.vbox-extpack
. -
Create a device filter for passing through the usb device to the VM.
-
Enable the systemd units. For
vboxvmservice
, you need to specify the machine UUID as follows:systemctl enable vboxvmservice@VM_UUID.service
. You can get this UUID fromVBoxManage list vms
.
- Install Windows XP (32 bit).
- Install the IBM printer driver, and make it the default printer.
- Install Microsoft Office 2007.
- Embed the macro in Word by opening Word, pressing
Alt
+F11
and pasting the code in a new script file. - Enable Microsoft Scripting Runtime in
Microsoft Visual Basic>Tools>References
. - Copy
src/windows/suremark
and its content toC:\
. - Execute
C:\suremark\poller.bat
when Windows starts (e.g. by placing a shortcut inC:\Documents and Settings\All Users\Start Menu\Programs\Startup
). - For Emoji support, install an emoji font (such as Segoe UI Emoji,
seguiemj.ttf
, make sure its name matches that in the.ini
-file). Go toControl Panel>Fonts
and drag & drop the.ttf
file.
When you can't connect the printer to the server physically, you can connect it to anything else running Linux, and virtually connect it to the server using usbip.
usbip server
- Install
usbip
. - Copy
src/raspberry/usbipd@.service
to/etc/systemd/system
. - Enable and start with
usbipd@04b3:4535.service
, verify with lsusb that the usb vendor and product ID's are correct.
usbip client
- Install
usbip
. - Run
sudo modprobe vhci-hcd
. - List the available usb devices on the server;
usbip list -r SERVER
. - Attach the printer, e.g.
sudo usbip attach -r SERVER -b 1-1.2
.
Allows you to pipe any stdout
to your printer, such as ls | mark
.
- Review
src/pipe/suremark_pipe/send_file
; change folder locations and server address. - Review
src/pipe/main.cpp
; update the username. - Make sure you have ssh access to your server with a (passwordless) key pair.
- Go to
src/pipe
and runsource install
.
You can enable RDP for your Windows XP VM for easier administration.
- Shut down your VMs.
- Download the extpack from Oracle
- Install extpack:
vboxmanage extpack install ep.vbox-extpack
- Execute
VBoxManage modifyvm "Windows XP" --vrde on
. - RDP in, e.g. by
wlfreerdp /v:SERVER
. - Consider turning it off again.
- Add automatic services. Printing reddit posts, weather.. Perhaps via RSS.