0

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...

4
  • 1
    Any reason not to do what you're doing? Noticeable slowdown? May 2, 2012 at 18:31
  • i have almost 26 request and response so if i do with this method think for adding any new request and response it ll be little hectic also expect this method will slow down...
    – Ragav
    May 2, 2012 at 18:35
  • 1
    FYI The title of this question is entirely irrelevant to what you're really asking.
    – dkamins
    May 2, 2012 at 18:38
  • @dkamins i just have set of req and responses in hex string and i jus wanna compare the request and sens respective response..so wanna to it with optimised way,,
    – Ragav
    May 2, 2012 at 18:50

1 Answer 1

2

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()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.