Driver

Start by importing dataq DI-245.

from dataq_di_245 import Driver

The simple example of the driver usage shown below.

In [1]: from dataq_di_245 import Driver

In [2]: driver = Driver()

In [3]: driver.available_ports
Out [3]: ['COM6']

In [4]: driver.init()

In [5]: driver.port
Out [5]: Serial<id=0x2238bb0, open=True>(port='COM6', baudrate=115200, bytesize=8, parity='N', stopbits=1, timeout=0.1, xonxoff=False, rtscts=True, dsrdtr=False)

In [6]: driver.config_channels(scan_lst = ['0','1','2','3'],phys_ch_lst = ['0','1','2','3'],gain_lst = ['0.5','0.5','0.5','0.5'], rate = 0)
Out [6]: (1, [True, True, True, True, True])

In [7]:  driver.start_scan()

In [8]:  arr = driver.read_number(N_of_channels = 4, N_of_points = 10)

In [9]: arr.shape, arr.mean()
Out [9]: ((4, 10), 14335.75)

In [10]: driver.waiting
Out [10]: (17192, 0)

In [11]: driver.acquiring
Out [11]: True

In [12]:  driver.description
Out [12]: {'Device name': b'A12450', 'Firmware version': b'6B', 'Last Calibration date in hex': b'FFFFFFFF', 'Serial Number': b'XXXXXXXXXX'}

In [13]: driver.stop_scan()
Out [13]: True

In [15]: driver.stop()

In [16]: driver.port.isOpen()
Out [16]: False
class dataq_di_245.Driver(serial_number=None)[source]
property available_ports

property objects that return a list of com ports that have DI245 in the description.

Returns
list :: list

list of com ports

Examples

>>> driver.available_ports
['COM23']
close(port=None)[source]

orderly closes serial port associated with the class

Parameters
port :: ‘’serial.serialposix.Serial’’, optional

pyserial port object, if left blank the self.port is assumed.

Examples

>>> driver.close()
config_channels(scan_lst=['0', '1', '2', '3'], phys_ch_lst=['0', '1', '2', '3'], gain_lst=['5', '5', '5', 'T-thrmc'], rate=0)[source]

configures channels: maps physical channel list on the scan list with defined gains. configures readout rate.

Parameters
scan_lst :: list

scan order list

phys_ch_lst :: list

physical channel order list

gain_lst :: list

list of gains

rate :: float

rate of data collection

Returns
ToDo… Add what is returned if any.

Examples

>>> driver.config_channels
convert_buffer_to_array(buffer, N_of_channels, N_of_points=1)[source]

break down read_number function into two steps 1) read buffer 2) convert data (this function)

convert buffer data into array

Parameters
buffer :: bytes string

raw data from the serial output buffer

N_of_channels :: integer

number of channels to read

N_of_points :: integer, optional

number of channels to datapoints to read, default value is 1

Returns
array :: numpy.ndarray

numpy array

Examples

>>> arr = driver.read_number(buffer = raw_data, N_of_channels = 4, N_of_points = 2)
flush(port=None, input=True, output=True)[source]

flushes input and output buffers of a given port

Parameters
port :: ‘’serial.serialposix.Serial’’

pyserial port object, default is None. If None takes self.port

input :: flag, optional

boolean flag whether to flush input port. default is True

output :: flag, optional

boolean flag whether to flush output port. default is True

Examples

>>> driver.flush(port)
init()[source]

orderly initialization of the DI-245 driver object

Examples

>>> driver.init()
kill()[source]

orderly stop and deletion of the object

Examples

>>> driver.stop_scan()
query(command, port=None, Nbytes=None)[source]

query is a write-read command

Parameters
command :: string

input command written in serial port input buffer

port :: ‘’serial.serialposix.Serial’’

pyserial port object

Nbytes :: integer

number of bytes expected as a result of command execution

Returns
string :: str

response string

Examples

>>> query.
read(Nbytes=None, port=None, timeout=10)[source]

read from serial port buffer

Parameters
Nbytes :: integer, optpional

specify how many bytes to read. the default value makes this command behave as readline, will read entire buffer.

port :: ‘’serial.serialposix.Serial’’, optional

pyserial port object. if left default, port will become self.port from the driver class.

timeout :: float
Returns
string :: str

string representation of read data from serial buffer

Examples

>>> driver.read()
read_buffer(N_of_channels, N_of_points=1)[source]

break down read_number function into two steps 1) read buffer (this function) 2) convert data

reads data from output serial buffer

Parameters
N_of_channels :: integer

number of channels to read

N_of_points :: integer, optional

number of channels to datapoints to read, default value is 1

Returns
buffer :: bytes string

raw data from the serial output buffer

Examples

>>> raw_data = driver.read_number(N_of_channels = 4, N_of_points = 2)
read_number(N_of_channels, N_of_points=1)[source]

reads N channels(N_of_channels) with N points(N_of_points) and puts them in an array (N channels x N points)

Parameters
N_of_channels :: integer

number of channels to read

N_of_points :: integer, optional

number of channels to datapoints to read, default value is 1

Returns
array :: numpy.ndarray

numpy array

Examples

>>> arr = driver.read_number(N_of_channels = 4, N_of_points = 2)
>>> arr.shape
(4,2)
start_scan()[source]

starts data acquisition. issues start command “S1” that initializes data stream from the DI 245

Examples

>>> driver.start_scan()
stop()[source]

stop current data acquisition. issues start command “S0” that initializes data stream from the DI 245

Examples

>>> driver.stop_scan()
stop_scan()[source]

stop current data acquisition. issues start command “S0” that initializes data stream from the DI 245

Examples

>>> driver.stop_scan()
use_com_port(serial_number=None)[source]
  1. connect to the serial port in self.available_ports(N)

  2. stops scanning if one is in progress

  3. tries to set buffer size

property objects that return a list of com ports that have DI245 in the description.

Parameters
serial_number :: str , optional

serial number of the device as a string. If left blank the first avaialable DI245 will be selected.

Returns
port :: ‘’serial.serialposix.Serial’’

pyserial port object

Examples

>>> port = driver.use_com_port(serial_number = '56671FE4A')
>>> port
Serial<id=0x3e18c30, open=True>(port='COM23', baudrate=115200, bytesize=8, parity='N', stopbits=1, timeout=0.1, xonxoff=False, rtscts=True, dsrdtr=False)
property waiting

returns number of bytes waiting in the serail buffer (in, out)

Parameters
port :: optional

serial port object

Returns
waiting :: tuple

tuple representaiotn of number of bytes waiting in input and output buffers

Examples

>>> driver.waiting()
(0,0)
write(command, port=None)[source]

write into serial port buffer

Parameters
command :: string

input command written in serial port input buffer

port :: ‘’serial.serialposix.Serial’’

pyserial port object

Returns
flag :: boolean

boolean

Examples

>>> driver.write(b'S0')