15 # serialize access lock |
15 # serialize access lock |
16 self.TransactionLock = Lock() |
16 self.TransactionLock = Lock() |
17 # open serial port |
17 # open serial port |
18 # self.serialPort = serial.Serial( port, rate, timeout = timeout ) |
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 ) |
20 self.serialPort = serial.Serial( port, rate, timeout = timeout ) |
21 class myser: |
21 # class myser: |
22 def read(self_,cnt): |
22 # def read(self_,cnt): |
23 res = self._serialPort.read(cnt) |
23 # res = self._serialPort.read(cnt) |
24 if len(res) > 16: |
24 # if len(res) > 16: |
25 print "Recv :", map(hex,map(ord,res[:16])), "[...]" |
25 # print "Recv :", map(hex,map(ord,res[:16])), "[...]" |
26 else: |
26 # else: |
27 print "Recv :", map(hex,map(ord,res)) |
27 # print "Recv :", map(hex,map(ord,res)) |
28 |
28 # |
29 return res |
29 # return res |
30 def write(self_, str): |
30 # def write(self_, str): |
31 if len(str) > 16: |
31 # if len(str) > 16: |
32 print "Send :", map(hex,map(ord,str[:16])), "[...]" |
32 # print "Send :", map(hex,map(ord,str[:16])), "[...]" |
33 else: |
33 # else: |
34 print "Send :", map(hex,map(ord,str)) |
34 # print "Send :", map(hex,map(ord,str)) |
35 self._serialPort.write(str) |
35 # self._serialPort.write(str) |
36 def flush(self_): |
36 # def flush(self_): |
37 self._serialPort.flush() |
37 # self._serialPort.flush() |
38 self.serialPort = myser() |
38 # self.serialPort = myser() |
39 # start with empty |
39 # start with empty |
40 self.serialPort.flush() |
40 self.serialPort.flush() |
41 |
41 |
|
42 def __del__(self): |
|
43 if self.serialPort: |
|
44 self.serialPort.close() |
|
45 |
|
46 def close(self): |
|
47 self.serialPort.close() |
|
48 self.serialPort = None |