Skip to content
This repository was archived by the owner on May 16, 2023. It is now read-only.

printer encoding CP437 #24

Closed
mushunrek opened this issue May 27, 2021 · 6 comments
Closed

printer encoding CP437 #24

mushunrek opened this issue May 27, 2021 · 6 comments
Labels

Comments

@mushunrek
Copy link

Hello everybody,

I am new here. I was working on a project using the Adafruit Mini Thermal Printer and I got into trouble when I wanted to use characters from extended ASCII tables. After looking into the user manual, it seems that the default encoding of the printer is CP437. So I was wondering, why one should use thas ASCII-encoding instead of the CP437-encoding in the _write_char funtion at line 193. Even though this encoding is a little out of date, it still manages most of the special characters from EU, additionally to the English characters. It would be nice to have some possibility to change the encoding, but I didn't exactly understand from the user manual how this works exactly.

If this is not the right place to give such proposition, I would be glad about a direction where to go instead :)

Bests,
mushunrek

@jposada202020
Copy link

If you have any questions related to the Adafruit Products, I would suggest to post it in the Adafruit Forums
https://forums.adafruit.com/, as you will have more visibility
Or the Adafruit Discord Channel, maybe some folks there have the answer already

I will keep this issue open for the moment to see if anybody familiar with this code could give you an answer.

Thanks

@mushunrek
Copy link
Author

Thank you very much, but I opened the issue to make this proposition to change the code: for me the problem is solved, as I simply changed the function in my code. But I think that this change might be helpful: since no commands are sent through _write_char, and all other ASCII-characters are preserved in CP437, the functionality of the function will only be extended.

@jposada202020
Copy link

Oh I see thank you, would you mind doing a PR? :)

@tcfranks
Copy link
Contributor

@mushunrek let's compare your change......I might be willing to do a pr to get your change incorporated....

@mushunrek
Copy link
Author

Hey! I am not yet super used to git as I am not a regular programmer. If I understand it correctly, I would need to create a new branch, make the change and do a pull request afterwards?
My solution back then was rather simplistic: as I needed to extend the Printerclass anyways, I simply rewrote the specific function. Here is the code:

ENCODING = "cp437"

class Printer(ThermalPrinter):
    def _write_char(self, char):
    # Write a single character to the printer.
        if char == "\r":
            return  # Strip carriage returns by skipping them.
        self._wait_timeout()
        self._uart.write(bytes(char, ENCODING))                                            # THIS IS THE ONLY CHANGE! [except for some differences in the variable names as I had to define a different __max_column...]
        delay = self._byte_delay_s
        # Add extra delay for newlines or moving past the last column.
        if char == "\n" or self._column == self.__max_column:
            if self._column == 0:
                # Feed line delay
                delay += (self._char_height + self._line_spacing) * self._dot_feed_s
            else:
                # Text line delay
                delay += (self._char_height * self._dot_print_s) + (
                    self._line_spacing * self._dot_feed_s
                )
            self._column = 0
        else:
            self._column += 1
        self._set_timeout(delay)

Since I am a newbie, it would be great if you could tell me how exactly to proceed. I could do a branch and then a pull request if that is the correct workflow.

If I am not mistaken, there is a second function [has_paper] that didn't work with my printer. But this should go into a different issue?

@tekktrik
Copy link
Member

Resolved by #29

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants