如何实现串行设备使用的自定义代码页,这样我就可以在Python中转换文本了?

时间:2022-10-30 16:13:00

I have a scrolling LED sign that takes messages in either ASCII or (using some specific code) characters from a custom code page.

我有一个滚动的LED标志,它从一个自定义的代码页中使用ASCII或(使用一些特定的代码)字符。

For example, the euro sign should be sent as

例如,欧元符号应该被发送。

<U00>

and ä is

和一个

<U64>

(You can find the full code page in the documentation)

(您可以在文档中找到完整的代码页)

My question is, what is the most pythonic way to implement this custom code page, and to have a codec that can convert UTF strings to my custom code page ?

我的问题是,实现这个自定义代码页的最python的方式是什么,并且有一个可以将UTF字符串转换为我的自定义代码页的编解码器?

1 个解决方案

#1


3  

  1. Pick a name for your encoding, maybe "led_display", whatever.
  2. 为您的编码选择一个名称,可能是“led_display”,随便什么。
  3. Implement and register a codec with the standard library.
  4. 用标准库实现和注册一个编解码器。
  5. Pythonic profit!
  6. 神谕的利润!

#1


3  

  1. Pick a name for your encoding, maybe "led_display", whatever.
  2. 为您的编码选择一个名称,可能是“led_display”,随便什么。
  3. Implement and register a codec with the standard library.
  4. 用标准库实现和注册一个编解码器。
  5. Pythonic profit!
  6. 神谕的利润!