python中int数组中的无符号字符数组

2024-05-28 23:45:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用wiringPi's ^{}在我2004年的液晶显示器上用wiringPi's ^{}来定义一个新字符(大写的德语变音“Ä”)

这是我的密码

import wiringpi2 as wiringpi

# Ä
cap_umlaut_a = [
    int('0b01010', 2),
    int('0b00100', 2),
    int('0b01010', 2),
    int('0b10001', 2),
    int('0b11111', 2),
    int('0b10001', 2),
    int('0b10001', 2),
    int('0b00000', 2)
]

print(cap_umlaut_a) # [10, 4, 10, 17, 31, 17, 17, 0]

wiringpi.lcdCharDef(lcd_handle, 0, cap_umlaut_a)

运行此代码时,出现以下错误:

TypeError: in method 'lcdCharDef', argument 3 of type 'unsigned char [8]'

我期望这些intsunsigned chars相同

[编辑]
在代码的另一部分中,我使用ord(char)将一个字符转换为无符号整数。这能导致正确的anser吗?在

如何将数组转换为可接受的类型?在

请注意(据我所知),python wiringPi库只是包装了wiringPi的C函数)

[编辑]
我在github上打开了一个问题:https://github.com/WiringPi/WiringPi2-Python/issues/20


Tags: 代码github编辑字符显示器intcapchar
1条回答
网友
1楼 · 发布于 2024-05-28 23:45:04

我做了一些研究,找到了相关python绑定at this github repo的源代码。在

有问题的线路是

res3 = SWIG_ConvertPtr(obj2, &argp3,SWIGTYPE_p_unsigned_char, 0 | 0 );

如您所见,您必须传入python中相当于指向unsigned char的指针。根据this thread,等价物是一个字节字符串。这意味着正确的调用应该是

^{pr2}$

相当于

wiringpi.lcdCharDef(lcd_handle, 0, b'\x0A\x04\x0A\x11\x1F\x11\x11\x00')

相关问题 更多 >

    热门问题