libsmu  1.0.4
Library for interfacing with ADALM1000 devices
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Friends | List of all members
smu::Device Class Referenceabstract

Generic device class. More...

#include <libsmu.hpp>

Public Member Functions

virtual const sl_device_infoinfo () const =0
 Get the descriptor for the device.
 
virtual const sl_channel_infochannel_info (unsigned channel) const =0
 Get the descriptor for the specified channel. More...
 
virtual Signalsignal (unsigned channel, unsigned signal)=0
 Get the specified signal. More...
 
virtual int fwver_sem (std::array< unsigned, 3 > &components)=0
 Get the array of firmware version components (major, minor, patch). Note that this method assumes semantic versioning so versions such as 2.06 will be coerced to 2.6.0, i.e. major=2, minor=6, patch=0.
 
virtual int set_serial (std::string serial="")=0
 Set a custom serial number for the device. More...
 
virtual int set_mode (unsigned channel, unsigned mode, bool restore=true)=0
 Set the mode of the specified channel. More...
 
virtual int get_mode (unsigned channel)=0
 Get the mode of the specified channel. More...
 
virtual ssize_t read (std::vector< std::array< float, 4 >> &buf, size_t samples, int timeout=0, bool skipsamples=false)=0
 Get all signal samples from a device. More...
 
virtual int write (std::vector< float > &buf, unsigned channel, bool cyclic=false)=0
 Write data to a specified channel of the device. More...
 
virtual void flush (int channel, bool read=false)=0
 Flush the read and selected channel write queue for a device. More...
 
int ctrl_transfer (unsigned bmRequestType, unsigned bRequest, unsigned wValue, unsigned wIndex, unsigned char *data, unsigned wLength, unsigned timeout)
 Perform a raw USB control transfer on the underlying USB device. More...
 
virtual int samba_mode ()=0
 Force the device into SAM-BA bootloader mode. More...
 
virtual int get_default_rate ()
 Get the default sample rate.
 
virtual int sync ()=0
 Prepare multi-device synchronization. Get current microframe index, set m_sof_start to be time in the future. More...
 
virtual void lock ()
 Lock the device's mutex. This prevents this device's transfers from being processed. Hold only briefly, while modifying signal state.
 
virtual void unlock ()
 Unlock the device's mutex. Allows this device's transfers to be processed.
 
virtual int write_calibration (const char *cal_file_name)
 Write the device calibration data into the EEPROM. More...
 
virtual int read_calibration ()=0
 Read device calibration data from the EEPROM.
 
virtual void calibration (std::vector< std::vector< float >> *cal)=0
 Get the device calibration data from the EEPROM. More...
 
virtual int set_led (unsigned leds)=0
 Set the leds states for device. More...
 
virtual int set_adc_mux (unsigned adc_mux)=0
 set adc mux mode
 

Public Attributes

const std::string m_hwver
 hardware version
 
const std::string m_fwver
 firmware version
 
const std::string m_serial
 serial number
 
int m_overcurrent = 0
 Session this device is associated with. More...
 

Protected Member Functions

 Device (Session *s, libusb_device *usb_dev, libusb_device_handle *usb_handle, const char *hw_version, const char *fw_version, const char *serial)
 Device constructor.
 
virtual int claim ()
 Device claiming and initialization when a session adds this device. More...
 
virtual int release ()
 Device releasing when a session removes this device. More...
 
virtual int configure (uint32_t sampleRate)=0
 Configurization and initialization for device sampling. More...
 
virtual int on ()=0
 Turn on power supplies and clear sampling state. More...
 
virtual int off ()=0
 Stop any current sample writes and stop capturing samples. More...
 
virtual int run (uint64_t samples)=0
 Make the device start sampling. More...
 
virtual int cancel ()=0
 Cancel all pending libusb transactions. More...
 

Protected Attributes

Session *const m_session
 Session this device is associated with.
 
libusb_device *const m_usb_dev = NULL
 Underlying libusb device.
 
libusb_device_handle * m_usb = NULL
 Underlying libusb device handle.
 
uint64_t m_requested_sampleno = 0
 Cumulative sample number being handled for input.
 
uint64_t m_in_sampleno = 0
 Current sample number being handled for input.
 
uint64_t m_out_sampleno = 0
 Current sample number being submitted for output.
 
double m_write_timeout = 100
 Amount of time in milliseconds to wait before timing out write operations, defaults to 100 ms and is based on the configured sample rate.
 
std::recursive_mutex m_state
 Lock for transfer state.
 

Friends

class Session
 

Detailed Description

Generic device class.

Member Function Documentation

◆ calibration()

virtual void smu::Device::calibration ( std::vector< std::vector< float >> *  cal)
pure virtual

Get the device calibration data from the EEPROM.

Parameters
calA vector of vectors containing calibration values.

◆ cancel()

virtual int smu::Device::cancel ( )
protectedpure virtual

Cancel all pending libusb transactions.

Returns
On success, 0 is returned.
On error, a negative errno code is returned.

◆ channel_info()

virtual const sl_channel_info* smu::Device::channel_info ( unsigned  channel) const
pure virtual

Get the descriptor for the specified channel.

Parameters
channelAn unsigned integer relating to the requested channel.

◆ claim()

virtual int smu::Device::claim ( )
inlineprotectedvirtual

Device claiming and initialization when a session adds this device.

Returns
On success, 0 is returned.
On error, a negative errno code is returned.

◆ configure()

virtual int smu::Device::configure ( uint32_t  sampleRate)
protectedpure virtual

Configurization and initialization for device sampling.

Parameters
sampleRateThe requested sampling rate for the device.
Returns
On success, the configured sample rate is returned.
On error, a negative errno code is returned.

