Thinkersbluff / DGUS-Reloaded_for_CR6-DWIN-SET_Component

Forks the Desuuuu DWIN T5UID1 touchscreen firmware, and refactors it for use on the CR6 T5L DWIN display . Must be used with the modified Klipper from https://github.com/Thinkersbluff/DGUS-Reloaded_for_CR6-Klipper_Component
GNU General Public License v3.0
20 stars 2 forks source link

UnicodeEncodeError 'ascii' codec can't encode character - ordinal not in range(128) #21

Open Thinkersbluff opened 1 year ago

Thinkersbluff commented 1 year ago

I encountered this problem, while trying to print a gcode file whose name included this non-ascii character: æ.

The attached snippet from Klipper.log shows what Klipper was able to report.

To troubleshoot this issue, I looked-up the ascii character xe6 that it was complaining about, and recognized the æ character in the filename. Sure enough, delete that character from the filename and t5uid1 is very happy to go ahead and print it.

I expect that the problem is incurred when the code that displays the current filename at the top of the Print Status screen tries to encode the message to the display.

It would probably be helpful if there is some way to substitute '_' for all non-ascii (128) characters in such strings, before they reach that routine. Can someone in the Community please suggest how I might go about adding that?

KlippyLogExtract.txt

Thinkersbluff commented 1 year ago

Coders familiar with encoding and decoding unicode strings in python may recognize the root of my troubles being that t5uid1.py is assuming all strings to be composed of some combination of the 128 ascii characters, while python3 works in unicode or utf-8. The æ character is of course not within that set of ascii characters.
This article offers some ideas, but I would rather not ignore the æ, or replace æ with a "?".

xmlcharrefreplace inserted \x.. character pointers, on the display. Party of my problem may lie in the DWIN_SET definition of this particular field...

I can use errors="ignore" for now, but looking for a better option...

Thinkersbluff commented 1 year ago

Since the current app seems to be having trouble executing vars_out.filename, I have implemented a local solution, with this mod to the filename string encoding instructions:

[t5uid1_var file_name] type: output address: 0x31c1 data_type: str data_len: 32 script: {% if printer.print_stats.filename %} {"{:>32s}".format((printer.print_stats.filename.encode(encoding="ascii",errors="ignore").decode())|trim)} {% else %} {"No name passed by slicer"}
{% endif %}

Now any non-ascii character(s) in the filename are simply left out of the filename.