UART
Talk to serial devices connected to an EZB. The hardware UART commands open one of the EZB's serial ports at a speed, write to it and read what has arrived. The send serial commands send bytes or text out of any digital port as software serial, without needing a hardware UART. For the serial ports of the computer itself, use the COM group.
Where to find it: type UART. in a Python script, or open the ARCx API view of the script editor and expand UART
Commands
| Command | What it does |
|---|---|
| UART.HardwareUartAvailable | Returns how many received bytes are waiting in a hardware UART's buffer on the first EZB, up to 4000. |
| UART.HardwareUartRead | Reads the given number of bytes from a hardware UART of the first EZB. |
| UART.HardwareUartReadAvailable | Reads every byte waiting (up to 4000) on a hardware UART of the first EZB, without waiting for more. |
| UART.HardwareUartReadString | Reads the given number of bytes from a hardware UART of the first EZB as ASCII text. |
| UART.HardwareUartReadStringAvailable | Reads everything waiting (up to 4000 bytes) on a hardware UART of the first EZB as ASCII text, without waiting for more. |
| UART.HardwareUartWrite | Sends one byte out of a hardware UART on the first EZB. |
| UART.HardwareUartWriteString | Sends text as ASCII out of a hardware UART on the first EZB. |
| UART.InitHardwareUart | Sets up a hardware UART on the first EZB at the given baud rate. |
| UART.SendSerial | Sends one byte as serial data out of a digital port on the first EZB. |
| UART.SendSerialString | Sends text as ASCII serial data out of a digital port on the first EZB. |
Details
UART.HardwareUartAvailable
Returns how many received bytes are waiting in a hardware UART's buffer on the first EZB, up to 4000. An error is raised if the EZB is not connected.
UART.HardwareUartAvailable(uartIndex)
UART.HardwareUartAvailable(uartIndex, ezbIndex)
| Value | Type | What it is |
|---|---|---|
uartIndex |
int | The hardware UART number, 0, 1 or 2. |
ezbIndex |
int | Optional. Which EZB to use, 0 being the first one. |
Gives back: int. The number of bytes waiting to be read.
UART.HardwareUartRead
Reads the given number of bytes from a hardware UART of the first EZB. The script waits until that many bytes have arrived, so check how many are available first.
UART.HardwareUartRead(uartIndex, bytesToRead)
UART.HardwareUartRead(uartIndex, bytesToRead, ezbIndex)
| Value | Type | What it is |
|---|---|---|
uartIndex |
int | The hardware UART number, 0, 1 or 2. |
bytesToRead |
int | How many bytes to read, up to 4000. |
ezbIndex |
int | Optional. Which EZB to use, 0 being the first one. |
Gives back: list[int]. The received bytes.
UART.HardwareUartReadAvailable
Reads every byte waiting (up to 4000) on a hardware UART of the first EZB, without waiting for more. Gives an empty array when nothing has arrived.
UART.HardwareUartReadAvailable(uartIndex)
UART.HardwareUartReadAvailable(uartIndex, ezbIndex)
| Value | Type | What it is |
|---|---|---|
uartIndex |
int | The hardware UART number, 0, 1 or 2. |
ezbIndex |
int | Optional. Which EZB to use, 0 being the first one. |
Gives back: list[int]. The received bytes, or an empty array.
UART.HardwareUartReadString
Reads the given number of bytes from a hardware UART of the first EZB as ASCII text. The script waits until that many bytes have arrived, so check how many are available first.
UART.HardwareUartReadString(uartIndex, bytesToRead)
UART.HardwareUartReadString(uartIndex, bytesToRead, ezbIndex)
| Value | Type | What it is |
|---|---|---|
uartIndex |
int | The hardware UART number, 0, 1 or 2. |
bytesToRead |
int | How many bytes to read, up to 4000. |
ezbIndex |
int | Optional. Which EZB to use, 0 being the first one. |
Gives back: str. The received text.
UART.HardwareUartReadStringAvailable
Reads everything waiting (up to 4000 bytes) on a hardware UART of the first EZB as ASCII text, without waiting for more. Gives an empty string when nothing has arrived.
UART.HardwareUartReadStringAvailable(uartIndex)
UART.HardwareUartReadStringAvailable(uartIndex, ezbIndex)
| Value | Type | What it is |
|---|---|---|
uartIndex |
int | The hardware UART number, 0, 1 or 2. |
ezbIndex |
int | Optional. Which EZB to use, 0 being the first one. |
Gives back: str. The received text, or an empty string.
UART.HardwareUartWrite
Sends one byte out of a hardware UART on the first EZB. The UART must be initialised first, and an error is raised if the EZB is not connected.
UART.HardwareUartWrite(uartIndex, @byte)
UART.HardwareUartWrite(uartIndex, byteArray)
UART.HardwareUartWrite(uartIndex, @byte, ezbIndex)
UART.HardwareUartWrite(uartIndex, byteArray, ezbIndex)
| Value | Type | What it is |
|---|---|---|
uartIndex |
int | The hardware UART number, 0, 1 or 2. |
byteArray |
object | Only in some forms. The bytes to send, as a bytearray. |
ezbIndex |
int | Only in some forms. Which EZB to use, 0 being the first one. |
@byte |
int | Only in some forms. |
UART.HardwareUartWrite(uartIndex, @byte): Sends one byte out of a hardware UART on the first EZB. The UART must be initialised first, and an error is raised if the EZB is not connected.UART.HardwareUartWrite(uartIndex, byteArray): Sends bytes out of a hardware UART on the first EZB. The UART must be initialised first, and an error is raised if the EZB is not connected.UART.HardwareUartWrite(uartIndex, @byte, ezbIndex): Sends one byte out of a hardware UART on the chosen EZB. The UART must be initialised first, and an error is raised if the EZB is not connected.UART.HardwareUartWrite(uartIndex, byteArray, ezbIndex): Sends bytes out of a hardware UART on the chosen EZB. The UART must be initialised first, and an error is raised if the EZB is not connected.
UART.HardwareUartWriteString
Sends text as ASCII out of a hardware UART on the first EZB. The UART must be initialised first, and an error is raised if the EZB is not connected.
UART.HardwareUartWriteString(uartIndex, str)
UART.HardwareUartWriteString(uartIndex, str, ezbIndex)
| Value | Type | What it is |
|---|---|---|
uartIndex |
int | The hardware UART number, 0, 1 or 2. |
str |
str | The text to send. Characters outside ASCII are sent as a question mark. |
ezbIndex |
int | Optional. Which EZB to use, 0 being the first one. |
UART.InitHardwareUart
Sets up a hardware UART on the first EZB at the given baud rate. Do this once before sending or receiving on that UART.
UART.InitHardwareUart(uartIndex, baud)
UART.InitHardwareUart(uartIndex, baud, ezbIndex)
| Value | Type | What it is |
|---|---|---|
uartIndex |
int | The hardware UART number, 0, 1 or 2. |
baud |
int | The baud rate in bits per second, such as 9600 or 115200. |
ezbIndex |
int | Optional. Which EZB to use, 0 being the first one. |
UART.SendSerial
Sends one byte as serial data out of a digital port on the first EZB. This is transmit only, and an error is raised if the EZB is not connected.
UART.SendSerial(port, baud, @byte)
UART.SendSerial(port, baud, byteArray)
UART.SendSerial(port, baud, @byte, ezbIndex)
UART.SendSerial(port, baud, byteArray, ezbIndex)
| Value | Type | What it is |
|---|---|---|
port |
int | The digital port, such as d0. |
baud |
int | The baud rate in bits per second: 4800, 9600, 19200, 38400, 57600 or 115200. The older codes are still accepted too (0 = 4800, 1 = 9600, 2 = 19200, 3 = 38400, 4 = 57600, 5 = 115200, 6 = custom). Other values raise an error listing the supported speeds. |
byteArray |
object | Only in some forms. The bytes to send, as a bytearray. |
ezbIndex |
int | Only in some forms. Which EZB to use, 0 being the first one. |
@byte |
int | Only in some forms. |
UART.SendSerial(port, baud, @byte): Sends one byte as serial data out of a digital port on the first EZB. This is transmit only, and an error is raised if the EZB is not connected.UART.SendSerial(port, baud, byteArray): Sends bytes as serial data out of a digital port on the first EZB, any length. This is transmit only, and an error is raised if the EZB is not connected.UART.SendSerial(port, baud, @byte, ezbIndex): Sends one byte as serial data out of a digital port on the chosen EZB. This is transmit only, and an error is raised if the EZB is not connected.UART.SendSerial(port, baud, byteArray, ezbIndex): Sends bytes as serial data out of a digital port on the chosen EZB, any length. This is transmit only, and an error is raised if the EZB is not connected.
UART.SendSerialString
Sends text as ASCII serial data out of a digital port on the first EZB. This is transmit only, and an error is raised if the EZB is not connected.
UART.SendSerialString(port, baud, str)
UART.SendSerialString(port, baud, str, ezbIndex)
| Value | Type | What it is |
|---|---|---|
port |
int | The digital port, such as d0. |
baud |
int | The baud rate in bits per second: 4800, 9600, 19200, 38400, 57600 or 115200. The older codes are still accepted too (0 = 4800, 1 = 9600, 2 = 19200, 3 = 38400, 4 = 57600, 5 = 115200, 6 = custom). Other values raise an error listing the supported speeds. |
str |
str | The text to send. Characters outside ASCII are sent as a question mark. |
ezbIndex |
int | Optional. Which EZB to use, 0 being the first one. |