我必须在通信协议中处理一些控制字/标志,而我的重点是编辑器为我提供了标志名的建议,并跳转到带有“ F3”的标志的定义。下面的代码满足了这些要求(很遗憾,今天的PyCharm索引器不支持@nealmcb的ctypes解决方案。)。 欢迎提出建议:
""" The following bit-manipulation methods are written to take a tuple as input, which is provided by the Bitfield class. The construct
looks weired, however the call to a setBit() looks ok and the editor (PyCharm) suggests all
possible bit names. I did not find a more elegant solution that calls the setBit()-function and needs
only one argument.
Example call:
setBit( STW1.bm01NoOff2() ) """
def setBit(TupleBitField_BitMask):
# word = word | bit_mask
TupleBitField_BitMask[0].word = TupleBitField_BitMask[0].word | TupleBitField_BitMask[1]
def isBit(TupleBitField_BitMask):
# (word & bit_mask) != 0
return (TupleBitField_BitMask[0].word & TupleBitField_BitMask[1]) !=0
def clrBit(TupleBitField_BitMask):
#word = word & (~ BitMask)
TupleBitField_BitMask[0].word = TupleBitField_BitMask[0].word & (~ TupleBitField_BitMask[1])
def toggleBit(TupleBitField_BitMask):
#word = word ^ BitMask
TupleBitField_BitMask[0].word = TupleBitField_BitMask[0].wor