VEX EDR Python API
Public Member Functions | List of all members
vex.Serial Class Reference

Public Member Functions

def __init__ (self, port=SerialParam.PORT_HOST, baud_rate=19200, word_length=SerialParam.WORDLEN_8B, stop_bits=SerialParam.STOPBITS_1, parity=SerialParam.PARITY_NO, flow_control=SerialParam.FLOWCONTROL_NONE)
 
def write (self, data, null_terminate_string=True)
 Write the data to the serial port. More...
 
def bytes_to_read (self)
 Get the number of bytes available for reading. More...
 
def read_bytes (self, length=None, stop_byte=None)
 Read the given number of bytes from the port. More...
 
def read_bytes_list (self, length=None, stop_byte=None)
 Read the given number of bytes from the port. More...
 
def read_byte (self)
 Read a single byte from the port. More...
 
def read_string (self)
 Read a null-terminated string from the port. More...
 
def flush_read (self)
 Flush serial input buffer discarding all bytes. More...
 
def log (self, item)
 Log an item to the host using the RM protocol. More...
 

Detailed Description

 **Config** Serial port device (host port, UART1, UART2).
 @param port 0 or for host port, 1 for UART1, 2 for UART2. Default 0 (host port).
 Parameters for UART1/UART2 are
 @param baud_rate baud rate, pass a standard value, e.g. 9600, 19200, 56000.
 @param word_length word length: SerialParam.WORDLEN_[8B|9B]. Default 8B.
 @param stop_bits stop bits: SerialParam.STOPBITS_[1|0_5|2|1_5]. Default 1.
 @param parity parity: SerialParam.PARITY_[NO|ODD|EVEN]. Default NO.
 @param flow_control hardware flow control: SerialParam.FLOWCONTROL_[NONE|RTS|CTS|RTS_CTS]. Default NONE.

Constructor & Destructor Documentation

◆ __init__()

def vex.Serial.__init__ (   self,
  port = SerialParam.PORT_HOST,
  baud_rate = 19200,
  word_length = SerialParam.WORDLEN_8B,
  stop_bits = SerialParam.STOPBITS_1,
  parity = SerialParam.PARITY_NO,
  flow_control = SerialParam.FLOWCONTROL_NONE 
)

Member Function Documentation

◆ write()

def vex.Serial.write (   self,
  data,
  null_terminate_string = True 
)

Write the data to the serial port.

Parameters
databytes to send. Type can be:
  • single int (e.g. 0xFF)
  • list of ints (e.g. [0x01, 0x02, 0x03])
  • bytearray or bytes literal
  • string
null_terminate_stringsend '\0' at the end if data type is string. Default True.

◆ bytes_to_read()

def vex.Serial.bytes_to_read (   self)

Get the number of bytes available for reading.

Returns
number

◆ read_bytes()

def vex.Serial.read_bytes (   self,
  length = None,
  stop_byte = None 
)

Read the given number of bytes from the port.

Blocks until data is available, returns string of bytes.

Parameters
lengthnumber of bytes to read, None for all available.
stop_bytebyte that halts the stream, usually \0 for strings.
Returns
string containing the bytes

◆ read_bytes_list()

def vex.Serial.read_bytes_list (   self,
  length = None,
  stop_byte = None 
)

Read the given number of bytes from the port.

Blocks until data is available, returns list of bytes.

Parameters
lengthnumber of bytes to read, None for all available.
stop_bytebyte that halts the stream, usually \0 for strings.
Returns
list containing the bytes (as numbers)

◆ read_byte()

def vex.Serial.read_byte (   self)

Read a single byte from the port.

Blocks until the byte arrives.

Returns
number [0-255]

◆ read_string()

def vex.Serial.read_string (   self)

Read a null-terminated string from the port.

Blocks until one is available.

Returns
string

◆ flush_read()

def vex.Serial.flush_read (   self)

Flush serial input buffer discarding all bytes.

◆ log()

def vex.Serial.log (   self,
  item 
)

Log an item to the host using the RM protocol.

Only the default host port (0) is supported.

Parameters
itemitem to log (string, tuple or list)