本文整理匯總了Python中termios.CSTOPB屬性的典型用法代碼示例。如果您正苦於以下問題:Python termios.CSTOPB屬性的具體用法?Python termios.CSTOPB怎麽用?Python termios.CSTOPB使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類termios
的用法示例。
在下文中一共展示了termios.CSTOPB屬性的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _set_stopbits
# 需要導入模塊: import termios [as 別名]
# 或者: from termios import CSTOPB [as 別名]
def _set_stopbits(self, stopbits):
if not isinstance(stopbits, int):
raise TypeError("Invalid stop bits type, should be integer.")
elif stopbits not in [1, 2]:
raise ValueError("Invalid stop bits, can be 1, 2.")
# Get tty attributes
try:
(iflag, oflag, cflag, lflag, ispeed, ospeed, cc) = termios.tcgetattr(self._fd)
except termios.error as e:
raise SerialError(e.errno, "Getting serial port attributes: " + e.strerror)
# Modify tty attributes
cflag &= ~termios.CSTOPB
if stopbits == 2:
cflag |= termios.CSTOPB
# Set tty attributes
try:
termios.tcsetattr(self._fd, termios.TCSANOW, [iflag, oflag, cflag, lflag, ispeed, ospeed, cc])
except termios.error as e:
raise SerialError(e.errno, "Setting serial port attributes: " + e.strerror)
示例2: __init__
# 需要導入模塊: import termios [as 別名]
# 或者: from termios import CSTOPB [as 別名]
def __init__(self, device="/dev/ttyAMA0", baudrate=9600):
if not device.startswith("/dev/"):
device = "/dev/%s" % device
if isinstance(baudrate, str):
baudrate = int(baudrate)
aname = "B%d" % baudrate
if not hasattr(termios, aname):
raise Exception("Unsupported baudrate")
self.baudrate = baudrate
Bus.__init__(self, "UART", device, os.O_RDWR | os.O_NOCTTY)
fcntl.fcntl(self.fd, fcntl.F_SETFL, os.O_NDELAY)
#backup = termios.tcgetattr(self.fd)
options = termios.tcgetattr(self.fd)
# iflag
options[0] = 0
# oflag
options[1] = 0
# cflag
options[2] |= (termios.CLOCAL | termios.CREAD)
options[2] &= ~termios.PARENB
options[2] &= ~termios.CSTOPB
options[2] &= ~termios.CSIZE
options[2] |= termios.CS8
# lflag
options[3] = 0
speed = getattr(termios, aname)
# input speed
options[4] = speed
# output speed
options[5] = speed
termios.tcsetattr(self.fd, termios.TCSADRAIN, options)
示例3: _get_stopbits
# 需要導入模塊: import termios [as 別名]
# 或者: from termios import CSTOPB [as 別名]
def _get_stopbits(self):
# Get tty attributes
try:
(_, _, cflag, _, _, _, _) = termios.tcgetattr(self._fd)
except termios.error as e:
raise SerialError(e.errno, "Getting serial port attributes: " + e.strerror)
if (cflag & termios.CSTOPB) != 0:
return 2
else:
return 1