-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebbrick_io.py
More file actions
35 lines (28 loc) · 837 Bytes
/
webbrick_io.py
File metadata and controls
35 lines (28 loc) · 837 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import serial
import logging
_log = logging.getLogger(__name__)
class WebbrickIo(object):
def __init__(self, portname = '/dev/ttyUSB1' ):
self._port = None
self.open(portname)
def open(self, portname):
print "Open", portname
self.port = serial.Serial(
port=portname,
baudrate=9600,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=1
)
print "IsOpen", self.port
# self.port.open()
def close(self):
if self.port.isOpen():
self.port.close()
def write(self,data):
if self.port.isOpen():
self.port.write(data)
def read(self, count):
chs = self.port.read(count)
return chs