gpt4 book ai didi

python - 如何在Python中查找框架集中的特定元素?

转载 作者:太空宇宙 更新时间:2023-11-03 16:53:58 24 4
gpt4 key购买 nike

我试图在长框架内找到一个特定元素,其输出如下:

接收:['01'、'03'、'3C'、'00'、'00'、'00'、'00'、'00'、'00'、'00'、'00'、 ‘00’、‘00’、‘00’、‘00’、‘00’、‘00’、‘00’、‘00’、‘00’、‘00’、‘00’、‘00’、‘4B '、'00'、'00'、'00'、'30'、'30'、'30'、'31'、'30'、'30'、'32'、'30'、'4B'、 “00”、“00”、“00”、“30”、“30”、“30”、“30”、“30”、“30”、“30”、“30”、“53” 、“4D”、“41”、“52”、“54”、“50”、“00”、“00”、“00”、“00”、“00”、“00”、“00', '00', '00', '00', '7D', '1F']

这是我正在尝试修改的代码的一部分:

    data = []
data.append(CMRead)
data.append((starting_address >> 8) & 0xFF)
data.append(starting_address & 0xFF)
data.append((num >> 8) & 0xFF)
data.append(num & 0xFF)

# opening a communication serial
if not self.Open():
return TIMEOUT

#send frame
if not self.SendFrame(address, data):
self.Close()
return TIMEOUT

#receive frame
if not self.ReceiveFrame(data, 2 + ((num + 7) // 8)):
self.Close()
return TIMEOUT

我需要一种机制来检查接收帧输出中是否存在十六进制值'53'、'4D'、'41',但我还没有。

感谢代码帮助!

最佳答案

wanted = ['53', '4D', '41']
frames = ['01', '03', '3C', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '4B', '00', '00', '00', '30', '30', '30', '31', '30', '30', '32', '30', '4B', '00', '00', '00', '30', '30', '30', '30', '30', '30', '30', '30', '53', '4D', '41', '52', '54', '50', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '7D', '1F']
captured = [(frame in wanted) for frame in frames]
any_captured = any(captured)

关于python - 如何在Python中查找框架集中的特定元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35599536/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com