- Timestamp:
- Jul 14, 2010, 11:23:43 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
misc/serial-sniffer.py
r146 r147 4 4 # sniffer (DIY schemes avaiable). 5 5 # HOST -> DEVICE at /dev/ttyUSB0 and DEVICE -> HOST at /dev/ttyUSB1 6 # 7 # NOTE: Use Cheap USB-to-Serial devices else you might run into trouble with 8 # 'smart' buffering and/or not clearing properly failing devices for example: 9 # - ID 0557:2008 ATEN International Co., Ltd UC-232A Serial Port [pl2303] 6 10 # 7 11 # $Id$ … … 12 16 import os 13 17 import sys 18 19 DEBUG = False 14 20 15 21 # Stolen from http://snippets.dzone.com/posts/show/7682 … … 41 47 return " ".join(["%02x" % ord(x) for x in s]) 42 48 49 def perror(s): 50 sys.stderr.write("[ERROR] %s\n" % s) 51 52 def pdebug(s): 53 if DEBUG: 54 sys.stderr.write("[DEBUG] %s\n" % s) 55 43 56 def main(): 44 57 while 1: … … 49 62 while send_buffer == "" or recv_buffer == "": 50 63 if send_buffer == "": 64 pdebug("trying to read send_buffer") 51 65 while 1: 52 66 try: 53 with Watchdog( 3):67 with Watchdog(1): 54 68 send_buffer += send.read(1) 55 69 except Watchdog: 56 70 break 57 71 else: 58 sys.stderr.write("#send_buffer filled %s" % str_to_hex(send_buffer))72 pdebug("send_buffer filled %s" % str_to_hex(send_buffer)) 59 73 60 74 if recv_buffer == "": 75 pdebug("trying to read recv_buffer") 61 76 while 1: 62 77 try: … … 66 81 break 67 82 else: 68 sys.stderr.write("#recv_buffer filled %s" % str_to_hex(recv_buffer))83 pdebug("recv_buffer filled %s" % str_to_hex(recv_buffer)) 69 84 70 85 # Try to fetch comment if we have any
Note:
See TracChangeset
for help on using the changeset viewer.