|Top Previous Next|
Once you have allocated memory for the TX and RX buffers you can start sending and receiving data through them.
Sending Data (through TX buffer)
Sending data is a two-step process. First, you put the data in the TX buffer using the ser.setdata method, and then you perform the actual sending (commit the data) using the ser.send method. For example:
Since this is a two-step process, you may first prepare a large block of data in the TX buffer and only then commit this data (this may come handy in some applications).
Receiving Data (through RX buffer)
Receiving data is a one-step process. To extract the data from a buffer, use the ser.getdata method. Data may only be extracted once from a buffer. Once extracted, it is no longer in the buffer. For example:
The variable whatigot now contains up to 255 bytes of data which came from the TX buffer of the serial port.
It is also possible to preview the data in the RX buffer without actually extracting it. Use ser.peekdata to achieve this.