Changeset 3543 for pykocard

Show
Ignore:
Timestamp:
04/27/10 10:13:55 (15 years ago)
Author:
jerome
Message:

Doesn't waste anymore the reading of one character at device opening
time. Activates debug mode in the testing program.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykocard/trunk/pykocard/cartadistcrs.py

    r3542 r3543  
    7171 
    7272        self.lastcommand = None 
     73        self.shortprompt = '$' 
    7374        self.sol = chr(13) + chr(10) # start of line (begins each answer) 
    7475        self.sollen = len(self.sol) 
    75         self.prompt = chr(13) + chr(10) + '$' # the prompt 
     76        self.prompt = chr(13) + chr(10) + self.shortprompt # the prompt 
    7677        self.promptlen = len(self.prompt) 
    7778        self.eoc = chr(13) # end of command 
     
    99100            self.tcrs.flushInput() 
    100101            self.tcrs.flushOutput() 
    101             self.tcrs.read(1) # Skips the first $ prompt 
    102102        except serial.serialutil.SerialException, msg : 
    103103            self.logError(msg) 
     
    152152            answer = self.tcrs.readline(eol=self.prompt) 
    153153            self.logDebug("TCRS answered %s" % repr(answer)) 
     154            if answer.startswith(self.shortprompt) : 
     155                answer = answer[len(self.shortprompt):] 
    154156            if answer.startswith(command) : 
    155157                answer = answer[len(command):] 
     
    157159                return answer[self.sollen:-self.promptlen] 
    158160            else : 
    159                 if answer != self.sol : 
     161                if answer and (answer != self.sol) : 
    160162                    self.logError("Unknown answer %s" % repr(answer)) 
    161163                return None 
     
    282284if __name__ == "__main__" : 
    283285    # Minimal testing 
    284     tcrs = CartadisTCRS("/dev/ttyS0", debug=False) 
     286    tcrs = CartadisTCRS("/dev/ttyS0", debug=True) 
    285287    try : 
    286288        sys.stdout.write("%s TCRS detected on device %s with serial number %s\n" \