◆ ctrl_transfer()

int smu::Device::ctrl_transfer ( unsigned  bmRequestType,
unsigned  bRequest,
unsigned  wValue,
unsigned  wIndex,
unsigned char *  data,
unsigned  wLength,
unsigned  timeout 
)

Perform a raw USB control transfer on the underlying USB device.

Returns
Passes through the return value of the underlying libusb_control_transfer method. See the libusb_control_transfer() docs for parameter descriptions.

◆ flush()

virtual void smu::Device::flush ( int  channel,
bool  read = false 
)
pure virtual

Flush the read and selected channel write queue for a device.

Parameters
channelChannel to flush the write queues for. If -1, skip flushing write queues.
readWhether to flush the incoming read queue as well.

◆ get_mode()

virtual int smu::Device::get_mode ( unsigned  channel)
pure virtual

Get the mode of the specified channel.

Parameters
channelAn unsigned integer relating to the requested channel.
Returns
The mode of the specified channel.
On error, a negative integer is returned relating to the error status.

◆ off()

virtual int smu::Device::off ( )
protectedpure virtual

Stop any current sample writes and stop capturing samples.

Returns
On success, 0 is returned.
On error, a negative errno code is returned.

◆ on()

virtual int smu::Device::on ( )
protectedpure virtual

Turn on power supplies and clear sampling state.

Returns
On success, 0 is returned.
On error, a negative errno code is returned.

◆ read()

virtual ssize_t smu::Device::read ( std::vector< std::array< float, 4 >> &  buf,
size_t  samples,
int  timeout = 0,
bool  skipsamples = false 
)
pure virtual

Get all signal samples from a device.

Parameters
bufBuffer object to store sample values into.
samplesNumber of samples to read.
timeoutAmount of time in milliseconds to wait for samples.
skipsamplesWhether to skip the queued samples. to be available. If 0 (the default), return immediately. If -1, block indefinitely until the requested number of samples is available.
Returns
On success, the number of samples read.
On error, a negative integer is returned relating to the error status.
Exceptions
std::system_errorof EBUSY if sample overflows have occurred.

◆ release()

virtual int smu::Device::release ( )
inlineprotectedvirtual

Device releasing when a session removes this device.

Returns
On success, 0 is returned.
On error, a negative errno code is returned.

◆ run()

virtual int smu::Device::run ( uint64_t  samples)
protectedpure virtual

Make the device start sampling.

Parameters
samplesNumber of samples to run before stopping.
Returns
On success, 0 is returned.
On error, a negative errno code is returned.
Exceptions
std::system_errorof EBUSY if sample underflows/overflows have occurred.

◆ samba_mode()

virtual int smu::Device::samba_mode ( )
pure virtual

Force the device into SAM-BA bootloader mode.

Returns
On success, 0 is returned.
On error, a negative errno code is returned.

◆ set_led()

virtual int smu::Device::set_led ( unsigned  leds)
pure virtual

Set the leds states for device.

Parameters
ledsvalue between [0, 7], each bit of the value represents the state of an LED (1-on 0-off) in this order (RGB or DS3,DS2,DS1 on rev F hardware)

◆ set_mode()

virtual int smu::Device::set_mode ( unsigned  channel,
unsigned  mode,
bool  restore = true 
)
pure virtual

Set the mode of the specified channel.

Parameters
channelAn unsigned integer relating to the requested channel.
modeAn unsigned integer relating to the requested mode.
restoreBoolean relating to supporting saving the mode being
Returns
On success, 0 is returned.
On error, a negative integer is returned relating to the error status. This method may not be called while the session is active.

◆ set_serial()

virtual int smu::Device::set_serial ( std::string  serial = "")
pure virtual

Set a custom serial number for the device.

Parameters
serialThe custom serial number to set, defaults to an empty string that causes the device to reset back to its original serial number.
Returns
On success, 0 is returned.
On error, a negative integer is returned relating to the error status. This method may not be called while the session is active.

◆ signal()

virtual Signal* smu::Device::signal ( unsigned  channel,
unsigned  signal 
)
pure virtual

Get the specified signal.

Parameters
channelAn unsigned integer relating to the requested channel.
signalAn unsigned integer relating to the requested signal.
Returns
The related Signal.

◆ sync()

virtual int smu::Device::sync ( )
pure virtual

Prepare multi-device synchronization. Get current microframe index, set m_sof_start to be time in the future.

Returns
On success, 0 is returned.
On error, a negative errno code is returned.

◆ write()

virtual int smu::Device::write ( std::vector< float > &  buf,
unsigned  channel,
bool  cyclic = false 
)
pure virtual

Write data to a specified channel of the device.

Parameters
bufBuffer of samples to write to the specified channel.
channelChannel to write samples to.
cyclicEnable cyclic mode (passed buffer is looped over continuously).
Returns
On success, 0 is returned.
On error, a negative integer is returned relating to the error status.
Exceptions
std::system_errorof EBUSY if sample underflows have occurred.

◆ write_calibration()

virtual int smu::Device::write_calibration ( const char *  cal_file_name)
inlinevirtual

Write the device calibration data into the EEPROM.

Parameters
cal_file_nameThe path to a properly-formatted calibration data file to write to the device. If NULL is passed, calibration is reset to the default setting.
Returns
On success, 0 is returned.
On error, a negative integer is returned relating to the error status.

Member Data Documentation

◆ m_overcurrent

int smu::Device::m_overcurrent = 0

Session this device is associated with.

Overcurrent status for the most recent data request. Is 1 if an overcurrent event occurred in the most recent data request, 0 otherwise.


The documentation for this class was generated from the following file: