1

I am trying to find a specific element inside of a long frame which its output is like:

Receive: ['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']

This is a part of my code that I'm trying to modify it:

    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

I need a mechanism to check if in receive frame output, the hex value '53', '4D', '41' exists or not however I have had not yet.

Code help is appreciated!

Avión
  • 7,963
  • 11
  • 64
  • 105
J2015
  • 320
  • 4
  • 24
  • 2
    Possible duplicate of [elegant find sub-list in list](http://stackoverflow.com/questions/10106901/elegant-find-sub-list-in-list) – Andrey Sobolev Feb 24 '16 at 10:31
  • `'53' in list` no good? – Idos Feb 24 '16 at 10:32
  • Do you want to know if they appear in that order ? Or just to know they are in `receive` ? –  Feb 24 '16 at 10:34
  • @Alex I just want to know if in ReceiveFrame function which has a hex output how can I check the value '53', '4D', '41' exists or not. Is there to find a value in a frame in Python. For example ReceiveFrame .FindElement(" '53', '4D', '41' ")..... – J2015 Feb 24 '16 at 10:38
  • A receive isn't random if you know 'what sending' ! What is your code exceptions ? Ex : `losing packet parts`, `error frame`, `checksum(if have)` etc. Change your methods because not good idea ! – dsgdfg Feb 24 '16 at 15:02

1 Answers1

1
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)
John Hua
  • 1,400
  • 9
  • 15