author | Edouqrd Tisserant <edouard.tisserant@gmail.com> |
Thu, 03 Feb 2011 18:23:24 +0100 | |
changeset 570 | 46abd6b2f639 |
parent 563 | c74a37d156df |
child 571 | 427bf9130d12 |
permissions | -rw-r--r-- |
448 | 1 |
import serial |
453 | 2 |
import exceptions |
448 | 3 |
from threading import Lock |
4 |
||
545
627e5c636a4f
Refactored LPC connector for new bootloader and application modes
Lolitech
parents:
536
diff
changeset
|
5 |
class LPCProtoError(exceptions.Exception): |
448 | 6 |
"""Exception class""" |
7 |
def __init__(self, msg): |
|
8 |
self.msg = msg |
|
9 |
||
10 |
def __str__(self): |
|
11 |
return "LPC communication error ! " + str(self.msg) |
|
12 |
||
13 |
class LPCProto: |
|
14 |
def __init__(self, port, rate, timeout): |
|
453 | 15 |
# serialize access lock |
16 |
self.TransactionLock = Lock() |
|
448 | 17 |
# open serial port |
453 | 18 |
# self.serialPort = serial.Serial( port, rate, timeout = timeout ) |
19 |
# Debugging serial stuff |
|
563 | 20 |
self.serialPort = serial.Serial( port, rate, timeout = timeout ) |
21 |
# class myser: |
|
22 |
# def read(self_,cnt): |
|
23 |
# res = self._serialPort.read(cnt) |
|
24 |
# if len(res) > 16: |
|
25 |
# print "Recv :", map(hex,map(ord,res[:16])), "[...]" |
|
26 |
# else: |
|
27 |
# print "Recv :", map(hex,map(ord,res)) |
|
28 |
# |
|
29 |
# return res |
|
30 |
# def write(self_, str): |
|
31 |
# if len(str) > 16: |
|
32 |
# print "Send :", map(hex,map(ord,str[:16])), "[...]" |
|
33 |
# else: |
|
34 |
# print "Send :", map(hex,map(ord,str)) |
|
35 |
# self._serialPort.write(str) |
|
36 |
# def flush(self_): |
|
37 |
# self._serialPort.flush() |
|
38 |
# self.serialPort = myser() |
|
453 | 39 |
# start with empty |
448 | 40 |
self.serialPort.flush() |
41 |
||
563 | 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 |