flybywiresim / aircraft

The A32NX & A380X Project are community driven open source projects to create free Airbus aircraft in Microsoft Flight Simulator that are as close to reality as possible.
https://flybywiresim.com
GNU General Public License v3.0
4.97k stars 1.03k forks source link

Physical printing on POS style thermal printers is unreadable #6468

Closed plhought closed 2 years ago

plhought commented 2 years ago

Aircraft Version

Development

Build info

{
  "built": "2022-01-01T15:56:48+00:00",
  "ref": "master",
  "sha": "e43e61e317489340a6b11e4960bcb72e72b0e722",
  "actor": "aguther",
  "event_name": "manual"
}

Describe the bug

Utilizing the new print interface of the MCDU server, when utilizing a widely avialiable and inexpensive POS style thermal printer ("POS-58" type - which is widely re-branded as resold under a number of different brands - TEROW, WAVA, MUNBYN, Zjiang etc etc), the text is very small an unreadable - along with going through about a foot and half of thermal paper before actually attempting to print something. 20220101_121800 This is in contrast to a similar function on the FSLabs Airbus, which actually includes pre-built settings to support POS-58 thermal printers, as they are widely utilized by some of their userbase.

Expected behavior

The text would print more in a manner similar to the actual aircraft - which also uses a thermal-printer - although wider.

Steps to reproduce

  1. Have a POS-58 type thermal printer
  2. Correctly set up the MCDU Server print option
  3. Attempt to print something via the ATSU in the MCDU

References (optional)

20220101_121800

Additional info (optional)

No response

Discord Username (optional)

Patrick#2854

andrejetcat commented 2 years ago

I think, it would solve the "problem" when the MCDU program gives out a normal word or .txt document instead of a .pdf

tracernz commented 2 years ago

One workaround is to increase the font size in the server code (I found 28 works well). It gives imperfect but perfectly readable output. This could be made an option.

The other way is to print directly to the printer in raw mode.. this is very easy in Python using the excellent escpos library but I cannot find a good JS library (the “escpos” library on npm is unrelated unfortunately). At the moment I am using a small Python script that connects to the MCDU websocket server, listens for print events, and prints in raw mode. It’s by no means production ready; there is no error handling or reconnect logic, everything is hardcoded including the printer name. Dependencies are escpos and websockets (you will need to install these with pip).

#!/usr/bin/env python

import asyncio
import json
import textwrap

from escpos.printer import Win32Raw
import websockets

# tune for your printer
COLUMNS = 44
PRINTER_NAME = 'HP Receipt'

def flatten(t):
    return [item for sublist in t for item in sublist]

def printer(message):
    print(message)
    p = Win32Raw(PRINTER_NAME)
    p.open()
    p.set(align='left', smooth=True)
    p.text(message + "\n")
    p.print_and_feed(n=3)
    p.cut(mode='PART')
    p.close()

async def printer_relay():
    async with websockets.connect("ws://localhost:8080") as websocket:
        while True:
            message = await websocket.recv()
            if message.startswith('print:'):
                msg = json.loads(message[6:])
                lines = flatten([m.replace('\\n', '\n').splitlines() for m in msg['lines']])
                output = '\n'.join([textwrap.fill(l.rstrip(), COLUMNS) for l in lines])
                printer(output)

asyncio.run(printer_relay())
andrejetcat commented 2 years ago

thank you @tracernz , but its very hard to understand for no-Pro´s and even hard to replicate/dublicate :/

Watsi01 commented 2 years ago

thank you @tracernz , but its very hard to understand for no-Pro´s and even hard to replicate/dublicate :/

Don't worry. We think about something to configure it.

Ryane37 commented 2 years ago

Do you think it’s a quick fix to sort.

Georgelumkin commented 2 years ago

I also have a POS-58 printer and would really love this to be solved! Here is a photo of a .txt file printed (right) vs the MCDU PDF (left), and also the printer I’m using.

319D47CA-AB63-41D7-B02F-BFDFCD373538 E7A06190-C5E1-42B0-BE9E-60188427CCF4

Ryane37 commented 2 years ago

Has anybody tried it on the exp version check if that works.

frankkopp commented 2 years ago

Has anybody tried it on the exp version check if that works.

Experimental is only different for LNAV - otherwise identical to Dev

wogapat commented 2 years ago

