12 |
13 |
13 class LPCProto: |
14 class LPCProto: |
14 def __init__(self, port, rate, timeout): |
15 def __init__(self, port, rate, timeout): |
15 # serialize access lock |
16 # serialize access lock |
16 self.TransactionLock = Lock() |
17 self.TransactionLock = Lock() |
17 # open serial port |
18 if BMZ_DBG: |
18 # self.serialPort = serial.Serial( port, rate, timeout = timeout ) |
19 # Debugging serial stuff |
19 # Debugging serial stuff |
20 self._serialPort = serial.Serial( port, rate, timeout = timeout, writeTimeout = timeout ) |
20 self.serialPort = serial.Serial( port, rate, timeout = timeout ) |
21 class myser: |
21 # class myser: |
22 def readline(self_): |
22 # def read(self_,cnt): |
23 res = self._serialPort.readline() |
23 # res = self._serialPort.read(cnt) |
24 print 'Recv :"', res, '"' |
24 # if len(res) > 16: |
25 return res |
25 # print "Recv :", map(hex,map(ord,res[:16])), "[...]" |
26 |
26 # else: |
27 def read(self_,cnt): |
27 # print "Recv :", map(hex,map(ord,res)) |
28 res = self._serialPort.read(cnt) |
28 # |
29 if len(res) > 16: |
29 # return res |
30 print "Recv :", map(hex,map(ord,res[:16])), "[...]" |
30 # def write(self_, str): |
31 else: |
31 # if len(str) > 16: |
32 print "Recv :", map(hex,map(ord,res)) |
32 # print "Send :", map(hex,map(ord,str[:16])), "[...]" |
33 |
33 # else: |
34 return res |
34 # print "Send :", map(hex,map(ord,str)) |
35 def write(self_, string): |
35 # self._serialPort.write(str) |
36 lstr=len(string) |
36 # def flush(self_): |
37 if lstr > 16: |
37 # self._serialPort.flush() |
38 print "Send :", map(hex,map(ord,string[:16])), "[...]" |
38 # self.serialPort = myser() |
39 else: |
39 # start with empty |
40 print "Send :", map(hex,map(ord,string)) |
|
41 return self._serialPort.write(string) |
|
42 # while len(string)>0: |
|
43 # i = self._serialPort.write(string[:4096]) |
|
44 # print ".", |
|
45 # string = string[i:] |
|
46 # print |
|
47 #return lstr |
|
48 def flush(self_): |
|
49 return self._serialPort.flush() |
|
50 def close(self_): |
|
51 self._serialPort.close() |
|
52 self.serialPort = myser() |
|
53 else: |
|
54 # open serial port |
|
55 self.serialPort = serial.Serial( port, rate, timeout = timeout ) |
|
56 # start with empty buffer |
40 self.serialPort.flush() |
57 self.serialPort.flush() |
41 |
58 |
42 def __del__(self): |
59 def __del__(self): |
43 if self.serialPort: |
60 if self.serialPort: |
44 self.serialPort.close() |
61 self.serialPort.close() |