0

I am trying to send data to a thermal printer directly.

I have the following test data:

raw_data = bytes ("This is a test", "utf-8")

I would like to include two initial bytes to build the sequence ESC+@ (character ESC is ASCII 27) to initialize the printer.

How shall I do that?

1 Answer 1

2

Use \033 to represent the ESC character.

raw_data = bytes ("\033@This is a test", "utf-8")
Sign up to request clarification or add additional context in comments.

2 Comments

Since when is \e escape? When I try this, I just get two bytes: \ and e. Do I need a newer Python or something?
Oops, it's \e in lots of other languages, but not Python. You have to use octal or hex code.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.