Same issue for me, different printer. It is a thermal printer though.

frankkopp commented 2 years ago

Several improvements in development: https://github.com/flybywiresim/a32nx/pull/6446

New parameters font-size and paper-size to adapt output to different printers.

Georgelumkin commented 2 years ago

Several improvements in development: #6446

New parameters font-size and paper-size to adapt output to different printers.

Amazing! What variable do need to enter after the new —paper-size argument ?

frankkopp commented 2 years ago

Several improvements in development: #6446 New parameters font-size and paper-size to adapt output to different printers.

Amazing! What variable do need to enter after the new —paper-size argument ?

This will all be documented - a draft of the documentation (which will be removed after the feature is released) is here: https://docs-git-fork-frankkopp-updt-webmcdu-docs-flybywire.vercel.app/fbw-a32nx/feature-guides/web-mcdu/#advanced-start-options Note: This is all still in development and subject to change!!

andrejetcat commented 2 years ago

would it be possible that the MCDU gives out a .txt/word file, or is it just a .pdf?

Georgelumkin commented 2 years ago

Sorry folks I’m new to all this, are these changes now live in either the Development or experimental versions in the installer? Or can I download the server exe from here on GitHub?

thanks in advance from an enthusiastic newbie!!

frankkopp commented 2 years ago

Sorry folks I’m new to all this, are these changes now live in either the Development or experimental versions in the installer? Or can I download the server exe from here on GitHub?

thanks in advance from an enthusiastic newbie!!

Patience please :) - the PR with the improvements is still in development. https://github.com/flybywiresim/a32nx/pull/6446

Georgelumkin commented 2 years ago

Sorry folks I’m new to all this, are these changes now live in either the Development or experimental versions in the installer? Or can I download the server exe from here on GitHub? thanks in advance from an enthusiastic newbie!!

Patience please :) - the PR with the improvements is still in development. #6446

Ah understood! Thank you @frankkopp, I will sit down and wait in line with everyone else 😬 thanks for the amazing work!

plhought commented 2 years ago

Several improvements in development: #6446 New parameters font-size and paper-size to adapt output to different printers.

Amazing! What variable do need to enter after the new —paper-size argument ?

This will all be documented - a draft of the documentation (which will be removed after the feature is released) is here: https://docs-git-fork-frankkopp-updt-webmcdu-docs-flybywire.vercel.app/fbw-a32nx/feature-guides/web-mcdu/#advanced-start-options Note: This is all still in development and subject to change!!

The paper-size option doesn't really help with thermal-printers though? Won't it just spit out unneccesary lengths of blank thermal paper before printing the text itself?

frankkopp commented 2 years ago

Several improvements in development: #6446

New parameters font-size and paper-size to adapt output to different printers.

Amazing! What variable do need to enter after the new —paper-size argument ?

This will all be documented - a draft of the documentation (which will be removed after the feature is released) is here: https://docs-git-fork-frankkopp-updt-webmcdu-docs-flybywire.vercel.app/fbw-a32nx/feature-guides/web-mcdu/#advanced-start-options Note: This is all still in development and subject to change!!

The paper-size option doesn't really help with thermal-printers though? Won't it just spit out unneccesary lengths of blank thermal paper before printing the text itself?

Not according to the users who already tested this.

tracernz commented 2 years ago

The paper-size option doesn't really help with thermal-printers though? Won't it just spit out unneccesary lengths of blank thermal paper before printing the text itself?

It does for me. The smaller the paper size the larger the text comes out.

Tuftymeercat37 commented 2 years ago

Just tried this with my GoojPrt PT-200 58mm thermal printer (Paper Size set to C8 & font size10). The printout is perfect :-)

msoehl commented 2 years ago

How can I get this option? I have only the old one's

VohnMclane commented 2 years ago

I don't appear to have the options to change the text and the paper size they are not appearing on my command line

frankkopp commented 2 years ago

I don't appear to have the options to change the text and the paper size they are not appearing on my command line

This improvement feature is not yet released.

VohnMclane commented 2 years ago

ahh okay just wasn't sure as @Tuftymeercat37 seem to have changed theirs

Tuftymeercat37 commented 2 years ago

I have just purchased the thermal printer so I was testing it by downloading/installing the build from PR #6446. This is not merged into the published Dev or Experimental versions yet. Hopefully it will be soon as it looks like it's just waiting for review.