The dataq_binary module¶
Autogenerated API documentation for dataq_binary¶
DataQ Binary protocol driver
To get started using the one of the supported DataQ data cards, use one of the sub-classes of DataQBinary e.g. DI1110, set scan list and start:
# Instantiate dataq object
dataq = DI1110('/dev/ttyUSB0')
# Get all available information from the data cards
print(repr(dataq.info()))
# Set sample rate frequence
dataq.sample_rate(1000)
# Set scan list (meaure on channel 1 first, then 0 and finnaly 2)
dataq.scan_list([1, 0, 2])
dataq.clear_buffer()
dataq.start()
sleep(0.1)
from pprint import pprint
try:
while True:
pprint(dataq.read())
sleep(0.5)
except KeyboardInterrupt:
dataq.stop()
else:
dataq.stop()
dataq.clear_buffer()
If the data card is being used on the limit of emptying the data buffer before it
overflow, it might be useful to put the calls to read
in a try except:
while True:
try:
dataq.read()
except dataq_binary.BufferOverflow:
# Re-start i.e. stop and start
or, to simple start and stop the card for a short amount of time, if slow measurements, which would otherwise fill buffer are required:
while True:
dataq.start()
sleep(0.1)
dataq.read()
dataq.stop()
# We really only need to measure every 10s
sleep(10)
On some Linux system, at the end of 2017, some models, e.g. the DI-1110 wasn’t automatically mounted. In that case, it can be manually mounted with a command like this one:
sudo modprobe usbserial vendor=0x0683 product=0x1110
On should be possible, on Debian based Linux systems to add an automatic mount rule along the lines of this thread: https://askubuntu.com/questions/525016/cant-open-port-dev-ttyusb0
So, add a new udev rule /etc/udev/rules.d/99-dataq_di1110.rules
with this content:
# /etc/udev/rules.d/99-dataq_di1110.rules
# contains DataQ DI-1110 udev rule to patch default
# rules
SYSFS{idProduct}=="1110",
SYSFS{idVendor}=="0683",
RUN+="/sbin/modprobe -q usbserial product=0x1110 vendor=0x0683"
and aftwerwards run: sudo udevadm control –reload-rules
-
exception
PyExpLabSys.drivers.dataq_binary.
BufferOverflow
[source]¶ Bases:
Exception
Custom exception to indicate a buffer overflow
-
class
PyExpLabSys.drivers.dataq_binary.
DataQBinary
(device, serial_kwargs=None)[source]¶ Bases:
object
Base class for DataQBinary driver
-
end_char
= '\r'¶ Serial communication end character
-
read_wait_time
= 0.001¶ Wait time between serial write and read
-
infos
= {'device name': 1, 'firmware revision': 2, 'sample rate divisor': 9, 'serial number': 6, 'vendor': 0}¶ Information items that can be retrieved along with their code number
-
led_colors
= {'black': 0, 'blue': 1, 'cyan': 3, 'green': 2, 'magenta': 5, 'red': 4, 'white': 7, 'yellow': 6}¶ Supported LED colors along with the code number
-
buffer_overflow_size
= 4095¶ Buffer overflow size, may be overwritte in sub classes
-
packet_sizes
= {16: 0, 32: 1, 64: 2, 128: 3, 256: 4, 512: 5, 1024: 6, 2048: 7}¶ Packet sizes and code numbers
-
info
(info_name='all')[source]¶ Return information about the device
Parameters: info_name (str) – Name of the requested information item(s). If info_name is one the specific info names, (the keys in DataQBinary.infos), a string will be returned with the value. If info_name is ‘all’, all values will be returned in a dict Returns: Information items Return type: str or dict
-
scan_list
(scan_list)[source]¶ Set the scan list
The scan list is the list of inputs to acquire from on the data card. The scan list can hold up to 11 items, since there are a total on 11 inputs and each element can only be there once. The analogue input channel are numbered 0-7, 8 is the counter channel, 9 is the rate channel and 10 is the general purpose input channel. 0.7 are specified only by their number, 8, 9 and 10 are configured specially, which is not described here yet.
Parameters: scan_list (list) – Etc. [3, 5, 0] for analogue input chanel 3, 5 and 0. NOTE: The numbers are integers, not strings.
-
sample_rate
(rate)[source]¶ Set the sample rate
The value values are calculated as being in the range of
sample rate divisor / 375 to sample rate divisor / 65535So e.g. for the DI-1110 product, with a sample rate divisor of 60,000,000, the valid inputs are in range from 915.5413 to 160000.
Parameters: rate (float) – The sample rate given in number of elements in the scan list sampled per second (i.e. in Hz). Valid values depend on the model and is given by the “sample rate divisor” information item (see the info method). See information about how to calculate the valid input range above.
-
packet_size
(size)[source]¶ Set the packet size
The packet size is he amount of data acquired before it is placed in the read buffer. The available packet sizes are the keys in packet_sizes class variable.
Parameters: size (int) – The requested packet size
-
led_color
(color)[source]¶ Set the LED color
Parameters: color (str) – The available colors are the keys in the led_colors class variable
-
read
()[source]¶ Read all values waiting
This method reads all available damples from the data card and returns for every channel the mean of those samples.
The returned data is on the form of a list with one item for each item in the scan list and in the same order. Each of the items is in them selves a dict, which holds the mean value of the samples, the number of samples in the mean, the channel number (0-based) and information about how full the data buffer was, at the time when it was read out. An example could be:
[{'buffer_status': '3040/4095 bytes', 'channel': 1, 'samples': 506, 'value': -1.6224543756175889}, {'buffer_status': '3040/4095 bytes', 'channel': 0, 'samples': 507, 'value': -0.0044494267751479287}, {'buffer_status': '3040/4095 bytes', 'channel': 2, 'samples': 507, 'value': 1.6192735299556213}]
where the scan list was set to [1, 0, 2].
Returns: - A list of values for each of the items in the scan-list and
- in the same order. For details of returns values see above.
Return type: list Raises: BufferOverflow
– If the buffer was full at the time of reading. The behavior in this case is ill-defined, so it is better to re-start the measurement if that happens.
-
-
class
PyExpLabSys.drivers.dataq_binary.
DI1110
(device, serial_kwargs=None)[source]¶ Bases:
PyExpLabSys.drivers.dataq_binary.DataQBinary
FIXME