def getSource(comm):
source = comm.split('@')
params = source[1].split(':')
+ debug = '--debug' in sys.argv
if source[0] == 'serial':
try:
- return Serial(params[0], int(params[1]), flush=True, debug=('--debug' in sys.argv))
+ return Serial(params[0], int(params[1]), flush=True, debug=debug)
except:
print "ERROR: Unable to initialize a serial connection to", comm
raise Exception
elif source[0] == 'network':
try:
- return SerialMIB600(params[0], int(params[1]), debug=False)
+ return SerialMIB600(params[0], int(params[1]), debug=debug)
except:
print "ERROR: Unable to initialize a network connection to", comm
print "ERROR:", traceback.format_exc()
#print "DEBUG: putBytes:", data
for b in data:
self._s.write(struct.pack('B', b))
+ time.sleep(0.000001)
def getTimeout(self):
return self._s.timeout
self._s.timeout = timeout
class SerialMIB600:
- def __init__(self, host, port=10002, debug=False, readTimeout=None, ackTimeout=0.05):
+ def __init__(self, host, port=10002, debug=False, readTimeout=None, ackTimeout=0.5):
self.debug = debug
self.readTimeout = readTimeout
self.ackTimeout = ackTimeout
def write(self, packet, amId, timeout=5, blocking=True, inc=1):
self.seqno = (self.seqno + inc) % 256
prevTimeout = self._source.getTimeout()
+ ack = None
end = None
if timeout: end = time.time() + timeout
while not end or time.time() < end:
break
self._source.setTimeout(prevTimeout)
#print 'SimpleAM:write: got an ack:', ack, ack.seqno == self.seqno
- return ack.seqno == self.seqno
+ return (ack != None and ack.seqno == self.seqno)
def setOobHook(self, oobHook):
self.oobHook = oobHook
s = "".join([chr(i) for i in packet.data]).strip('\0')
lines = s.split('\n')
for line in lines:
- print "PRINTF:", line
+ if line: print "PRINTF:", line
packet = None # No further processing for the printf packet
return packet
return self._names
def values(self):
- return self._names
+ return self._values
# Custom functions
def names(self):