API documentation for ad24usbdevice.Device class.
__init__(serial_string, description = b"AD24USB", index = 0):
Constructor initializes and opens ad24usb device. Device is selected by serial_string, description and index parameters. Raises OpenError if is not able to open device and InitError when some initilization fails.
serial_string
Ftdi serial byte string of device.
description
Description byte string. Default is b"AD24USB"
index
If is more devices with the same serial_string and description, device can be selected by index. Indexes starts from 0 what is also a default value.
close()
Stops periodical mode, sets current to 0, and deinit device.
set_range(unipolar = True)
Sets input range of AD converter.
unipolar
If parameter is True range is set to unipolar. Otherwise range will be bipolar.
set_chopper(chop_type = CHOPPER_DISABLED, samples_count = 2)
Method sets type of chopper and number of sampes for chopping. Chopper can remove voltage drifts and noise. Automaticaly sets device into bipolar mode for any active chopper.
chop_type
Type of required chopper. Must be one of:
samples_count
Number of measured samples used by chopper. Value should be even number.
set_resolution(self, resolution)
Sets resolution (integrating time) for AD converter. Raises DeviceInPeriodicalMode exception if device is in periodical mode and ValueError for incorrect resolution values.
resolution
Should be one of RESOLUTIONS constants.
calibration(one_gain, gain)
Method internaly fills calibration table that is used to convert measured values to real voltage. This function must be called before each measurement. And for longer measuring should be called periodicaly because of thermal changes and voltage drifts inside the device. Raises DeviceInPeriodicalMode when is called during periodical measurement, ValueError for bad gain parameter and CommunicationError if is not able to communicate with device.
one_gain
If True, only one gain will be calibrated. Otherwise all gains will be calibrated and gain parameter is ignored.
gain
Gain that should be calibrated (ignored when one_gain is False). Value must be one of GAINS constants.
get_sample(channel, gain)
Returns measured voltage (modified by calibration table) from channel with gain if device is in standard mode. If periodical mode is enabled, both parameters are ignored and measuring depends on channels parameter in start_periodical_mode method. Method applies and uses chopper if is enabled. Raises ValueError if gain or channel are not a valid values. Function call ftdidevice.read() so eventualy can be raised ftdidevice.DeviceReadError.
channel
Input channel. Must be one of CHANNELS constants.
gain
Required gain for channel. Must be one of GAINS constants.
start_periodical_mode(channels, timer)
Method starts periodical mode in device. Device will continualy with timer period measures voltage based on channels parameter. Measurement starts immediately after this function is called. Measured values are returned by get_sample function. TimerError is raised if timer is too sort.
channels
Must be a iterable object that contains tuples with channel id and gain for each channel where measurement will be performed. E.g. if it is list like [(CHANNEL_0, GAIN_1), (CHANNEL_5, GAIN_39), (CHANNEL_7, GAIN_17)]. Then measured will be (and get_sample returns voltage) from CHANNEL_0 with GAIN_1. After the timer ms CHANNEL_5 with GAIN_39 will be measured and after another timer ms CHANNEL_7 with GAIN_17 will follows. After that measurement starts again from the begining until stop_periodical_mode is called.
timer
Value in ms for internal timer. Value must be more than a time necessary to finish measurement for given channel, chopper and resolution. Maximal value is 65000.
stop_periodical_mode()
Method stops periodical mode.
is_periodical_mode()
Returns True if device is in periodical mode. If not returns False.
set_current_value(current, sleep = True)
Method set power of output current source. Returns value that is setted.
current
Should be a float number of required power in mA. Value is rounded to match device current resolution. ValueError is raised if current is more then maximal current. DeviceInPeriodicalMode if device is in periodical mode.
sleep
If True, method will wait for 100ms. To be sure the current value is exact before method returns. If False method return immediately.
get_current_source_info()
Returns tuple that contains maximal current of current source in mA and resolution in bits of current DA converter. Both values are integers.
get_version()
Method returns 4 bytes long binary string representing device firmware verions.
get_serial_number()
Returns device serial number as a integer.
get_real_gains()
Returns list of real devices gains. Those values are obtained from device flash rom in init method.
dig_output(byte)
THIS IS EXPERIMENTAL FUNCTION AND IS NOT TESTED YET!!
Method sends byte to digital output pins.
byte
Integer value that will be written to digital output.
dig_input()
THIS IS EXPERIMENTAL FUNCTION AND IS NOT TESTED YET!!
Method reads byte from digital input pins and returns it as a integer.