OLD | NEW |
| (Empty) |
1 # Copyright (c) 2001-2004 Twisted Matrix Laboratories. | |
2 # See LICENSE for details. | |
3 | |
4 | |
5 """ | |
6 Serial Port Protocol | |
7 """ | |
8 | |
9 # system imports | |
10 import os, sys | |
11 | |
12 # all of them require pyserial at the moment, so check that first | |
13 import serial | |
14 from serial import PARITY_NONE, PARITY_EVEN, PARITY_ODD | |
15 from serial import STOPBITS_ONE, STOPBITS_TWO | |
16 from serial import FIVEBITS, SIXBITS, SEVENBITS, EIGHTBITS | |
17 | |
18 # common code for serial ports | |
19 class BaseSerialPort: | |
20 def setBaudRate(self, baudrate): | |
21 if hasattr(self._serial, "setBaudrate"): | |
22 self._serial.setBaudrate(baudrate) | |
23 else: | |
24 self._serial.setBaudRate(baudrate) | |
25 | |
26 def inWaiting(self): | |
27 return self._serial.inWaiting() | |
28 | |
29 def flushInput(self): | |
30 self._serial.flushInput() | |
31 | |
32 def flushOutput(self): | |
33 self._serial.flushOutput() | |
34 | |
35 def sendBreak(self): | |
36 self._serial.sendBreak() | |
37 | |
38 def getDSR(self): | |
39 return self._serial.getDSR() | |
40 | |
41 def getCD(self): | |
42 return self._serial.getCD() | |
43 | |
44 def getRI(self): | |
45 return self._serial.getRI() | |
46 | |
47 def getCTS(self): | |
48 return self._serial.getCTS() | |
49 | |
50 def setDTR(self, on = 1): | |
51 self._serial.setDTR(on) | |
52 | |
53 def setRTS(self, on = 1): | |
54 self._serial.setRTS(on) | |
55 | |
56 class SerialPort(BaseSerialPort): | |
57 pass | |
58 | |
59 # replace SerialPort with appropriate serial port | |
60 if os.name == 'posix': | |
61 from twisted.internet._posixserialport import SerialPort | |
62 elif os.name == 'java': | |
63 from twisted.internet._javaserialport import SerialPort | |
64 elif sys.platform == 'win32': | |
65 from twisted.internet._win32serialport import SerialPort | |
OLD | NEW |