Fri, 02 Dec 2011 23:08:34 +0100
started communication class and CLI
23 | 1 | """ |
2 | FreeSlot project | |
3 | Blackbox communication library | |
4 | """ | |
5 | ||
25
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
6 | class SerialCommunicator(): |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
7 | def __init__(self, device, speed): |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
8 | self.device = device |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
9 | self.speed = speed |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
10 | self.port = None |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
11 | self.connected = False |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
12 | |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
13 | def connect(self): |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
14 | if self.connected: |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
15 | return True |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
16 | |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
17 | def disconnect(self): |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
18 | return True |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
19 | |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
20 | def write(self): |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
21 | return True |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
22 | |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
23 | def read(self): |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
24 | return True |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
25 | |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
26 | class Blackbox(): |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
27 | def __init__(self): |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
28 | self.com = None |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
29 | self.info = None |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
30 | |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
31 | def connect(self, device="/dev/ttyUSB0", speed=115200): |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
32 | if self.com == None: |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
33 | self.com = SerialCommunicator(device, speed) |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
34 | self.com.connect() |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
35 | self.info = self.readinfo() |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
36 | |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
37 | def disconnect(): |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
38 | self.com.disconnect() |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
39 | |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
40 | def readinfo(): |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
41 | """ |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
42 | Read complete Information from connected box |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
43 | """ |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
44 | return None |