本文整理汇总了Python中serial.EIGHTBITS属性的典型用法代码示例。如果您正苦于以下问题:Python serial.EIGHTBITS属性的具体用法?Python serial.EIGHTBITS怎么用?Python serial.EIGHTBITS使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类serial
的用法示例。
在下文中一共展示了serial.EIGHTBITS属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: open
# 需要导入模块: import serial [as 别名]
# 或者: from serial import EIGHTBITS [as 别名]
def open(self, port, speed=Constants.serial_default_speed, timeout=Constants.serial_timeout_ms):
"""
Opens a specified serial port.
:param port: Serial port name.
:type port: str.
:param speed: Baud rate, in bps, to connect to port.
:type speed: int.
:param timeout: Sets the general connection timeout.
:type timeout: float.
:return: True if the port is available.
:rtype: bool.
"""
self._serial.port = port
self._serial.baudrate = int(speed)
self._serial.stopbits = serial.STOPBITS_ONE
self._serial.bytesize = serial.EIGHTBITS
self._serial.timeout = timeout
return self._is_port_available(self._serial.port)
示例2: test_serialPortDefaultArgs
# 需要导入模块: import serial [as 别名]
# 或者: from serial import EIGHTBITS [as 别名]
def test_serialPortDefaultArgs(self):
"""
Test correct positional and keyword arguments have been
passed to the C{serial.Serial} object.
"""
port = RegularFileSerialPort(self.protocol, self.path, self.reactor)
# Validate args
self.assertEqual((self.path,), port._serial.captured_args)
# Validate kwargs
kwargs = port._serial.captured_kwargs
self.assertEqual(9600, kwargs["baudrate"])
self.assertEqual(serial.EIGHTBITS, kwargs["bytesize"])
self.assertEqual(serial.PARITY_NONE, kwargs["parity"])
self.assertEqual(serial.STOPBITS_ONE, kwargs["stopbits"])
self.assertEqual(0, kwargs["xonxoff"])
self.assertEqual(0, kwargs["rtscts"])
self.assertEqual(None, kwargs["timeout"])
port.connectionLost(Failure(Exception("Cleanup")))
示例3: getCoord
# 需要导入模块: import serial [as 别名]
# 或者: from serial import EIGHTBITS [as 别名]
def getCoord():
# Start the serial connection
ser=serial.Serial('/dev/ttyAMA0', 115200, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, timeout=1)
ser.write("AT+CGNSINF\r")
while True:
response = ser.readline()
if "+CGNSINF: 1," in response:
# Split the reading by commas and return the parts referencing lat and long
array = response.split(",")
lat = array[3]
print lat
lon = array[4]
print lon
return (lat,lon)
# Start the program by opening the cellular connection and creating a bucket for our data
示例4: setup_serial
# 需要导入模块: import serial [as 别名]
# 或者: from serial import EIGHTBITS [as 别名]
def setup_serial(ser, port, lock):
"""Setup all parameters for the serial communication"""
try:
with lock:
ser.baudrate = 4800
ser.port = port
ser.bytesize = serial.EIGHTBITS
ser.stopbits = serial.STOPBITS_ONE
ser.parity = serial.PARITY_NONE
ser.timeout = 0.1 # Read timeout in seconds
ser.write_timeout = 0.1 # Write timeout in seconds
except Exception as e:
helper.show_error("Problem initializing serial port " + port + ".\n\n"
"Exception:\n" + str(e) + "\n\n"
"The application will now exit.")
sys.exit(0)
示例5: initializeUartPort
# 需要导入模块: import serial [as 别名]
# 或者: from serial import EIGHTBITS [as 别名]
def initializeUartPort(
portName,
baudrate = 57600,
bytesize = serial.EIGHTBITS,
parity = serial.PARITY_NONE,
stopbits = serial.STOPBITS_ONE,
timeout = 0
):
port = serial.Serial()
#tuning port object
port.port = portName
port.baudrate = baudrate
port.bytesize = bytesize
port.parity = parity
port.stopbits = stopbits
port.timeout = timeout
return port
示例6: modbus_send_serial
# 需要导入模块: import serial [as 别名]
# 或者: from serial import EIGHTBITS [as 别名]
def modbus_send_serial(data, properties):
modbus_data = pickle.dumps(data)
data_length = len(modbus_data)
encoded_data = base64.b64encode(modbus_data)
data_size = sys.getsizeof(encoded_data)
log.debug('Data size : %s' % data_size)
ser = serial.Serial(
port='/dev/ttyAMA0',
baudrate = 57600,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=0.5
)
ser.write(encoded_data)
log.debug(encoded_data)
示例7: __init__
# 需要导入模块: import serial [as 别名]
# 或者: from serial import EIGHTBITS [as 别名]
def __init__(self, port, verbose=False):
threading.Thread.__init__(self)
self._on = True
self.verbose = verbose
self.lock = threading.Lock()
self.ser = serial.Serial(port,
baudrate=115200,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS)
is_open = self.ser.isOpen()
if self.verbose:
print('pydobot: %s open' % self.ser.name if is_open else 'failed to open serial port')
self._set_queued_cmd_start_exec()
self._set_queued_cmd_clear()
self._set_ptp_joint_params(200, 200, 200, 200, 200, 200, 200, 200)
self._set_ptp_coordinate_params(velocity=200, acceleration=200)
self._set_ptp_jump_params(10, 200)
self._set_ptp_common_params(velocity=100, acceleration=100)
self._get_pose()
示例8: __init__
# 需要导入模块: import serial [as 别名]
# 或者: from serial import EIGHTBITS [as 别名]
def __init__(self, protocol, deviceNameOrPortNumber, reactor,
baudrate = 9600, bytesize = EIGHTBITS, parity = PARITY_NONE,
stopbits = STOPBITS_ONE, timeout = 3, xonxoff = 0, rtscts = 0):
# do NOT use timeout = 0 !!
self._serial = serial.Serial(deviceNameOrPortNumber, baudrate = baudrate, bytesize = bytesize, parity = parity, stopbits = stopbits, timeout = timeout, xonxoff = xonxoff, rtscts = rtscts)
javareactor.JConnection.__init__(self, self._serial.sPort, protocol, None)
self.flushInput()
self.flushOutput()
self.reactor = reactor
self.protocol = protocol
self.protocol.makeConnection(self)
wb = javareactor.WriteBlocker(self, reactor.q)
wb.start()
self.writeBlocker = wb
javareactor.ReadBlocker(self, reactor.q).start()
示例9: __init__
# 需要导入模块: import serial [as 别名]
# 或者: from serial import EIGHTBITS [as 别名]
def __init__(self, portnum=None, useByteQueue=False):
self.ser = None
try:
self.ser = serial.Serial(
port=portnum,
baudrate=460800,
bytesize=serial.EIGHTBITS,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
timeout=None, # seconds
writeTimeout=None,
rtscts=True
)
except Exception as e:
if self.ser:
self.ser.close()
raise
self.useByteQueue = useByteQueue
self.byteQueue = collections.deque()
# if self.ser.name != None:
# print "UART %s on port %s" % ("open" if self.ser else "closed", self.ser.name)
示例10: SetSamBA
# 需要导入模块: import serial [as 别名]
# 或者: from serial import EIGHTBITS [as 别名]
def SetSamBA(DueSerialPort):
"""
Initial triggering of chip into SAM-BA mode.
On the Programming Port there is an ATMEGA16U2 chip, acting as a USB bridge to expose the SAM UART as USB.
If the host is connected to the programming port at baud rate 1200, the ATMEGA16U2 will assert the Erase pin and Reset pin of the SAM3X, forcing it to the SAM-BA bootloader mode.
The port remains the same number but to access SAM-BA Baud rate must be changed to 115200.
"""
log.Log("Setting into SAM-BA..." + DueSerialPort)
ser = serial.Serial(port=DueSerialPort,\
baudrate=1200,\
parity=serial.PARITY_NONE,\
stopbits=serial.STOPBITS_ONE,\
bytesize=serial.EIGHTBITS,\
timeout=2000)
ser.write("\n")
time.sleep(3)
ser.close()
log.Log("SAM-BA Set.")
示例11: Checks
# 需要导入模块: import serial [as 别名]
# 或者: from serial import EIGHTBITS [as 别名]
def Checks(Port, SketchFile):
""" Does basic checks that sketch file exists and port is connected."""
if not os.path.isfile(SketchFile):
log.Log("Sketch File Does Not Exist: " + SketchFile)
sys.exit()
try:
ser = serial.Serial(port=Port,\
baudrate=1200,\
parity=serial.PARITY_NONE,\
stopbits=serial.STOPBITS_ONE,\
bytesize=serial.EIGHTBITS,\
timeout=2000)
except serial.SerialException:
log.Log("Problem with selected Port. Double check it is correct.")
sys.exit()
except Exception:
raise Exception("Unexpected excetion in Checks(): " + traceback.format_exc())
示例12: SetSamBA
# 需要导入模块: import serial [as 别名]
# 或者: from serial import EIGHTBITS [as 别名]
def SetSamBA():
"""
Initial triggering of chip into SAM-BA mode.
On the Programming Port there is an ATMEGA16U2 chip, acting as a USB bridge to expose the SAM UART as USB.
If the host is connected to the programming port at baud rate 1200, the ATMEGA16U2 will assert the Erase pin and Reset pin of the SAM3X, forcing it to the SAM-BA bootloader mode.
The port remains the same number but to access SAM-BA Baud rate must be changed to 115200.
"""
log.Log("Setting into SAM-BA...")
ser = serial.Serial(port=ArduinoFlashHardValues.arduinoPort,\
baudrate=1200,\
parity=serial.PARITY_NONE,\
stopbits=serial.STOPBITS_ONE,\
bytesize=serial.EIGHTBITS,\
timeout=2000)
time.sleep(10)
ser.close()
log.Log("SAM-BA Set.")
示例13: _port_open
# 需要导入模块: import serial [as 别名]
# 或者: from serial import EIGHTBITS [as 别名]
def _port_open(self, port):
if self._port: # port is already open
return True
prt = serial.Serial()
prt.port = port
prt.baudrate = 115200
prt.bytesize = serial.EIGHTBITS # number of bits per bytes
prt.parity = serial.PARITY_NONE # set parity check: no parity
prt.stopbits = serial.STOPBITS_ONE # number of stop bits
prt.timeout = .001 # non-block read
prt.writeTimeout = None # timeout for write
try:
prt.open()
self._port = prt
return True
except Exception as ex:
return False
示例14: getCoord
# 需要导入模块: import serial [as 别名]
# 或者: from serial import EIGHTBITS [as 别名]
def getCoord():
# Start the serial connection
ser=serial.Serial('/dev/serial0', 115200, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, timeout=1)
ser.write("AT+CGNSINF\r")
while True:
response = ser.readline()
if "+CGNSINF: 1," in response:
# Split the reading by commas and return the parts referencing lat and long
array = response.split(",")
lat = array[3]
print lat
lon = array[4]
print lon
return (lat,lon)
# Start the program by opening the cellular connection and creating a bucket for our data
示例15: __connect_to_devices
# 需要导入模块: import serial [as 别名]
# 或者: from serial import EIGHTBITS [as 别名]
def __connect_to_devices(self): # Function for opening connection and connecting to devices
for device in self.__devices:
try: # Start error handler
connection_start = time.time()
if self.__devices[device].get("serial") is None \
or self.__devices[device]["serial"] is None \
or not self.__devices[device]["serial"].isOpen(): # Connect only if serial not available earlier or it is closed.
self.__devices[device]["serial"] = None
while self.__devices[device]["serial"] is None or not self.__devices[device]["serial"].isOpen(): # Try connect
# connection to serial port with parameters from configuration file or default
self.__devices[device]["serial"] = serial.Serial(port=self.__config.get('port', '/dev/ttyUSB0'),
baudrate=self.__config.get('baudrate', 9600),
bytesize=self.__config.get('bytesize', serial.EIGHTBITS),
parity=self.__config.get('parity', serial.PARITY_NONE),
stopbits=self.__config.get('stopbits', serial.STOPBITS_ONE),
timeout=self.__config.get('timeout', 1),
xonxoff=self.__config.get('xonxoff', False),
rtscts=self.__config.get('rtscts', False),
write_timeout=self.__config.get('write_timeout', None),
dsrdtr=self.__config.get('dsrdtr', False),
inter_byte_timeout=self.__config.get('inter_byte_timeout', None),
exclusive=self.__config.get('exclusive', None))
time.sleep(.1)
if time.time() - connection_start > 10: # Break connection try if it setting up for 10 seconds
log.error("Connection refused per timeout for device %s", self.__devices[device]["device_config"].get("name"))
break
except serial.serialutil.SerialException:
log.error("Port %s for device %s - not found", self.__config.get('port', '/dev/ttyUSB0'), device)
except Exception as e:
log.exception(e)
else: # if no exception handled - add device and change connection state
self.__gateway.add_device(self.__devices[device]["device_config"]["name"], {"connector": self}, self.__devices[device]["device_config"]["type"])
self.__connected = True