/[anoncvs]/projects/dispense2/sql-edition/servers/SerialClient.py


UCC Code Repository

Contents of /projects/dispense2/sql-edition/servers/SerialClient.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations) (download) (as text)
Sun Jan 27 09:13:20 2013 UTC (8 years, 3 months ago) by root
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +1 -1 lines
File MIME type: text/x-python
[TPG] Increased serial timeout to account for vend time

1 import os, termios
2 from time import sleep
3 import logging
4 from serial import *
5
6 class SerialClientException(Exception): pass
7
8 class SerialClient:
9 def __init__(self, port = '/dev/ttyS1', baud = 9600):
10 self.ser = Serial(
11 port = port,
12 baudrate = baud,
13 bytesize=EIGHTBITS, #number of databits
14 parity=PARITY_NONE, #enable parity checking
15 stopbits=STOPBITS_ONE, #number of stopbits
16 timeout=10, #set a timeout value, None for waiting forever, return on read
17 xonxoff=0, #enable software flow control
18 rtscts=0, #enable RTS/CTS flow control
19 )
20
21
22 self.rfh = self.ser
23 self.wfh = self.ser
24 self.wfh.write('B\n')
25
26 def get_fh(self):
27 return (self.rfh, self.wfh)
28
29 def __del__(self):
30 pass
31
32
33 if __name__ == '__main__':
34 s = SerialClient("/dev/ttyS1", 9600)
35
36 (rfh, wfh) = s.get_fh()
37
38 wfh.write('B\n')
39 print rfh.read()
40
41

Managed by UCC Webmasters ViewVC Help
Powered by ViewVC 1.1.26