root/trunk/twisted/internet/serialport.py

Revision 28995, 1.9 KB (checked in by cyli, 3 months ago)

Merge jython-platformdetection-remove-3725-2: removing jython platform detection

Author: cyli
Reviewer: jesstess, thijs, glyph, exarkun
Fixes: #3725

twisted.python.threadpool.ThreadSafeList is deprecated and Jython platform detection in Twisted core removed

Line 
1# Copyright (c) 2001-2010 Twisted Matrix Laboratories.
2# See LICENSE for details.
3
4
5"""
6Serial Port Protocol
7"""
8
9# http://twistedmatrix.com/trac/ticket/3725#comment:24
10# Apparently applications use these names even though they should
11# be imported from pyserial
12__all__ = ["serial", "PARITY_ODD", "PARITY_EVEN", "PARITY_NONE",
13           "STOPBITS_TWO", "STOPBITS_ONE", "FIVEBITS",
14           "EIGHTBITS", "SEVENBITS", "SIXBITS",
15# Name this module is actually trying to export
16           "SerialPort"]
17
18# system imports
19import os, sys
20
21# all of them require pyserial at the moment, so check that first
22import serial
23from serial import PARITY_NONE, PARITY_EVEN, PARITY_ODD
24from serial import STOPBITS_ONE, STOPBITS_TWO
25from serial import FIVEBITS, SIXBITS, SEVENBITS, EIGHTBITS
26
27# common code for serial ports
28class BaseSerialPort:
29    def setBaudRate(self, baudrate):
30        if hasattr(self._serial, "setBaudrate"):
31            self._serial.setBaudrate(baudrate)
32        else:
33            self._serial.setBaudRate(baudrate)
34
35    def inWaiting(self):
36        return self._serial.inWaiting()
37
38    def flushInput(self):
39        self._serial.flushInput()
40
41    def flushOutput(self):
42        self._serial.flushOutput()
43
44    def sendBreak(self):
45        self._serial.sendBreak()
46
47    def getDSR(self):
48        return self._serial.getDSR()
49
50    def getCD(self):
51        return self._serial.getCD()
52
53    def getRI(self):
54        return self._serial.getRI()
55
56    def getCTS(self):
57        return self._serial.getCTS()
58
59    def setDTR(self, on = 1):
60        self._serial.setDTR(on)
61
62    def setRTS(self, on = 1):
63        self._serial.setRTS(on)
64
65class SerialPort(BaseSerialPort):
66    pass
67
68# replace SerialPort with appropriate serial port
69if os.name == 'posix':
70    from twisted.internet._posixserialport import SerialPort
71elif sys.platform == 'win32':
72    from twisted.internet._win32serialport import SerialPort
Note: See TracBrowser for help on using the browser.