Ragav
Ragav

Reputation: 962

Best method for (HEX) string comparison

suggest a best and efficient method for this

a = "data read from serial port in HEX"
TX1 = "\x10\x04"
RX1 = "\x10\x04"
TX2 = "\xF2\x00\x04\x43\x30\x40\x32\xED\x45"
RX2 = "\x06\xF2\x00\x13\x50\x30\x40\x30\x30\x31\x31\x31\x30\x31\x31\x30\x30\x30\x30\x30\x30\x30\x30\xAE\xFD"
if tx1 in a:
    send.ser(rx1)
    read_buufer()
if tx2 in a:
    send.ser(rx2)
    read_buf()

so what is the best way to do this comparison....jus wanna verify the hex data received from serial buffer (a) and verify with list of available request string tx1,tx2,tx3.....txn and send response to from rx1,rx2,rx2......rxn...

Upvotes: 0

Views: 233

Answers (1)

Andrew Clark
Andrew Clark

Reputation: 208545

One option would be to use a dictionary:

tx_rx = {TX1: RX1, TX2: RX2}
for tx in tx_rx:
    if tx in a:
        send.ser(tx_rx[tx])
        read_buf()

Upvotes: 2

Related Questions