SmartWaveAPI.smartwave module
- class SmartWaveAPI.smartwave.SmartWave
Bases:
object
An instance of a SmartWave device. Keeps track of all available resources.
- FPGABitstreamEnd = 4503599627370495
- FPGABitstreamStart = 0
- FPGAClockDivided: int = 1525.9021896696422
- FPGAClockSpeed: int = 100000000.0
- FirmwareEnd = 98816
- FirmwareStart = 36864
- PID: int = 32881
- SBLStart = 8192
- VID: int = 9025
- configGeneral(vddio: float | None = None, trigger_mode: TriggerMode | None = None)
Configure general information on the connected device.
- Parameters:
vddio (float) – The IO voltage of the connected device (accurate to 0.01V). Can be set between 1.6V and 5V, or to 0 to disable output.
trigger_mode (TriggerMode) – The trigger mode of the output device (i.e. whether it runs once or continuously)
- Raises:
AttributeError – if vddio is not betweeen 1.6V and 5.0V, or exactly 0
- connect(port_name: str = None, reset: bool = True, request_info: bool = True, configure_general: bool = True)
Try to connect to a SmartWave device at the specified port.
- Parameters:
port_name (str) – The name of the port to connect to
reset (bool) – Reset the device after connection
request_info (bool) – Request info from the device after connection
configure_general (bool) – Configure general with the default values
- Returns:
Self
- Return type:
- Raises:
ConnectionRefusedError – If no connection could be established with the specified port
AttributeError – If the device at the specified port is not a SmartWave device
- createGPIO(pin_name: str | None = None, name: str | None = None, level: Literal[0, 1] | None = None, pullup: bool | None = None, output_type: PinOutputType | None = None, input_level_callback: Callable[[Literal[0, 1]], None] | None = None) GPIO
Create a GPIO configuration object.
- Parameters:
pin_name (str) – The name of the pin to use, eg “A1”
name (str) – The name of the GPIO pin, as displayed on the device, eg “GPIO”
level (Literal[0, 1]) – The initial level of the pin
pullup (bool) – Whether to enable a pullup resistor on the pin
output_type (PinOutputType) – The output type of the pin
input_level_callback (Callable[[Literal[0, 1]], None]) – A callable to be run whenever the input level of the pin is changed.
- Returns:
A GPIO configuration object
- Return type:
- createI2CConfig(sda_pin_name: str | None = None, scl_pin_name: str | None = None, clock_speed: int | None = None, scl_display_name: str | None = None, sda_display_name: str | None = None) I2CConfig
Create an I2C Configuration object.
- Parameters:
sda_pin_name (str) – The pin to use for SDA, eg “A1”. By default, the next unused pin is used.
scl_pin_name (str) – The pin to use for SCL, eg “A2”. By default, the next unused pin is used.
clock_speed (int) – The transmission clock speed in Hz. Default: 400kHz
scl_display_name (str) – The name to display for the driver’s SCL pin. Default: SCL
sda_display_name (str) – The name to display for the driver’s SDA pin. Default: SDA
- Returns:
An I2C Configuration with the specified settings
- Return type:
- createSPIConfig(sclk_pin_name: str | None = None, mosi_pin_name: str | None = None, miso_pin_name: str | None = None, cs_pin_name: str | None = None, clock_speed: int | None = None, bit_width: int | None = None, bit_numbering: Literal['MSB', 'LSB'] | None = None, cspol: Literal[0, 1] | None = None, cpol: Literal[0, 1] | None = None, cphase: Literal[0, 1] | None = None, sclk_display_name: str | None = None, mosi_display_name: str | None = None, miso_display_name: str | None = None, cs_display_name: str | None = None)
Create an SPI Configuration object.
- Parameters:
sclk_pin_name (str) – The name of the pin to use for SCLK
mosi_pin_name (str) – The name of the pin to use for MOSI
miso_pin_name (str) – The name of the pin to use for MISO
cs_pin_name (str) – The name of the pin to use for CS
clock_speed (int) – The transmission clock speed in Hz
bit_width (int) – The bit width of the SPI transmissions
bit_numbering (Literal["MSB", "LSB"]) – Whether to transmit MSB-first or LSB-first
cspol (Literal[0, 1]) – The polarity of the chipselect pin
cpol (Literal[0, 1]) – The polarity of the clock pin
cphase (Literal[0, 1]) – The phase of the clock
sclk_display_name (str) – The name to display for the driver’s SCLK pin. Default: SCLK
mosi_display_name (str) – The name to display for the driver’s MOSI pin. Default: MOSI
miso_display_name (str) – The name to display for the driver’s MISO pin. Default: MISO
cs_display_name (str) – The name to display for the driver’s CS pin. Default: CS
- Returns:
An SPI Configuration with the specified settings
- Return type:
- disconnect()
Disconnect from the connected device.
- getNextAvailableI2CDriver() I2CDriver
Get the next available I2C Driver.
- Returns:
An I2C Driver, which has already been marked as in use
- Return type:
- Raises:
Exception – If no more I2C Drivers are available on the device
- getNextAvailablePin() Pin
Get the next available Pin.
- Returns:
A Pin, which has already been marked as in use
- Return type:
- Raises:
Exception – If no more Pins are available on the device
- getNextAvailableSPIDriver() SPIDriver
Get the next available SPI Driver.
- Returns:
An SPI Driver, which has already been marked as in use
- Return type:
- Raises:
Exception – If no more SPI Drivers are available on the device
- getNextAvailableStimulus() Stimulus
Get the next available stimulus.
- Returns:
A Stimulus, which has already been marked as in use
- Return type:
- Raises:
Exception – If no more Stimuli are available on the device
- getPin(name: str) Pin
Get a pin by its name.
- Parameters:
name (str) – The pin’s name
- Returns:
The specified pin, which has already been marked as in use
- Return type:
- Raises:
AttributeError – If the pin name does not exist on the device
Exception – If the pin is already in use
- isConnected() bool
Return whether a device connection is currently active.
- Returns:
True if the device is connected, False otherwise
- readFPGARegister(address: int, blocking: bool = True) int | None
Read directly from a register on the SmartWave’s FPGA.
- Parameters:
address (int) – The address to read from
blocking (bool) – If true, wait for the response from the connected device
- Returns:
If blocking == True, return the content of the specified register. Else return None.
- Return type:
Union[int, None]
- Raises:
Exception – If the blocking mode is requested and another callback for a register read operation is already registered
- removeConfig(config: Config)
Remove a config from the device.
- Parameters:
config (Config) – the config to remove
- Raises:
AttributeError – If the config is not found
- requestInfo()
Request the device information from the connected device.
- reset()
Reset the configuration of the connected device.
- returnI2CDriver(driver: I2CDriver) int
Return an I2C Driver to the list of available I2C Drivers.
- Parameters:
driver (I2CDriver) – The I2C driver to return
- Returns:
The new number of available I2C Drivers
- Return type:
int
- returnPin(pin: Pin) int
Return a Pin to the list of available pins.
- Parameters:
pin (Pin) – The pin to return
- Returns:
The new number of available pins
- Return type:
int
- returnSPIDriver(driver: SPIDriver) int
Return an SPI Driver to the list of available SPI Drivers.
- Parameters:
driver (SPIDriver) – The SPI driver to return
- Returns:
The new number of available SPI drivers
- Return type:
int
- returnStimulus(stimulus: Stimulus) int
Return a stimulus to the list of available stimuli.
- Parameters:
stimulus (Stimulus) – The stimulus to return
- Returns:
The new number of available stimuli
- Return type:
int
- scanAndConnect(reset: bool = True, request_info: bool = True, configure_general: bool = True)
Scan all serial ports on the PC and connect to a SmartWave device if one is found.
- Parameters:
reset (bool) – Reset the device after connection
request_info (bool) – Request info from the device after connection
configure_general (bool) – Configure general with the default values
- Returns:
Self
- Return type:
- Raises:
ConnectionRefusedError – If no suitable device is found
- trigger()
Start or Stop the current configuration on the connected device.
- property triggerMode: TriggerMode
Get the current trigger mode of the connected device.
- Returns:
The current trigger mode of the connected device
- Return type:
- updateFPGABitstream(bitstream_path: str | None = None, blocking: bool = True)
Update the FPGA bitstream with a given bitstream, or to the newest version.
Also checks the bitstream file for plausibility and calculates the checksum.
- Parameters:
bitstream_path (Optional[str]) – The path to the bitstream. If unspecified, upload newest packaged bitstream.
blocking (bool) – Whether to wait until the bitstream update is finished
- Raises:
FileNotFoundError – If the bitstream file could not be found
Exception – If the bitstream file is of the wrong size
- updateFirmware(firmware_path: str | None = None)
Update the microcontroller firmware with a given firmware, or to the newest version.
This also checks the firmware file for plausibility and calculates the checksum.
- Parameters:
firmware_path (Optional[str]) – The path to the new firmware. If unspecified, upload newest packaged firmware.
- Raises:
FileNotFoundError – If the firmware file could not be found
Exception – If the firmware file is incompatible with the bootloader
Exception – If the firmware size is incompatible with the bootloader
- property vddio: float
Get the current IO voltage of the connected device.
- Returns:
The current IO voltage of the connected device
- Return type:
float
- writeFPGARegister(address: int, value: int)
Write directly to a register on the SmartWave’s FPGA.
- Parameters:
address (int) – The address to write to
value (int) – The value to write
- writeToDevice(data: bytes, acquire_lock: bool = True, progress_callback: Callable[[int], None] | None = None)
Write bare data to the connected device.
- Parameters:
data (bytes) – the data to write
acquire_lock (bool) – Whether to acquire lock for serial resource. Setting this to False may have adverse side effects.
progress_callback (Optional[Callable[[int], None]]) – a callback to tell the progress of the transaction. Gives the progress in percent.
- Raises:
Exception – If the serial connection is not active