slotUI/freeslot.py

changeset 27
3e617fcf999a
parent 26
4af697fa5ea9
child 35
00166228a419
equal deleted inserted replaced
26:4af697fa5ea9 27:3e617fcf999a
1 """ 1 """
2 FreeSlot project 2 FreeSlot project
3 Blackbox communication library 3 Blackbox communication library
4 """ 4 """
5 5
6 from serial import Serial 6 import serial
7 import sys
7 8
8 class SerialCommunicator(): 9 class SerialCommunicator():
9 def __init__(self, device, speed): 10 def __init__(self, device, speed):
10 self.device = device 11 self.device = device
11 self.speed = speed 12 self.speed = speed
13 self.connected = False 14 self.connected = False
14 15
15 def connect(self): 16 def connect(self):
16 if self.connected: 17 if self.connected:
17 return True 18 return True
18 self.com = Serial(self.device, baudrate=self.speed, xonxoff=0, timeout=1) 19 try:
20 self.com = serial.Serial(self.device, baudrate=self.speed, xonxoff=0, timeout=1)
21 except serial.SerialException, err:
22 print err
23 sys.exit(1)
19 self.connected = True 24 self.connected = True
20 return True 25 return True
21 26
22 def disconnect(self): 27 def disconnect(self):
23 self.com = None 28 self.com = None

mercurial