pyb.USB_VCP
Classes
Create a new USB_VCP object. The id argument specifies which USB VCP port to |
Module Contents
- class pyb.USB_VCP.USB_VCP(id=0)
Create a new USB_VCP object. The id argument specifies which USB VCP port to use.
- close() Incomplete
This method does nothing. It exists so the USB_VCP object can act as a file.
- init(*, flow=-1) None
Configure the USB VCP port. If the flow argument is not -1 then the value sets the flow control, which can be a bitwise-or of
USB_VCP.RTSandUSB_VCP.CTS. RTS is used to control read behaviour and CTS, to control write behaviour.
- irq(handler=None, trigger=IRQ_RX, hard=False) None
Register handler to be called whenever an event specified by trigger occurs. The handler function must take exactly one argument, which will be the USB VCP object. Pass in
Noneto disable the callback.Valid values for trigger are:
USB_VCP.IRQ_RX: new data is available for reading from the USB VCP object.
- read(nbytes: Any | None = None) bytes
Read at most
nbytesfrom the serial device and return them as a bytes object. Ifnbytesis not specified then the method reads all available bytes from the serial device. USB_VCPstreamimplicitly works in non-blocking mode, so if no pending data available, this method will return immediately withNonevalue.
- readinto(buf, maxlen: Any | None = None) int
Read bytes from the serial device and store them into
buf, which should be a buffer-like object. At mostlen(buf)bytes are read. Ifmaxlenis given and then at mostmin(maxlen, len(buf))bytes are read.Returns the number of bytes read and stored into
buforNoneif no pending data available.
- readline() bytes
Read a whole line from the serial device.
Returns a bytes object containing the data, including the trailing newline character or
Noneif no pending data available.
- readlines() List
Read as much data as possible from the serial device, breaking it into lines.
Returns a list of bytes objects, each object being one of the lines. Each line will include the newline character.
- recv(data, *, timeout=5000) int
Receive data on the bus:
datacan be an integer, which is the number of bytes to receive, or a mutable buffer, which will be filled with received bytes.timeoutis the timeout in milliseconds to wait for the receive.
Return value: if
datais an integer then a new buffer of the bytes received, otherwise the number of bytes read intodatais returned.
- send(data, *, timeout=5000) int
Send data over the USB VCP:
datais the data to send (an integer to send, or a buffer object).timeoutis the timeout in milliseconds to wait for the send.
Return value: number of bytes sent.
- setinterrupt(chr) None
Set the character which interrupts running Python code. This is set to 3 (CTRL-C) by default, and when a CTRL-C character is received over the USB VCP port, a KeyboardInterrupt exception is raised.
Set to -1 to disable this interrupt feature. This is useful when you want to send raw bytes over the USB VCP port.
- CTS: Incomplete
to select the flow control type.
- IRQ_RX: Incomplete
IRQ trigger values for
USB_VCP.irq().
- RTS: Incomplete
to select the flow control type.