【发布时间】:2023-03-12 04:18:01
【问题描述】:
我需要有关此 C 代码的 python 版本的帮助:
#define HostBusy_high 0x02
#define control_register 0x37a
Out32 (control_register,(unsigned char)(Inp32(control_register) | HostBusy_high));
Out32 和 Inp32 是位于 inpout32.dll 中的函数,用于连接并行端口。这些函数将十六进制值作为其参数。我尝试在 python 中编写代码以获得所需的值,但这不是我得到的。请参阅下面的python版本:
from ctypes import windll
#parallel port instance
p_port = windll.inpout32
HostBusy_high = 0x02
control_register = 0x37a
write_data = write(p_port(Inp32(control_register) | HostBusy_high))
Out32 (control_register,write_data))
使用上面的代码,我似乎没有得到我想要的值。我怀疑这是无符号值。
谢谢
【问题讨论】:
-
需要更多上下文。你想用字节值做什么?
-
user680730,无意冒犯,但考虑到您的历史@stackoverflow,我建议您先阅读 Python 教程,并且仅在仍有不清楚的地方提问。给你:docs.python.org/tutorial/index.html