0

I read some RFID Tags with <STX>RFID String<EOT>

how can i use read_until with this EOT character. I tried this:

serResponse = self.ser.read_until(chr(4))

didn't work, I got the string after a timeout

[EDIT]

while True:
    for c in ser.read():
        line.append(c)
        if c == '\n':
            print("Line: " + ''.join(line))
            line = []
            break

how can I change the '\n' to check for EOT or STX char.

that the print(c) output of one tag: 2 82 51 48 52 50 70 65 50 49 65 49 4

I thought I can check for c=='4' or c==4, but it didn't work.

bluelemonade
  • 1,115
  • 1
  • 14
  • 26
  • Perhaps, [this answer](https://stackoverflow.com/questions/16470903/pyserial-2-6-specify-end-of-line-in-readline) may help you – Mauro Baraldi Jan 23 '19 at 18:12
  • hmm, please have a look after the EDIT in my question. the point is not to use \r, that's nw problem, I have to check for STX or EOT Ascii char. – bluelemonade Jan 23 '19 at 18:19
  • Assuming that `c` is a byte string you can do a byte string comparison; `EOT` is `b'\x04'` and `STX` is `b'\x02'`. http://www.asciitable.com – Oluwafemi Sule Jan 23 '19 at 18:36

1 Answers1

1

that snippet workd for me, eol as bytearray and then read one by one into a bytearray and check if the last byte is the eol

eol = bytearray([4])
    leneol = len(eol)
    line = bytearray()
    while True:
         c = self.ser.read(1)
          if c:
              line += c
              if line[-leneol:] == eol:
                  break
          else:
              break
bluelemonade
  • 1,115
  • 1
  • 14
  • 26