How to use the pyserial.Serial function in pyserial

To help you get started, we’ve selected a few pyserial examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github 602p / serpint / bin / monitor.py View on Github external
fd = sys.stdin.fileno()
        old_settings = termios.tcgetattr(fd)
        try:
            tty.setraw(sys.stdin.fileno())
            ch = sys.stdin.read(1)
        finally:
            termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
        return ch

import pyserial as serial
import time, sys, os

print "Welcome to the SERPINT test program."
print "This program expects that you have followed the instructions in doc/demo.odt"
port_name=raw_input("What serial port did you use during setup? [i.e. /dev/ttyS44] ")
port=serial.Serial(port_name)
port.write(chr(2))
while 1:
	if ord(port.read())!=1: break
port.write(chr(30))
if ord(port.read())!=10:
	print "ERROR!"
	sys.exit()

#----------------------------------------------------------------------------------------#

getch=_GetchUnix()
print "\n\nPress  to toggle the power on GPIO pin 4 [http://elinux.org/images/2/2a/GPIOs.png] and q to quit [close all SERPINT components]"
state=False
port.write(chr(22))
port.write(chr(7))
port.write(chr(26))
github 602p / serpint / bin / main.py View on Github external
def serial_to_socket(ser_addr, port): #forward data from a virtual serial port to a socket, I would use remserial, but it only works with proper (non-virtual) serial ports
	try:
		ser=serial.Serial("/dev/"+ser_addr) #open the serial port
		ser.open()
		sock=socket.socket(socket.AF_INET, socket.SOCK_STREAM) #open and bind the socket
		sock.bind(("", port))
		sock.listen(1)
		print "Waiting for remote connection to socket..." #wait for the other machine to run SOCKTOSERIAL
		conn, addr=sock.accept()
		print "Got connection!"
	except BaseException as e:
		throw_error(7,e) #error initilizing
	thread.start_new_thread(ser_to_sock_a, (ser, conn)) #start thread a (forwarding from serial to socket)
	time.sleep(0.1) #slight delay to keep the serial port psuedo-threadsafe
	thread.start_new_thread(ser_to_sock_b, (ser, conn)) #start thread b (forwarding from socket to serial)
	while 1:pass #keep running, as not to close the process with still-running threads
github 602p / serpint / bin / serpint.py View on Github external
def serial_to_socket(ser_addr, port): #forward data from a virtual serial port to a socket, I would use remserial, but it only works with proper (non-virtual) serial ports
	try:
		ser=serial.Serial("/dev/"+ser_addr) #open the serial port
		ser.open()
		sock=socket.socket(socket.AF_INET, socket.SOCK_STREAM) #open and bind the socket
		sock.bind(("", port))
		sock.listen(1)
		print "Waiting for remote connection to socket..." #wait for the other machine to run SOCKTOSERIAL
		conn, addr=sock.accept()
		print "Got connection!"
	except BaseException as e:
		throw_error(7,e) #error initilizing
	thread.start_new_thread(ser_to_sock_a, (ser, conn)) #start thread a (forwarding from serial to socket)
	time.sleep(0.1) #slight delay to keep the serial port psuedo-threadsafe
	thread.start_new_thread(ser_to_sock_b, (ser, conn)) #start thread b (forwarding from socket to serial)
	while 1:pass #keep running, as not to close the process with still-running threads
github 602p / serpint / bin / main.py View on Github external
def serial_format_bridge_passable(port, ser_addr, ser_addr2): #A passable function object that is passed to the SFB child module, and then executed, creating the sock and ser objects
	try:
		ser=serial.Serial("/dev/"+ser_addr) #Open serial port
		ser.open()
		sock=socket.socket(socket.AF_INET, socket.SOCK_STREAM)#Open socket
		sock.bind(("", port))
		sock.listen(1)
		print "Waiting for remote connection to socket..."
		thread.start_new_thread(vsi_system_sock, (ser_addr2,'localhost',port)) #Start the system socket
		conn, addr=sock.accept()#Meanwhile, wait for the system socket to become live
		print "Got connection!"
		print "Opening Phase 2 Port..."
		return conn, ser
	except BaseException as e:
		throw_error(7,e)
github gepd / uPiotMicroPythonTool / tools / esptool.py View on Github external
def __init__(self, port=DEFAULT_PORT, baud=ESP_ROM_BAUD, trace_enabled=False):
        """Base constructor for ESPLoader bootloader interaction

        Don't call this constructor, either instantiate ESP8266ROM
        or ESP32ROM, or use ESPLoader.detect_chip().

        This base class has all of the instance methods for bootloader
        functionality supported across various chips & stub
        loaders. Subclasses replace the functions they don't support
        with ones which throw NotImplementedInROMError().

        """
        if isinstance(port, serial.Serial):
            self._port = port
        else:
            self._port = serial.serial_for_url(port)
        self._slip_reader = slip_reader(self._port, self.trace)
        # setting baud rate in a separate step is a workaround for
        # CH341 driver on some Linux versions (this opens at 9600 then
        # sets), shouldn't matter for other platforms/drivers. See
        # https://github.com/espressif/esptool/issues/44#issuecomment-107094446
        self._set_port_baudrate(baud)
        self._trace_enabled = trace_enabled
github 602p / serpint / bin / serpint.py View on Github external
def serial_format_bridge_passable(port, ser_addr, ser_addr2): #A passable function object that is passed to the SFB child module, and then executed, creating the sock and ser objects
	try:
		ser=serial.Serial("/dev/"+ser_addr) #Open serial port
		ser.open()
		sock=socket.socket(socket.AF_INET, socket.SOCK_STREAM)#Open socket
		sock.bind(("", port))
		sock.listen(1)
		print "Waiting for remote connection to socket..."
		thread.start_new_thread(vsi_system_sock, (ser_addr2,'localhost',port)) #Start the system socket
		conn, addr=sock.accept()#Meanwhile, wait for the system socket to become live
		print "Got connection!"
		print "Opening Phase 2 Port..."
		return conn, ser
	except BaseException as e:
		throw_error(7,e)

pyserial

Python Serial Port Extension

BSD-2-Clause
Latest version published 4 years ago

Package Health Score

76 / 100
Full package analysis

Popular pyserial functions