Skip to content

Pi link library

Red-Leader117 edited this page Dec 28, 2018 · 3 revisions

The Raspberry Pi side of Pi2Ard is based on the Link class in Pi-lib/link.py, which handles the data coming from the Arduino. This part requries the pySerial library.

Link

checkAvailable()

  • Arguments: port = None
  • Returns: bool

Returns True if the given port is available and False if not.

clearBuffer()

Clears in the input buffer by calling serial.Serial.reset_input_buffer().

connect()

  • Arguments: baudRate = None, port = None

Opens the connection to the Arduino. The default baudrate is 9600. If the given port is None, it will attempt to find the default port for Windows and Linux (COM3 and /dev/ttyACM0, respectively).

disconnect()

Closes the connection to the Arduino.

isOpen()

  • Returns: bool

As its name suggests, this returns True if the connection is open, returns False otherwise.

receive()

Checks to see if there is any data in the input buffer. If there is, it will trigger the callback function (passing the data as its argument. This uses serial.Serial.readline() to obtain the data as a bytes array.

setOnReceive()

  • Arguments: func

Sets the callback function for the receive() function. This callback function must have one argument, which will be the new data received as a bytes array.

Clone this wiki locally