This is the highest level module import for the PiSoC API, which the user should import into their scripts for full use of it. It is used to keep records of some globally used variables between all classes.
It is also used to send data to, and receive data from the PiSoC using a user chosen communication protocol.
Note
Most of the classes and functions described in this section have little use to most users. They generally will only be useful when implementing new functionality in the firmware.
At the beginning of each script, insert the following two lines:
>>> from pisoc import * #This will handle dependencies
>>> PiSoC('PC', log_level = 'info') #for PC
>>> PiSoC('PI', log_level = 'info') #for PI
Class: | This class is used to define the register locations of each component on the PiSoC, it defines which communication protocol will be utilized by the API, and it collects compiled data from the PiSoC. The class is not to be assigned to an object; it only needs to be called so that addresses can be defined, compiled data on the PiSoC can be verified, and so that the communication protocol can be initialized. Optionally, one can construct the object with a logging parameter, as described in the __new__() description, which will print diagnostic information to the terminal.
|
---|
Method: | __new__ |
||||||||
---|---|---|---|---|---|---|---|---|---|
Description: | Constructs the PiSoC object. It will decide the communication protocol to be utilized by the API and it will attempt to learn what components are available on the PiSoC |
||||||||
Parameters: |
|
||||||||
Returns: | None |
Class: | Provides a serial (USB UART) interface for communicating with the PiSoC |
---|---|
Note: | pyserial 2.7 must be available to use this class |
Method: | __init__ |
Description: | Constructs and initializes a USB_UART object. This is the default protocol for PC use. No serial port should need to be provided, as long as the drivers are properly installed. This function should find the PiSoC automatically. |
Parameters: | baud (int) – Baud rate to be used. Defaults to 9600, but can be any standard baud rate. (\(9600 * 2^n\)). The Port may need to be configured for higher baud rates on some operating systems (Windows), or the OS may not honor the request. |
Returns: | None |
Method: | cleanup |
---|---|
Description: | Forces a software reset on the PiSoC and then closes and cleans up the serial port |
Returns: | None |
Method: | disconnect |
---|---|
Description: | Forces a clean disconnection from the PiSoC, if it is connected. |
Returns: | None |
Method: | is_connected |
---|---|
Description: | Checks to see if the serial port is open, and that it is connected to a PiSoC |
Returns: | Boolean value (True/False) indicating whether the PiSoC is connected or disconnected, respectively. |
Method: | receive_data |
---|---|
Description: | Called when a returned value is desired from the PiSoC. It will send a command, and then wait for a response. If the response appears valid, it will be unpacked and returned, otherwise debug messages will be logged indicating possible errors. |
Parameters: |
|
Returns: | Unpacked data from the PiSoC, indicating the returned value. |
Raises: |
Method: | reconnect |
---|---|
Description: | Used to reestablish a connection to the PiSoC after it has been lost |
Returns: | Boolean value (True/False) indicating whether the reconnection was successful or unsuccessful, respectively. |
Method: | send_data |
---|---|
Description: | Sends data to the PiSoC, without requiring a return value. It will wait to be sure the provided arguments produce a valid command on the PiSoC, and return an error code if not. |
Parameters: |
|
Returns: | None |
Raises: |
Method: | __init__ |
---|---|
Description: | Constructs and initializes a UART object. This is the default protocol for Raspberry Pi use. |
Parameters: | |
Returns: | None |
Method: | cleanup |
---|---|
Description: | Forces a software reset on the PiSoC and then closes and cleans up the serial port |
Returns: | None |
Method: | receive_data |
---|---|
Description: | Called when a returned value is desired from the PiSoC. It will send a command, and then wait for a response. If the response appears valid, it will be unpacked and returned, otherwise debug messages will be logged indicating possible errors. |
Parameters: |
|
Returns: | Unpacked data from the PiSoC, indicating the returned value. |
Method: | send_data |
---|---|
Description: | Sends data to the PiSoC, without requiring a return value. It will wait to be sure the provided arguments produce a valid command on the PiSoC, and return an error code if not. |
Parameters: |
|
Returns: | None |
Method: | __init__ |
---|---|
Description: | Constructs and initializes an I2C object. This is the default protocol for the Raspberry Pi 3 to use. |
Parameters: | |
Returns: | None |
Method: | receive_data |
---|---|
Description: | Called when a returned value is desired from the PiSoC. It will send a command, and then wait for a response. If the response appears valid, it will be unpacked and returned, otherwise debug messages will be logged indicating possible errors. |
Parameters: |
|
Returns: | Unpacked data from the PiSoC, indicating the returned value. |
Method: | send_data |
---|---|
Description: | Sends data to the PiSoC, without requiring a return value. It will wait to be sure the provided arguments produce a valid command on the PiSoC, and return an error code if not. |
Parameters: |
|
Returns: | None |
Exception: | LostConnection |
---|---|
Description: | Raised when connection to the PiSoC is lost |
Exception: | ClosedPortException |
---|---|
Description: | Raised when a write or read attempt is being made on a closed port |
Function: | Test_Read |
---|---|
Description: | Used to test data transfer between devices. It will take a generic list of data, and echo back a piece of that data at the specified location. |
Parameters: |
|
Returns: | The data returned from the PiSoC; if transmission of args was successful, the return value should be args[index]. |
Example: | >>> from pisoc import *
>>> PiSoC('PC', log_level = 'info')
>>> Test_Read(1, 2, 3, 4, 5)
1
>>> Test_Read(2, 4, 6, 8, 10, 12, 22, index = 3)
8
|
Function: | PrepareData |
---|---|
Description: | Used internally to format unpacked arguments into a character buffer for transfer to the PiSoC in the expected format. |
Parameters: |
|
Returns: | character buffer to be sent to the PiSoC sequentially. |