如何在Python的框架集中找到特定的元素?

2024-09-29 18:43:17 发布

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

我试图在一个长帧中找到一个特定的元素,它的输出是这样的:

接收:['01','03','3C','00','00','00','00','00','00','00','00','00','00','00','00','00','00','4B','00','00','30','30','31','30','32','30','4B','00','00','30','30','30','30','30','53','4D','41','52','54','50',','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'是否存在,但是我还没有。你知道吗

感谢代码帮助!你知道吗


Tags: 代码self元素closedatareturnifaddress
1条回答
网友
1楼 · 发布于 2024-09-29 18:43:17
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)

相关问题 更多 >

    热门问题