"""
Description:
This module is a wrapper of VPixx low-level library for Python.
It provides all functions found in "Libdpx.h", as well as the error codes "defined".
The first section is the list of all functions available to the user.
The second section is the list of all error codes.
The last section provides short descriptions for each error codes.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Copyright (C) 2008-2017 VPixx Technologies
"""
import platform, os
import ctypes
import re
import sys
#from typing_extensions import ParamSpec
import numpy as np
import math
sys_platform = platform.system()
os_64bit = sys.maxsize > 2**32
path = os.path.dirname(os.path.realpath(__file__))
#change working directory to be able to load implic dll dependencies
cwd = os.getcwd()
os.chdir(path)
if sys_platform == 'Windows':
if os_64bit:
path += os.sep + 'lib' + os.sep + 'win_amd64'
os.chdir(path)
print(path)
DPxDll = ctypes.CDLL(os.path.join(path,"libdpx.dll"))
else:
path += os.sep + 'lib' + os.sep + 'win32'
os.chdir(path)
DPxDll = ctypes.CDLL(os.path.join(path,"libdpx.dll"))
elif sys_platform == 'Linux':
path += os.sep + 'lib' + os.sep + 'linux_x86_64'
os.chdir(path)
DPxDll = ctypes.cdll.LoadLibrary(os.path.join(path,"libdpx.so"))
elif (sys_platform == 'Darwin') or (sys_platform == 'Mac'):
path += os.sep + 'lib' + os.sep + 'mac'
DPxDll = ctypes.cdll.LoadLibrary(os.path.join(path,"libdpx.dylib"))
else:
raise Exception('OS Not Recognized')
#restore working directory
os.chdir(cwd)
DPXREG_SCHED_CTRL_RATE_HZ = 0 # rateValue is updates per second, maximum 96 kHz
DPXREG_SCHED_CTRL_RATE_XVID = 16 # rateValue is updates per video frame, maximum 96 kHz
DPXREG_SCHED_CTRL_RATE_NANO = 32 # rateValue is update period in nanoseconds, minimum 10417 ns
#unsigned char* TPxGetImagePtr(int *height, int *width)
_TPxGetImagePtrCall = DPxDll['TPxGetImagePtr']
_TPxGetImagePtrCall.restype = ctypes.POINTER(ctypes.c_byte)
_TPxGetImagePtrCall.argtypes = [ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_int)]
[docs]def TPxGetImagePtr():
"""Allocates memory for the image data to be stored in ram and return a int pointing to it.
Args:
height (int): Height in pixel of the image.
width (int): Width in pixel of the image.
Returns:
ctypes.c_uint pointer : Pointing to the image data
NULL, if problem with malloc of ram reading.
:Low-level C definition:
``unsigned char* TPxGetImagePtr(int *height, int *width)``
"""
heightcType = ctypes.c_int(0)
widthcType = ctypes.c_int(0)
imagePtr = _TPxGetImagePtrCall(ctypes.byref(heightcType),ctypes.byref(widthcType))
height = heightcType.value
width = widthcType.value
return imagePtr, height, width
#unsigned short * TPxGetCalibrationImagePtr(int *height, int *width, int imageIndex);
_TPxGetCalibrationImagePtrCall = DPxDll['TPxGetCalibrationImagePtr']
_TPxGetCalibrationImagePtrCall.restype = ctypes.POINTER(ctypes.c_ushort)
_TPxGetCalibrationImagePtrCall.argtypes = [ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_int)]
[docs]def TPxGetCalibrationImagePtr(imageIndex):
"""Allocates memory for the image data to be stored in ram and return a int pointing to it.
Args:
height (int): Height in pixel of the image.
width (int): Width in pixel of the image.
imageIndex (int): Index of the image [0-15].
Returns:
ctypes.c_uint pointer : Pointing to the image data
NULL, if problem with malloc of ram reading.
:Low-level C definition:
``unsigned short * TPxGetCalibrationImagePtr(int *height, int *width, int imageIndex)``
"""
heightcType = ctypes.c_int(0)
widthcType = ctypes.c_int(0)
imagePtr = _TPxGetCalibrationImagePtrCall(ctypes.byref(heightcType),ctypes.byref(widthcType),ctypes.c_int(imageIndex))
height = heightcType.value
width = widthcType.value
image = np.ctypeslib.as_array(imagePtr,shape=(height * width,))
return image, height, width
#void DPxOpen()
_DPxOpenCall = DPxDll['DPxOpen']
_DPxOpenCall.restype = None
[docs]def DPxOpen():
"""Opens VPixx devices.
Must be called before any other DPx functions.
:Low-level C definition:
``void DPxOpen()``
"""
_DPxOpenCall()
#void DPxClose()
_DPxCloseClose = DPxDll['DPxClose']
_DPxCloseClose.restype = None
[docs]def DPxClose():
"""Close currently selected VPixx device.
:Low-level C definition:
``void DPxClose()``
"""
_DPxCloseClose()
#void DPxUpdateRegCache()
_DPxUpdateRegCacheCall = DPxDll['DPxUpdateRegCache']
_DPxUpdateRegCacheCall.restype = None
[docs]def DPxUpdateRegCache():
"""Updates the local register cache.
DPxWriteRegCache, then readback registers over USB into local cache
:Low-level C definition:
``void DPxUpdateRegCache()``
"""
_DPxUpdateRegCacheCall()
#void DPxReadRam(unsigned address, unsigned length, void* buffer)
_DPxGetWriteRamBuffSize = DPxDll['DPxGetWriteRamBuffSize']
_DPxGetWriteRamBuffSize.restype = ctypes.c_int
def DPxGetWriteRamBuffSize():
return _DPxGetWriteRamBuffSize()
#void DPxReadRam(unsigned address, unsigned length, void* buffer)
DPxReadRamCall = DPxDll['DPxReadRam']
[docs]def DPxReadRam(address, length):
"""Reads a block of VPixx RAM into a local buffer.
Args:
address (int): Any even value equal to or greater than zero.
length (int): Any value from zero to the RAM size.
Returns:
list: Values taken from RAM.
:Low-level C definition:
``void DPxReadRam(unsigned address, unsigned length, void* buffer)``
:Example:
>>> from _libdpx import *
>>>
>>> DPxOpen()
>>>
>>> # Here is a list with the data to write in RAM.
>>> data = [1,2,3,4,5,6]
>>> DPxWriteRam(address= 42, int_list= data)
>>>
>>> DPxUpdateRegCache()
>>>
>>> print'DPxReadRam() = ', DPxReadRam(address= 42, length= 6)
>>>
>>> DPxClose()
"""
intList = [0]*int(length)
intSize = ctypes.sizeof(ctypes.c_ushort)
itemCount = len(intList)
totalSize = intSize * itemCount
# Create a c-type array of itemCount length of ushorts initialized with intList
packedData = (ctypes.c_ushort * itemCount)(*intList)
DPxReadRamCall(ctypes.c_uint(int(address)), ctypes.c_uint(totalSize), packedData)
returnData = np.ctypeslib.as_array(packedData,shape=(length,))
return returnData
#void DPxWriteRam(unsigned address, unsigned length, void* buffer)
_DPxWriteRamCall = DPxDll['DPxWriteRam']
_DPxWriteRamCall.restype = None
[docs]def DPxWriteRam(address, int_list):
"""Writes a local buffer into VPixx RAM.
Args:
address (int): Any even value equal to or greater than zero.
int_list (int): ``int_list`` is a list which will fill the RAM data. The length of RAM used is based on the length of ``int_list``. It can't be greater than RAM size.
:Low-level C definition:
``void DPxWriteRam(unsigned address, unsigned length, void* buffer)``
See Also:
:class:`DPxGetRamSize`
:Example:
>>> from _libdpx import *
>>>
>>> DPxOpen()
>>>
>>> # Here is a list with the data to write in RAM.
>>> data = [1,2,3,4,5,6]
>>> DPxWriteRam(address= 42, int_list= data)
>>>
>>> DPxUpdateRegCache()
>>>
>>> print'DPxReadRam() = ', DPxReadRam(address= 42, length= 6)
>>>
>>> DPxClose()
"""
if type(int_list) is list:
int_size = ctypes.sizeof(ctypes.c_ushort)
item_count = len(int_list)
total_size = int_size * item_count
packed_data = (ctypes.c_ushort * item_count)(*int_list)
_DPxWriteRamCall(ctypes.c_uint(int(address)), ctypes.c_ushort(total_size), packed_data)
else:
_DPxWriteRamCall(ctypes.c_uint(address), ctypes.sizeof(int_list), ctypes.byref(int_list))
#void DPxWriteRegCache()
_DPxWriteRegCacheCall = DPxDll['DPxWriteRegCache']
_DPxWriteRegCacheCall.restype = None
[docs]def DPxWriteRegCache():
"""Write local register cache to VPixx device over USB.
:Low-level C definition:
``void DPxWriteRegCache()``
"""
_DPxWriteRegCacheCall()
#void DPxWriteRegCacheAfterVideoSync()
_DPxWriteRegCacheAfterVideoSyncCall = DPxDll['DPxWriteRegCacheAfterVideoSync']
_DPxWriteRegCacheAfterVideoSyncCall.restype = None
[docs]def DPxWriteRegCacheAfterVideoSync():
"""Write local register cache to VPixx device over USB on the next video frame.
This function is like DPxWriteRegCache, but the device only writes the registers on leading edge of next vertical sync pulse.
:Low-level C definition:
``void DPxWriteRegCacheAfterVideoSync()``
"""
_DPxWriteRegCacheAfterVideoSyncCall()
_DPxUpdateRegCacheAfterVideoSyncCall = DPxDll['DPxUpdateRegCacheAfterVideoSync']
_DPxUpdateRegCacheAfterVideoSyncCall.restype = None
[docs]def DPxUpdateRegCacheAfterVideoSync():
"""Updates local register cache with VPixx device.
This function is like DPxUpdateRegCache, but the device only writes the registers on the leading edge
of the next vertical sync pulse.
:Low-level C definition:
``void DPxUpdateRegCacheAfterVideoSync()``
"""
_DPxUpdateRegCacheAfterVideoSyncCall()
#void DPxWriteRegCacheAfterPixelSync(int nPixels, unsigned char* pixelData, int timeout)
_DPxWriteRegCacheAfterPixelSyncCall = DPxDll['DPxWriteRegCacheAfterPixelSync']
_DPxWriteRegCacheAfterPixelSyncCall.restype = None
_DPxWriteRegCacheAfterPixelSyncCall.argtype = [ctypes.c_int, ctypes.POINTER(ctypes.c_ubyte), ctypes.c_int]
[docs]def DPxWriteRegCacheAfterPixelSync(pixelData, timeout=255):
"""Write local register cache to VPixx device over USB.
This function is like DPxWriteRegCache, but it waits for a pixel sync sequence.
Args:
pixelData (list, tuple, or numpy array): The requested pattern for PSync.
Formatted such that the array is shape (3*N,) or (N,3) where 'N'
is the number of RGB pixel triplets.
timeout (int): Maximum time to wait before a PSync in video frames.
Exceptions:
1) pixelData is 1D and its length is not divisible by 3 or pixelData is
2D but does not have 3 columns or has more than 8 rows
2) pixelData contains values outside of the range [0,255]
3) timeout is not an integer or is outside of the range [0,65535]
:Low-level C definition:
``void DPxWriteRegCacheAfterPixelSync(int nPixels, unsigned char* pixelData, int timeout)``
"""
pixelData = np.array(pixelData)
if len(pixelData.shape)==1 and not np.remainder(pixelData.size,3):
nPixels = pixelData.size // 3
elif len(pixelData.shape)==2 and pixelData.shape[1]==3 and pixelData.shape[0]<9:
nPixels = pixelData.shape[0]
else:
raise Exception('"pixelData" must be shaped as (3*N,) or (N,3) and cannot contain more than 8 rows.')
if (pixelData < 0).any() or (pixelData > 255).any():
raise Exception('"pixelData" must only contains values in the interval [0,255].')
if not isinstance(timeout,int) or timeout < 0 or timeout > 65535:
raise Exception('"timeout" must be an integer in the interval [0,65535].')
p_pixelData = (ctypes.c_char*pixelData.size)(*pixelData.astype('uint8').flatten().tolist())
_DPxWriteRegCacheAfterPixelSyncCall(nPixels, p_pixelData, timeout)
#int DPxSpiRead(int spiAddr, int nReadBytes, char* readBuffer, PercentCompletionCallback percentCompletionCallback)
_DPxSpiReadCall = DPxDll['DPxSpiRead']
_DPxSpiReadCall.restype = None
[docs]def DPxSpiRead(address, nReadBytes, spiBuffer=None): #NOTE (GMarin # 1 # 23/03/18): Changed built-in symbol buffer to spiBuffer
"""Read a SPI block of any size.
Assumes that spiAddr starts on a 256-byte boundary.
Args:
address (int): Any even value equal to or greater than zero.
:Low-level C definition:
``int DPxSpiRead(int spiAddr, int nReadBytes, char* readBuffer, PercentCompletionCallback percentCompletionCallback)``
"""
if not(spiBuffer):
p_readBuffer = ctypes.create_string_buffer(nReadBytes)
_DPxSpiReadCall(ctypes.c_int(address), ctypes.c_int(nReadBytes), ctypes.byref(p_readBuffer), None)
return_value = (ctypes.c_ubyte * nReadBytes).from_buffer_copy(p_readBuffer)
return return_value
else:
try:
_DPxSpiReadCall(ctypes.c_int(address), ctypes.c_int(nReadBytes), ctypes.byref(spiBuffer), None)
return True
except:
return False
[docs]def DPxReadProductionInfo(address=None):
"""Read a SPI block and return some production information.
Args:
address (int): Any even value equal to or greater than zero.
Returns:
dictionary : Production informations
"""
if not(address):
if DPxIsDatapixx():
address = 0x1F0000
elif DPxIsDatapixx3():
address = 0x1FF1000
elif DPxIsTrackpixx():
address = 0xFF0000
elif DPxIsIOHub():
info = {'Part Number': 'Not found',
'S/N':'Not found',
'Shipping Date':'Not found',
'Expiration Date':'Not found',
'Assembly REV':'Not found'}
return info
else:
address = 0x7F0000
try:
p_readBuffer = ctypes.create_string_buffer(256)
_DPxSpiReadCall(ctypes.c_int(address), ctypes.c_int(256), ctypes.byref(p_readBuffer), None)
text = p_readBuffer.value.decode('utf-8').split(', ')
text[0] = text[0].strip()
text[1] = text[1].split('S/N:')[1]
text[1] = text[1].strip()
text[2] = text[2].split('Shipping date:')[1]
text[2] = text[2].strip()
text[3] = text[3].split('Assembly REV:')[1]
text[3] = text[3].strip()
info = {'Part Number': text[0],
'S/N':text[1],
'Shipping Date':text[2],
'Assembly REV': text[3]}
temp = info['Shipping Date'].split()
temp[0] = temp[0].strip()
info['Expiration Date'] = temp[0] +" "+ temp[1] +" "+ str(int(temp[2])+2)
if '\n' in info['Assembly REV']:
info['Assembly REV'] = (info['Assembly REV'].split('\n'))[0]
except:
info = {'Part Number': 'Not found',
'S/N':'Not found',
'Shipping Date':'Not found',
'Expiration Date':'Not found',
'Assembly REV':'Not found'}
return info
#int DPxSpiWrite(int spiAddr, int nWriteBytes, char* writeBuffer, PercentCompletionCallback percentCompletionCallback)
_DPxSpiWriteCall = DPxDll['DPxSpiWrite']
_DPxSpiWriteCall.restype = ctypes.c_int
[docs]def DPxSpiWrite(address, writeBuffer):
"""Write a SPI block of any size.
Assumes that spiAddr starts on a 256-byte boundary.
If nWriteBytes is not a multiple of 256 bytes, the last page is padded with 0.
Args:
address (int): Any even value equal to or greater than zero.
writeBuffer (int) : value to write
Returns:
ctypes.c_int : Error code (0 if no error)
:Low-level C definition:
``int DPxSpiWrite(int spiAddr, int nWriteBytes, char* writeBuffer, PercentCompletionCallback percentCompletionCallback)``
"""
return _DPxSpiWriteCall(address, ctypes.sizeof(writeBuffer), ctypes.byref(writeBuffer), None)
#int DPxSpiErase(int spiAddr, int nEraseBytes, PercentCompletionCallback percentCompletionCallback)
_DPxSpiEraseCall = DPxDll['DPxSpiErase']
_DPxSpiEraseCall.restype = ctypes.c_int
[docs]def DPxSpiErase(address, n_byte):
"""Erase (sets to 1) a SPI block of any size.
Assumes that spiAddr starts on a 64kB boundary.
The SPI is erased in 64kB chunks; if nEraseBytes is not a 64k multiple, it is rounded up to the next 64k multiple.
Args:
address (int): Any even value equal to or greater than zero.
n_byte (int) : Count to erease.
Returns:
ctypes.c_int : Error code (0 if no error)
:Low-level C definition:
``int DPxSpiErase(int spiAddr, int nEraseBytes, PercentCompletionCallback percentCompletionCallback)``
"""
return _DPxSpiEraseCall(address, n_byte, None)
#void DPxSpiModify(int spiAddr, int nWriteBytes, unsigned char* writeBuffer)
_DPxSpiModifyCall = DPxDll['DPxSpiModify']
_DPxSpiModifyCall.restype = None
[docs]def DPxSpiModify(address, nWriteBytes, writeBuffer):
"""Modify a region of SPI within a single 64kB page
Args:
address (int): Any even value equal to or greater than zero.
nWriteBytes (int) : Count to write.
writeBuffer (ctypes.c_int) : Value to write
Returns:
ctypes.c_int : Error code (0 if no error)
:Low-level C definition:
``void DPxSpiModify(int spiAddr, int nWriteBytes, unsigned char* writeBuffer)``
"""
_DPxSpiModifyCall(address, nWriteBytes, ctypes.byref(writeBuffer))
#void DPxUpdateRegCacheAfterPixelSync(int nPixels, unsigned char* pixelData, int timeout)
_DPxUpdateRegCacheAfterPixelSyncCall = DPxDll['DPxUpdateRegCacheAfterPixelSync']
_DPxUpdateRegCacheAfterPixelSyncCall.restype = None
_DPxUpdateRegCacheAfterPixelSyncCall.argtype = [ctypes.c_int, ctypes.POINTER(ctypes.c_ubyte), ctypes.c_int]
[docs]def DPxUpdateRegCacheAfterPixelSync(pixelData, timeout=255):
"""Writes local register cache to VPixx device over USB, using Pixel Sync timing.
This function is like DPxUpdateRegCache, but waits for a pixel sync sequence before executing.
Args:
pixelData (list, tuple, or numpy array): The requested pattern for PSync.
Formatted such that the array is shape (3*N,) or (N,3) where 'N'
is the number of RGB pixel triplets.
timeout (int): Maximum time to wait before a PSync in video frames.
Exceptions:
1) pixelData is 1D and its length is not divisible by 3 or pixelData is
2D but does not have 3 columns or has more than 8 rows
2) pixelData contains values outside of the range [0,255]
3) timeout is not an integer or is outside of the range [0,65535]
:Low-level C definition:
``void DPxUpdateRegCacheAfterPixelSync(int nPixels, unsigned char* pixelData, int timeout)``
"""
pixelData = np.array(pixelData)
if len(pixelData.shape)==1 and not np.remainder(pixelData.size,3):
nPixels = pixelData.size // 3
elif len(pixelData.shape)==2 and pixelData.shape[1]==3 and pixelData.shape[0]<9:
nPixels = pixelData.shape[0]
else:
raise Exception('"pixelData" must be shaped as (3*N,) or (N,3) and cannot contain more than 8 rows.')
if (pixelData < 0).any() or (pixelData > 255).any():
raise Exception('"pixelData" must only contains values in the interval [0,255].')
if not isinstance(timeout,int) or timeout < 0 or timeout > 65535:
raise Exception('"timeout" must be an integer in the interval [0,65535].')
p_pixelData = (ctypes.c_char*pixelData.size)(*pixelData.astype('uint8').flatten().tolist())
_DPxUpdateRegCacheAfterPixelSyncCall(nPixels, ctypes.byref(p_pixelData), timeout)
#int DPxIsDatapixx()
_DPxIsDatapixxCall = DPxDll['DPxIsDatapixx']
_DPxIsDatapixxCall.restype = ctypes.c_int
[docs]def DPxIsDatapixx():
"""Verifies if the device is a DATAPixx.
Returns:
int: Non-zero if a DATAPixx was found, zero otherwise.
:Low-level C definition:
``int DPxIsDatapixx()``
"""
return _DPxIsDatapixxCall()
#int DPxIsDatapixx2()
_DPxIsDatapixx2Call = DPxDll['DPxIsDatapixx2']
_DPxIsDatapixx2Call.restype = ctypes.c_int
[docs]def DPxIsDatapixx2():
"""Verifies if the device is a DATAPixx2.
Returns:
int: Non-zero if a DATAPixx2 was found, zero otherwise.
:Low-level C definition:
``int DPxIsDatapixx2()``
"""
return _DPxIsDatapixx2Call()
#int DPxIsDatapixx3()
_DPxIsDatapixx3Call = DPxDll['DPxIsDatapixx3']
_DPxIsDatapixx3Call.restype = ctypes.c_int
[docs]def DPxIsDatapixx3():
"""Verifies if the device is a DATAPixx3.
Returns:
int: Non-zero if a DATAPixx3 was found, zero otherwise.
:Low-level C definition:
``int DPxIsDatapixx3()``
"""
return _DPxIsDatapixx3Call()
#int DPxDetectDevice(int devsel)
_DPxDetectDeviceCall = DPxDll['DPxDetectDevice']
_DPxDetectDeviceCall.restype = ctypes.c_int
[docs]def DPxDetectDevice(devsel, offset = 0 ):
"""Verifies if a specific device exists in the system.
Args:
devsel (string) : Any of the predefined constants.
* **DATAPixx**: DATAPixx.
* **DATAPixx2**: DATAPixx2.
* **VIEWPixx**: VIEWPixx.
* **PROPixx Ctrl**: PROPixx Controller.
* **PROPixx**: PROPixx.
* **TRACKPIXX**
offset (int): Offset if more than one device of same type is connected, 0 by default.
Returns:
int: Non-zero if the device exists, 0 if the device does not exist.
:Low-level C definition:
``int DPxDetectDevice(int devsel)``
"""
#Check if the offset is bad
if ((offset > 10) or (offset <0)) :
return 0
return _DPxDetectDeviceCall(api_constants[devsel.upper().replace(" ", "")] + offset)
#int DPxSelectDevice(int)
_DPxSelectDeviceCall = DPxDll['DPxSelectDevice']
_DPxSelectDeviceCall.restype = ctypes.c_int
_DPxSelectDeviceCall.argtypes = [ctypes.c_int]
[docs]def DPxSelectDevice(devsel, offset = 0):
"""Selects which of the device found in the system should be used.
Args:
devsel (string): Any of the predefined constants.
* **Auto**: Lets the low-level choose the device.
* **DATAPixx**: DATAPixx.
* **DATAPixx2**: DATAPixx2.
* **DATAPixx3**: DATAPixx3.
* **VIEWPixx**: VIEWPixx.
* **PROPixx Ctrl**: PROPixx Controller.
* **PROPixx**: PROPixx.
* **TRACKPIXX**
offset (int): Offset if more than one device of same type is connected, 0 by default.
Returns:
int: Non-zero if the device exists, 0 if the device does not exist.
:Low-level C definition:
``int DPxSelectDevice(int)``
"""
#Check if the offset is bad
if ((offset > 10) or (offset <0)) :
return 0
# Todo, fix the following work around where a selectdevice breaks the table
DPxClearError()
return _DPxSelectDeviceCall(api_constants[devsel.upper().replace(" ", "")] + offset)
#int DPxSelectDeviceSubName(int, char*)
_DPxSelectDeviceSubNameCall = DPxDll['DPxSelectDeviceSubName']
_DPxSelectDeviceSubNameCall.restype = ctypes.c_int
[docs]def DPxSelectDeviceSubName(devsel, name, offset = 0):
"""Select which VPixx device to access by specifying the sub name.
Args:
devsel (string): Any of the predefined constants.
* **Auto**: Lets the low-level choose the device.
* **DATAPixx**: DATAPixx.
* **DATAPixx2**: DATAPixx2.
* **VIEWPixx**: VIEWPixx.
* **PROPixx Ctrl**: PROPixx Controller.
* **PROPixx**: PROPixx.
* **TRACKPIXX**
name (string): Must me a valid custom device sub name.
offset (int): Offset if more than one device of same type is connected, 0 by default.
Returns:
int: Non-zero if the device exists, 0 if the device does not exist.
:Low-level C definition:
``int DPxSelectDeviceSubName(int, char*)``
"""
p_name = ctypes.create_string_buffer(name.encode('utf-8'))
return _DPxSelectDeviceSubNameCall(api_constants[devsel.upper().replace(" ", "")] + offset, p_name)
#int DPxIsReady()
_DPxIsReadyCall = DPxDll['DPxIsReady']
_DPxIsReadyCall.restype = ctypes.c_int
[docs]def DPxIsReady():
"""Verifies if the current device is ready to use.
Returns:
int: Non-zero if the device is ready to use, zero otherwise.
:Low-level C definition:
``int DPxIsReady()``
"""
return _DPxIsReadyCall()
#int DPxGetID()
_DPxGetIDCall = DPxDll['DPxGetID']
_DPxGetIDCall.restype = ctypes.c_int
[docs]def DPxGetID():
"""Gets the VPixx device identifier code.
Returns:
int: Value higher than 0.
:Low-level C definition:
``int DPxGetID()``
"""
return _DPxGetIDCall()
#int DPxIsViewpixx()
_DPxIsViewpixxCall = DPxDll['DPxIsViewpixx']
_DPxIsViewpixxCall.restype = ctypes.c_int
[docs]def DPxIsViewpixx():
"""Verifies if the device is a VIEWPixx.
Returns:
int: Non-zero if a VIEWPixx (VIEWPixx, VIEWPixx /EEG or VIEWPixx /3D) is detected, zero otherwise.
:Low-level C definition:
``int DPxIsViewpixx()``
"""
return _DPxIsViewpixxCall()
#`int DPxIsViewpixx3D()
_DPxIsViewpixx3DCall = DPxDll['DPxIsViewpixx3D']
_DPxIsViewpixx3DCall.restype = ctypes.c_int
[docs]def DPxIsViewpixx3D():
"""Verifies if the device is a VIEWPixx3D.
Returns:
int: Non-zero if a VIEWPixx3D was found, zero otherwise.
:Low-level C definition:
``int DPxIsViewpixx3D()``
"""
return _DPxIsViewpixx3DCall()
#int DPxIsViewpixxEeg()
_DPxIsViewpixxEegCall = DPxDll['DPxIsViewpixxEeg']
_DPxIsViewpixxEegCall.restype = ctypes.c_int
[docs]def DPxIsViewpixxEeg():
"""Verifies if the device is a VIEWPixxEEG.
Returns:
int: Non-zero if a VIEWPixxEEG was found, zero otherwise.
:Low-level C definition:
``int DPxIsViewpixxEeg()``
"""
return _DPxIsViewpixxEegCall()
#int DPxIsViewpixxXL()
_DPxIsViewpixxXLCall = DPxDll['DPxIsViewpixxXL']
_DPxIsViewpixxXLCall.restype = ctypes.c_int
[docs]def DPxIsViewpixxXL():
"""Verifies if the device is a VIEWPixxXL.
Returns:
int: Non-zero if a VIEWPixxXL was found, zero otherwise.
:Low-level C definition:
``int DPxIsViewpixxXL()``
"""
return _DPxIsViewpixxXLCall()
#int DPxIsPropixxCtrl()
_DPxIsPropixxCtrlCall = DPxDll['DPxIsPropixxCtrl']
_DPxIsPropixxCtrlCall.restype = ctypes.c_int
[docs]def DPxIsPropixxCtrl():
"""Verifies if the device is a PROPixx Controller.
Returns:
int: Non-zero if a PROPixx Controller was found, zero otherwise.
:Low-level C definition:
``int DPxIsPropixxCtrl()``
"""
return _DPxIsPropixxCtrlCall()
#int DPxIsPropixx()
_DPxIsPropixxCall = DPxDll['DPxIsPropixx']
_DPxIsPropixxCall.restype = ctypes.c_int
[docs]def DPxIsPropixx():
"""Verifies if the device is a PROPixx.
This function will not detect the PROPixx Controller.
Returns:
int: Non-zero if the device exists, 0 if the device does not exist.
:Low-level C definition:
``int DPxIsPropixx()``
"""
return _DPxIsPropixxCall()
#int DPxIsTrackpixx()
_DPxIsTrackpixxCall = DPxDll['DPxIsTrackpixx']
_DPxIsTrackpixxCall.restype = ctypes.c_int
[docs]def DPxIsTrackpixx():
"""Verifies if the device is a TRACKPixx.
Returns:
int: Non-zero if a TRACKPixx was found. Else if not.
:Low-level C definition:
``int DPxIsTrackpixx()``
"""
return _DPxIsTrackpixxCall()
#int DPxIsIOHub()
_DPxIsIOHubCall = DPxDll['DPxIsIOHub']
_DPxIsIOHubCall.restype = ctypes.c_int
[docs]def DPxIsIOHub():
"""Verifies if the device is a USB IOHub.
Returns:
int: Non-zero if a USB IOHub was found. Else if not.
:Low-level C definition:
``int DPxIsIOHub()``
"""
return _DPxIsIOHubCall()
#int DPxGetRamSize()
_DPxGetRamSizeCall = DPxDll['DPxGetRamSize']
_DPxGetRamSizeCall.restype = ctypes.c_uint
[docs]def DPxGetRamSize():
"""Gets the number of bytes of RAM in the VPixx device.
Returns:
int: Value higher than 0.
:Low-level C definition:
``int DPxGetRamSize()``
"""
return _DPxGetRamSizeCall()
#int DPxGetPartNumber()
_DPxGetPartNumberCall = DPxDll['DPxGetPartNumber']
_DPxGetPartNumberCall.restype = ctypes.c_int
[docs]def DPxGetPartNumber():
"""Gets the integer part number of the VPixx Device.
Returns:
int: Value higher than 0.
:Low-level C definition:
``int DPxGetPartNumber()``
"""
return _DPxGetPartNumberCall()
#int DPxGetFirmwareRev()
_DPxGetFirmwareRevCall = DPxDll['DPxGetFirmwareRev']
_DPxGetFirmwareRevCall.restype = ctypes.c_int
[docs]def DPxGetFirmwareRev():
"""Gets the VPixx Device firmware revision.
Returns:
int: Value higher than 0.
:Low-level C definition:
``int DPxGetFirmwareRev()``
"""
return _DPxGetFirmwareRevCall()
#int DPxGetCPLDFirmwareRev()
_DPxGetCPLDFirmwareRevCall = DPxDll['DPxGetCPLDFirmwareRev']
_DPxGetCPLDFirmwareRevCall.restype = ctypes.c_int
[docs]def DPxGetCPLDFirmwareRev():
"""Gets the VPixx Device firmware revision.
Returns:
int: Value higher than 0.
:Low-level C definition:
``int DPxGetFirmwareRev()``
"""
return _DPxGetCPLDFirmwareRevCall()
#double DPxGetSupplyVoltage()
_DPxGetSupplyVoltageCall = DPxDll['DPxGetSupplyVoltage']
_DPxGetSupplyVoltageCall.restype = ctypes.c_double
[docs]def DPxGetSupplyVoltage():
"""Gets the voltage being supplied from +5V supply.
Returns:
float: Value higher than 0 in Volt.
:Low-level C definition:
``double DPxGetSupplyVoltage()``
"""
return _DPxGetSupplyVoltageCall()
#double DPxGetSupplyCurrent()
_DPxGetSupplyCurrentCall = DPxDll['DPxGetSupplyCurrent']
_DPxGetSupplyCurrentCall.restype = ctypes.c_double
[docs]def DPxGetSupplyCurrent():
"""Gets the current being supplied from the 5V power supply.
Returns:
float: Value higher than 0 in Amperes.
:Low-level C definition:
``double DPxGetSupplyCurrent()``
"""
return _DPxGetSupplyCurrentCall()
#double DPxGetSupply2Voltage()
_DPxGetSupply2VoltageCall = DPxDll['DPxGetSupply2Voltage']
_DPxGetSupply2VoltageCall.restype = ctypes.c_double
[docs]def DPxGetSupply2Voltage():
"""Gets the voltage being supplied from the 12V power supply.
Returns:
float: Value higher than 0 in Volts.
:Low-level C definition:
``double DPxGetSupply2Voltage()``
"""
return _DPxGetSupply2VoltageCall()
#double DPxGetSupply2Current()
_DPxGetSupply2CurrentCall = DPxDll['DPxGetSupply2Current']
_DPxGetSupply2CurrentCall.restype = ctypes.c_double
[docs]def DPxGetSupply2Current():
"""Gets the current being supplied from the +12V power supply.
Returns:
float: Value higher than 0 in Amperes.
:Low-level C definition:
``double DPxGetSupply2Current()``
"""
return _DPxGetSupply2CurrentCall()
#int DPxIs5VFault()
_DPxIs5VFaultCall = DPxDll['DPxIs5VFault']
_DPxIs5VFaultCall.restype = ctypes.c_int
[docs]def DPxIs5VFault():
"""Verifies the state of the 5V power supply.
This function allows the user to know if the VESA and Analog +5V input/output pins are trying to draw more than 500 mA.
Returns:
int: 0 if the current is normal, non-zero otherwise (too much current drawn).
:Low-level C definition:
``int DPxIs5VFault()``
"""
return _DPxIs5VFaultCall()
#int DPxIsPsyncTimeout()
_DPxIsPsyncTimeoutCall = DPxDll['DPxIsPsyncTimeout']
_DPxIsPsyncTimeoutCall.restype = ctypes.c_int
[docs]def DPxIsPsyncTimeout():
"""Verifies if a timeout occurred on the pixel synchronization.
This function allows the user to know if the VESA and Analog +5V input/output pins are trying to draw more than 500 mA.
Returns:
int: Non-zero if a timeout occurred, zero otherwise.
:Low-level C definition:
``int DPxIsPsyncTimeout()``
"""
return _DPxIsPsyncTimeoutCall()
#int DPxIsRamOffline()
_DPxIsRamOfflineCall = DPxDll['DPxIsRamOffline']
_DPxIsRamOfflineCall.restype = ctypes.c_int
[docs]def DPxIsRamOffline():
"""Verifies if the RAM controller is offline.
Returns:
int: Zero if the RAM is online, non-zero otherwise.
:Low-level C definition:
``int DPxIsRamOffline()``
"""
return _DPxIsRamOfflineCall()
#double DPxGetTempCelcius()
_DPxGetTempCelciusCall = DPxDll['DPxGetTempCelcius']
_DPxGetTempCelciusCall.restype = ctypes.c_double
[docs]def DPxGetTempCelcius():
"""Gets the temperature inside a VPixx device chassis.
When used with a PROPixx, this function gets the temperature of the Receiver DVI.
When used with other devices, it gets the chassis temperature.
Returns:
float: Temperature in degrees Celsius.
:Low-level C definition:
``double DPxGetTempCelcius()``
"""
return _DPxGetTempCelciusCall()
#double DPxGetTemp2Celcius()
_DPxGetTemp2CelciusCall = DPxDll['DPxGetTemp2Celcius']
_DPxGetTemp2CelciusCall.restype = ctypes.c_double
[docs]def DPxGetTemp2Celcius():
"""Gets the temperature inside a VPixx device.
This function gets the board temperature of any VPixx device except the DATAPixx.
Returns:
float: Temperature in degrees Celsius.
:Low-level C definition:
``double DPxGetTemp2Celcius()``
"""
return _DPxGetTemp2CelciusCall()
#double DPxGetTemp3Celcius()
_DPxGetTemp3CelciusCall = DPxDll['DPxGetTemp3Celcius']
_DPxGetTemp3CelciusCall.restype = ctypes.c_double
[docs]def DPxGetTemp3Celcius():
"""Gets the FPGA temperature inside a VPixx device.
This function cannot be used with a DATAPixx.
Returns:
float: Temperature in degrees Celsius.
:Low-level C definition:
``double DPxGetTemp3Celcius()``
"""
return _DPxGetTemp3CelciusCall()
#double DPxGetTempFarenheit()
_DPxGetTempFarenheitCall = DPxDll['DPxGetTempFarenheit']
_DPxGetTempFarenheitCall.restype = ctypes.c_double
[docs]def DPxGetTempFarenheit():
"""Gets the temperature inside a VPixx device in Fahrenheit.
Returns:
float: Temperature in degrees Fahrenheit.
:Low-level C definition:
``double DPxGetTempFarenheit()``
"""
return _DPxGetTempFarenheitCall()
#double DPxGetTime()
_DPxGetTimeCall = DPxDll['DPxGetTime']
_DPxGetTimeCall.restype = ctypes.c_double
[docs]def DPxGetTime():
"""Gets the device time since last power up.
Returns:
float: Time in seconds.
:Low-level C definition:
``double DPxGetTime()``
"""
return _DPxGetTimeCall()
#void DPxGetMarker()
_DPxSetMarkerCall = DPxDll['DPxSetMarker']
_DPxSetMarkerCall.restype = None
[docs]def DPxSetMarker():
"""Latches the current time value into the marker register.
:Low-level C definition:
``void DPxGetMarker()``
See Also:
:class:`DPxSetMarker`, :class:`DPxGetNanoMarker`
"""
return _DPxSetMarkerCall()
#double DPxGetMarker()
_DPxGetMarkerCall = DPxDll['DPxGetMarker']
_DPxGetMarkerCall.restype = ctypes.c_double
[docs]def DPxGetMarker():
"""Gets the current marker from the register.
This function allows the user to get the marker value previously latched.
Returns:
float: Time in seconds.
:Low-level C definition:
``double DPxGetMarker()``
See Also:
:class:`DPxSetMarker`, :class:`DPxGetNanoMarker`
"""
return _DPxGetMarkerCall()
#void DPxGetNanoTime(unsigned *nanoHigh32, unsigned *nanoLow32)
_DPxGetNanoTimeCall = DPxDll['DPxGetNanoTime']
_DPxGetNanoTimeCall.restype = None
[docs]def DPxGetNanoTime():
"""Gets the current time since power up with high precision.
This function allows the user to get the marker value previously latched.
Returns:
tuple: Time in seconds.
:Low-level C definition:
``void DPxGetNanoTime(unsigned *nanoHigh32, unsigned *nanoLow32)``
See Also:
:class:`DPxSetMarker`, :class:`DPxGetNanoMarker`
"""
nanoLow32 = 0
nanoHigh32 = 0
p_nanoLow32 = ctypes.c_uint(nanoLow32)
p_nanoHigh32 = ctypes.c_uint(nanoHigh32)
_DPxGetNanoTimeCall(ctypes.byref(p_nanoLow32), ctypes.byref(p_nanoHigh32))
return (p_nanoLow32.value, p_nanoHigh32.value)
#void DPxGetNanoMarker(unsigned *nanoHigh32, unsigned *nanoLow32)
_DPxGetNanoMarkerCall = DPxDll['DPxGetNanoMarker']
_DPxGetNanoMarkerCall.restype = None
[docs]def DPxGetNanoMarker():
"""Gets the current marker from the register with high precision.
This function allows the user to get the marker value previously latched.
Returns:
tuple: Time in seconds.
:Low-level C definition:
``void DPxGetNanoMarker(unsigned *nanoHigh32, unsigned *nanoLow32)``
See Also:
:class:`DPxSetMarker`, :class:`DPxGetNanoMarker`
"""
LowMrk32 = 0
HighMrk32 = 0
p_LowMrk32 = ctypes.c_uint(LowMrk32)
p_HighMrk32 = ctypes.c_uint(HighMrk32)
_DPxGetNanoMarkerCall(ctypes.byref(p_LowMrk32), ctypes.byref(p_HighMrk32))
return (p_LowMrk32.value, p_HighMrk32.value)
#void DPxEnableCalibReload()
_DPxEnableCalibReloadCall = DPxDll['DPxEnableCalibReload']
_DPxEnableCalibReloadCall.restype = None
[docs]def DPxEnableCalibReload():
""" Reload LED, DAC and ADC hardware calibration tables
:Low-level C definition:
``void DPxEnableCalibReload()``
"""
_DPxEnableCalibReloadCall()
#int DPxGetDacNumChans()
_DPxGetDacNumChansCall = DPxDll['DPxGetDacNumChans']
_DPxGetDacNumChansCall.restype = ctypes.c_int
[docs]def DPxGetDacNumChans():
"""Gets the number of channels available.
This method returns the number of DAC channels in the system (4 in current implementation)
Returns:
int: Number of channels.
:Low-level C definition:
``int DPxGetDacNumChans()``
"""
return _DPxGetDacNumChansCall()
#DPxGetDacRange(int channel, double *minV, double *maxV)
_DPxGetDacRangeCall = DPxDll['DPxGetDacRange']
[docs]def DPxGetDacRange(channel):
"""Gets the voltage range.
This method returns the voltage range; For a VIEWPixx: +-10V, for a DATAPixx: +-10V for ch0/1, +-5V for ch2/3
Args:
channel (int): Channel number
Returns:
int: voltage range.
:Low-level C definition:
``DPxGetDacRange(int channel, double *minV, double *maxV)``
"""
minV = 0
maxV = 0
p_minV = ctypes.c_double(minV)
p_maxV = ctypes.c_double(maxV)
_DPxGetDacRangeCall(channel, ctypes.byref(p_minV), ctypes.byref(p_maxV))
return (p_minV.value, p_maxV.value)
#void DPxSetDacValue(int value, int channel)
_DPxSetDacValueCall = DPxDll['DPxSetDacValue']
_DPxSetDacValueCall.argtypes = [ctypes.c_int, ctypes.c_int]
_DPxSetDacValueCall.restype = None
[docs]def DPxSetDacValue(value, channel):
"""Sets the current value of a channel.
This method allows the user to set the 16-bit 2's complement signed value for one DAC channel.
In other words, this means that you have access to values between -32768 and +32768. For a positive
number, you will simply need to leave it as is. For a negative number, since we are using signed, you will
need to convert it to the 2's complement representation.
Args:
value (int): Value of the channel. It is a 16-bit 2's complement signed number.
channel (int): Channel number.
:Low-level C definition:
``void DPxSetDacValue(int value, int channel)``
See Also:
:class:`DPxGetDacValue`
"""
return _DPxSetDacValueCall(value, channel)
#int DPxGetDacValue(int channel)
_DPxGetDacValueCall = DPxDll['DPxGetDacValue']
_DPxGetDacValueCall.restype = ctypes.c_int
_DPxGetDacValueCall.argtypes = [ctypes.c_int]
[docs]def DPxGetDacValue(channel):
"""Gets the value for one DAC channel.
Args:
channel (int): Channel number.
Returns:
int: A 16-bit 2's complement signed value.
:Low-level C definition:
``int DPxGetDacValue(int channel)``
See Also:
:class:`DPxSetDacValue`
"""
return _DPxGetDacValueCall(channel)
#void DPxSetDacVoltage(double voltage, int channel)
_DPxSetDacVoltageCall = DPxDll['DPxSetDacVoltage']
_DPxSetDacVoltageCall.argtypes = [ctypes.c_double, ctypes.c_int]
_DPxSetDacVoltageCall.restype = None
[docs]def DPxSetDacVoltage(voltage, channel):
"""Sets the voltage for one DAC channel.
For channels 0 and 1: |plusmn| 10V for ch0/1. For channels 2 and 3: |plusmn| 5V.
Args:4
voltage (float): Voltage of the channel.
channel (int): Channel number.
:Low-level C definition:
``void DPxSetDacVoltage(double voltage, int channel)``
See Also:
:class:`DPxGetDacVoltage`
"""
return _DPxSetDacVoltageCall(voltage, channel)
#double DPxGetDacVoltage(int channel)
_DPxGetDacVoltageCall = DPxDll['DPxGetDacVoltage']
_DPxGetDacVoltageCall.restype = ctypes.c_double
_DPxGetDacVoltageCall.argtypes = [ctypes.c_int]
[docs]def DPxGetDacVoltage(channel):
"""Gets the value for one DAC channel.
Args:
channel (int): Channel number.
* For channel 0 and 1: |plusmn| 10V.
* For channel 2 and 3: |plusmn| 5V.
Returns:
float: Voltage.
:Low-level C definition:
``double DPxGetDacVoltage(int channel)``
See Also:
:class:`DPxSetDacValue`
.. |plusmn| unicode:: U+000B1 .. PLUS-MINUS SIGN
"""
return _DPxGetDacVoltageCall(channel)
#void DPxEnableDacCalibRaw()
_DPxEnableDacCalibRawDll = DPxDll['DPxEnableDacCalibRaw']
_DPxEnableDacCalibRawDll.restype = None
[docs]def DPxEnableDacCalibRaw():
"""Sets the hardware calibration mode.
Enables DAC "raw" mode, causing DAC data to bypass hardware calibration.
:Low-level C definition:
``void DPxEnableDacCalibRaw()``
See Also:
:class:`DPxDisableDacCalibRaw`
"""
_DPxEnableDacCalibRawDll()
#void DPxDisableDacCalibRaw()
_DPxDisableDacCalibRawCall = DPxDll['DPxDisableDacCalibRaw']
_DPxDisableDacCalibRawCall.restype = None
[docs]def DPxDisableDacCalibRaw():
"""Sets the hardware calibration mode.
Disables DAC "raw" mode, causing normal DAC hardware calibration.
:Low-level C definition:
``void DPxDisableDacCalibRaw()``
See Also:
:class:`DPxEnableDacCalibRaw`
"""
_DPxDisableDacCalibRawCall()
#int DPxIsDacCalibRaw()
_DPxIsDacCalibRawCall = DPxDll['DPxIsDacCalibRaw']
_DPxIsDacCalibRawCall.restype = ctypes.c_int
[docs]def DPxIsDacCalibRaw():
"""Verifies if the hardware calibration mode is enabled.
Returns:
int: Non-zero if DAC data is bypassing hardware calibration.
:Low-level C definition:
``int DPxIsDacCalibRaw()``
See Also:
:class:`DPxEnableDacCalibRaw`, :class:`DPxDisableDacCalibRaw`
"""
return _DPxIsDacCalibRawCall()
#void DPxEnableDacBuffChan(int channel)
_DPxEnableDacBuffChanCall = DPxDll['DPxEnableDacBuffChan']
_DPxEnableDacBuffChanCall.restype = None
[docs]def DPxEnableDacBuffChan(channel):
"""Enables RAM buffering of a DAC channel.
Args:
channel (int): Channel number.
:Low-level C definition:
``void DPxEnableDacBuffChan(int channel)``
See Also:
:class:`DPxDisableDacBuffChan`, :class:`DPxDisableDacBuffAllChans`
"""
_DPxEnableDacBuffChanCall(ctypes.c_int(channel))
#void DPxDisableDacBuffChan(int channel)
_DPxDisableDacBuffChanCall = DPxDll['DPxDisableDacBuffChan']
_DPxDisableDacBuffChanCall.restype = None
[docs]def DPxDisableDacBuffChan(channel):
"""Disables RAM buffering of a DAC channel.
Args:
channel (int): Channel number.
:Low-level C definition:
``void DPxDisableDacBuffChan(int channel)``
See Also:
:class:`DPxEnableDacBuffChan`, :class:`DPxDisableDacBuffAllChans`
"""
_DPxDisableDacBuffChanCall(ctypes.c_int(channel))
#`void DPxDisableDacBuffAllChans()
_DPxDisableDacBuffAllChansCall = DPxDll['DPxDisableDacBuffAllChans']
_DPxDisableDacBuffAllChansCall.restype = None
[docs]def DPxDisableDacBuffAllChans():
"""Disables RAM buffering of all DAC channels.
:Low-level C definition:
``void DPxDisableDacBuffAllChans()``
See Also:
:class:`DPxEnableDacBuffChan`, :class:`DisableDacBuffChan`
"""
_DPxDisableDacBuffAllChansCall()
#int DPxIsDacBuffChan(int channel)
_DPxIsDacBuffChanCall = DPxDll['DPxIsDacBuffChan']
_DPxIsDacBuffChanCall.restype = ctypes.c_int
[docs]def DPxIsDacBuffChan(channel):
"""Verifies if RAM buffering is enabled for a DAC channel.
Args:
channel (int): Channel number.
Returns:
int: Non-zero if RAM buffering is enabled for a DAC channel.
:Low-level C definition:
``int DPxIsDacBuffChan(int channel)``
See Also:
:class:`DPxEnableDacCalibRaw`, :class:`DPxDisableDacCalibRaw`
"""
return _DPxIsDacBuffChanCall(ctypes.c_int(channel))
#void DPxSetDacBuffBaseAddr(unsigned buffBaseAddr)
_DPxSetDacBuffBaseAddrCall = DPxDll['DPxSetDacBuffBaseAddr']
_DPxSetDacBuffBaseAddrCall.argtypes = [ctypes.c_uint]
_DPxSetDacBuffBaseAddrCall.restype = None
[docs]def DPxSetDacBuffBaseAddr(buffBaseAddr):
"""Sets the DAC RAM buffer start address.
Must be an even value.
Args:
buffBaseAddr (int): Base address.
:Low-level C definition:
``void DPxSetDacBuffBaseAddr(unsigned buffBaseAddr)``
See Also:
:class:`DPxGetDacBuffBaseAddr`
"""
return _DPxSetDacBuffBaseAddrCall(buffBaseAddr)
#unsigned DPxGetDacBuffBaseAddr()
_DPxGetDacBuffBaseAddrCall = DPxDll['DPxGetDacBuffBaseAddr']
_DPxGetDacBuffBaseAddrCall.restype = ctypes.c_uint
[docs]def DPxGetDacBuffBaseAddr():
"""Gets the DAC RAM buffer start address.
Returns:
int: Base address.
:Low-level C definition:
``unsigned DPxGetDacBuffBaseAddr()``
See Also:
:class:`DPxSetDacBuffBaseAddr`
"""
return _DPxGetDacBuffBaseAddrCall()
#void DPxSetDacBuffReadAddr(unsigned buffReadAddr)
_DPxSetDacBuffReadAddrCall = DPxDll['DPxSetDacBuffReadAddr']
_DPxSetDacBuffReadAddrCall.argtypes = [ctypes.c_uint]
_DPxSetDacBuffReadAddrCall.restype = None
[docs]def DPxSetDacBuffReadAddr(buffReadAddr):
"""Sets RAM address from which next DAC datum will be read.
Must be an even value.
Args:
buffReadAddr (int): Read address.
:Low-level C definition:
``void DPxSetDacBuffReadAddr(unsigned buffReadAddr)``
See Also:
:class:`DPxGetDacBuffReadAddr`
"""
return _DPxSetDacBuffReadAddrCall(buffReadAddr)
#`unsigned DPxGetDacBuffReadAddr()
_DPxGetDacBuffReadAddrCall = DPxDll['DPxGetDacBuffReadAddr']
_DPxGetDacBuffReadAddrCall.restype = ctypes.c_uint
[docs]def DPxGetDacBuffReadAddr():
"""Gets RAM address from which next DAC datum will be read.
Returns:
int: Read address.
:Low-level C definition:
``unsigned DPxGetDacBuffReadAddr()``
See Also:
:class:`DPxSetDacBuffReadAddr`
"""
return _DPxGetDacBuffReadAddrCall()
#void DPxSetDacBuffSize(unsigned buffSize)
_DPxSetDacBuffSizeCall = DPxDll['DPxSetDacBuffSize']
_DPxSetDacBuffSizeCall.argtypes = [ctypes.c_uint]
_DPxSetDacBuffSizeCall.restype = None
[docs]def DPxSetDacBuffSize(buffSize):
"""Sets DAC RAM buffer size in bytes.
Must be an even value. Buffer wraps to Base after Size.
Args:
buffSize (int): Buffer size.
:Low-level C definition:
``void DPxSetDacBuffSize(unsigned buffSize)``
See Also:
:class:`DPxGetDacBuffReadAddr`
"""
return _DPxSetDacBuffSizeCall(buffSize)
#unsigned DPxGetDacBuffSize()
_DPxGetDacBuffSizeCall = DPxDll['DPxGetDacBuffSize']
_DPxGetDacBuffSizeCall.restype = ctypes.c_uint
[docs]def DPxGetDacBuffSize():
"""Gets the DAC RAM buffer size in bytes.
Returns:
int: buffer size.
:Low-level C definition:
``unsigned DPxGetDacBuffSize()``
See Also:
:class:`DPxSetDacBuffSize`
"""
return _DPxGetDacBuffSizeCall()
#void DPxSetDacBuff(unsigned buffAddr, unsigned buffSize)
_DPxSetDacBuffCall = DPxDll['DPxSetDacBuff']
_DPxSetDacBuffCall.argtypes = [ctypes.c_uint, ctypes.c_uint]
_DPxSetDacBuffCall.restype = None
[docs]def DPxSetDacBuff(buffAddr, buffSize):
"""Sets base address, read address and buffer size for DAC schedules.
This function is a shortcut which assigns Size/BaseAddr/ReadAddr
Args:
buffAddr (int): Base address.
buffSize (int): Buffer size.
:Low-level C definition:
``void DPxSetDacBuff(unsigned buffAddr, unsigned buffSize)``
See Also:
:class:`DPxGetDacSchedOnset`, :class:`DPxSetDacBuffSize`, :class:`DPxSetDacBuffReadAddr`
"""
return _DPxSetDacBuffCall(int(buffAddr), buffSize)
#void DPxSetDacSchedOnset(unsigned onset)
_DPxSetDacSchedOnsetCall = DPxDll['DPxSetDacSchedOnset']
_DPxSetDacSchedOnsetCall.argtypes = [ctypes.c_uint]
_DPxSetDacSchedOnsetCall.restype = None
[docs]def DPxSetDacSchedOnset(onset):
"""Sets the nanosecond delay between schedule start and first DAC update.
Args:
onset (int): delay in nanoseconds.
:Low-level C definition:
``void DPxSetDacSchedOnset(unsigned onset)``
See Also:
:class:`DPxGetDacSchedOnset`
"""
return _DPxSetDacSchedOnsetCall(onset)
#unsigned DPxGetDacSchedOnset()
_DPxGetDacSchedOnsetCall = DPxDll['DPxGetDacSchedOnset']
_DPxGetDacSchedOnsetCall.restype = ctypes.c_uint
[docs]def DPxGetDacSchedOnset():
"""Gets the nanosecond delay between the schedule start and first DAC update.
Returns:
int: onset.
:Low-level C definition:
``unsigned DPxGetDacSchedOnset()``
See Also:
:class:`DPxSetDacSchedOnset`
"""
return _DPxGetDacSchedOnsetCall()
#void DPxSetDacSchedRate(unsigned rateValue, int rateUnits)
_DPxSetDacSchedRateCall = DPxDll['DPxSetDacSchedRate']
_DPxSetDacSchedRateCall.argtypes = [ctypes.c_uint, ctypes.c_int]
_DPxSetDacSchedRateCall.restype = None
[docs]def DPxSetDacSchedRate(rate, unit):
"""Sets the schedule rate.
This method allows the user to set the schedule rate. Since the rate can be given
with different units, the method also needs to have a unit associated with the rate.
If no delay is required, this method does not need to be used. Default value is 0.
Args:
rate (int): Any positive value equal to or greater than zero.
unit (str): Any of the predefined constants.
* **hz**: rate updates per second, maximum 1 MHz.
* **video**: rate updates per video frame, maximum 1 MHz.
* **nano**: rate updates period in nanoseconds, minimum 1000 ns.
:Low-level C definition:
``void DPxSetDacSchedRate(unsigned rateValue, int rateUnits)``
"""
_DPxSetDacSchedRateCall(rate, api_constants[unit.upper()])
#unsigned DPxGetDacSchedRate(int *rateUnits)
_DPxGetDacSchedRateCall = DPxDll['DPxGetDacSchedRate']
_DPxGetDacSchedRateCall.restype = ctypes.c_uint
[docs]def DPxGetDacSchedRate():
"""Gets DAC schedule update rate and the rate units.
Returns:
tuple: rate and unit.
:Low-level C definition:
``unsigned DPxGetDacSchedRate(int *rateUnits)``
See Also:
:class:`DPxSetDacSchedRate`
"""
Var = 0
p_Var = ctypes.c_int(Var)
return (_DPxGetDacSchedRateCall(ctypes.byref(p_Var)), rate_constants[p_Var.value])
#void DPxSetDacSchedCount(unsigned count)
_DPxSetDacSchedCountCall = DPxDll['DPxSetDacSchedCount']
_DPxSetDacSchedCountCall.argtypes = [ctypes.c_uint]
_DPxSetDacSchedCountCall.restype = None
[docs]def DPxSetDacSchedCount(count):
"""Sets DAC schedule update count.
Args:
count (int): Schedule count.
:Low-level C definition:
``void DPxSetDacSchedCount(unsigned count)``
See Also:
:class:`DPxGetDacSchedCount`
"""
return _DPxSetDacSchedCountCall(count)
#unsigned DPxGetDacSchedCount()
_DPxGetDacSchedCountCall = DPxDll['DPxGetDacSchedCount']
_DPxGetDacSchedCountCall.restype = ctypes.c_uint
[docs]def DPxGetDacSchedCount():
"""Gets DAC schedule update count.
Returns:
int: Schedule sample count.
:Low-level C definition:
``unsigned DPxGetDacSchedCount()``
See Also:
:class:`DPxSetDacSchedCount`
"""
return _DPxGetDacSchedCountCall()
#void DPxEnableDacSchedCountdown()
_DPxEnableDacSchedCountdownCall = DPxDll['DPxEnableDacSchedCountdown']
_DPxEnableDacSchedCountdownCall.restype = None
[docs]def DPxEnableDacSchedCountdown():
"""Enables DAC schedule count down.
SchedCount decrements at SchedRate, and schedule stops automatically when count hits 0.
:Low-level C definition:
``void DPxEnableDacSchedCountdown()``
See Also:
:class:`DPxDisableDacSchedCountdown`, :class:`DPxIsDacSchedCountdown`
"""
_DPxEnableDacSchedCountdownCall()
#void DPxDisableDacSchedCountdown()
_DPxDisableDacSchedCountdownCall = DPxDll['DPxDisableDacSchedCountdown']
_DPxDisableDacSchedCountdownCall.restype = None
[docs]def DPxDisableDacSchedCountdown():
"""Disables DAC schedule count down.
SchedCount increments at SchedRate, and schedule is stopped by calling SchedStop.
:Low-level C definition:
``void DPxDisableDacSchedCountdown()``
See Also:
:class:`DPxEnableDacSchedCountdown`, :class:`DPxIsDacSchedCountdown`
"""
_DPxDisableDacSchedCountdownCall()
#int DPxIsDacSchedCountdown()
_DPxIsDacSchedCountdownCall = DPxDll['DPxIsDacSchedCountdown']
_DPxIsDacSchedCountdownCall.restype = ctypes.c_int
[docs]def DPxIsDacSchedCountdown():
"""Verifies if RAM buffering is enabled for a DAC channel.
Returns:
int: Non-zero if SchedCount decrements to 0 and automatically stops schedule.
:Low-level C definition:
``int DPxIsDacSchedCountdown()``
See Also:
:class:`DPxEnableDacSchedCountdown`, :class:`DPxDisableDacSchedCountdown`
"""
return _DPxIsDacSchedCountdownCall()
#void DPxSetDacSched(unsigned onset, unsigned rateValue, int rateUnits, unsigned count)
_DPxSetDacSchedCall = DPxDll['DPxSetDacSched']
_DPxSetDacSchedCall.argtypes = [ctypes.c_uint, ctypes.c_uint, ctypes.c_int, ctypes.c_uint]
_DPxSetDacSchedCall.restype = None
[docs]def DPxSetDacSched(onset, rateValue, rateUnits, count):
"""Sets DAC schedule onset, count and rate.
This function is a shortcut which assigns Onset/Rate/Count. If ``count`` is greater than zero, the count
down mode is enabled.
Args:
onset (int): Schedule onset.
rateValue (int): Rate value.
rateUnits (str): Usually ``hz``. Can also be ``video`` to update every ``rateValue`` video frames or ``nano`` to update every ``rateValue`` nanoseconds.
count (int): Schedule count.
:Low-level C definition:
``void DPxSetDacSched(unsigned onset, unsigned rateValue, int rateUnits, unsigned count)``
"""
return _DPxSetDacSchedCall(onset, rateValue, api_constants[rateUnits.upper()], count)
#void DPxStartDacSched()
_DPxStartDacSchedCall = DPxDll['DPxStartDacSched']
_DPxStartDacSchedCall.restype = None
[docs]def DPxStartDacSched():
"""Starts running a DAC schedule.
:Low-level C definition:
``void DPxStartDacSched()``
See Also:
:class:`DPxStopDacSched`, :class:`DPxIsDacSchedRunning`
"""
_DPxStartDacSchedCall()
#void DPxStopDacSched()`
_DPxStopDacSchedCall = DPxDll['DPxStopDacSched']
_DPxStopDacSchedCall.restype = None
[docs]def DPxStopDacSched():
"""Stops running a DAC schedule.
:Low-level C definition:
``void DPxStopDacSched()``
See Also:
:class:`DPxStartDacSched`, :class:`DPxIsDacSchedRunning`
"""
_DPxStopDacSchedCall()
#int DPxIsDacSchedRunning()
_DPxIsDacSchedRunningCall = DPxDll['DPxIsDacSchedRunning']
_DPxIsDacSchedRunningCall.restype = ctypes.c_int
[docs]def DPxIsDacSchedRunning():
"""Verifies if a DAC schedule is currently running.
Returns:
int: Non-zero if a DAC schedule is currently running, zero otherwise.
:Low-level C definition:
``int DPxIsDacSchedRunning()``
See Also:
:class:`DPxStartDacSched`, :class:`DPxStopDacSched`
"""
return _DPxIsDacSchedRunningCall()
#int DPxGetAdcNumChans()
_DPxGetAdcNumChansCall = DPxDll['DPxGetAdcNumChans']
_DPxGetAdcNumChansCall.restype = ctypes.c_int
[docs]def DPxGetAdcNumChans():
"""Gets the number of channel available.
This method returns the number of ADC channels in the system (18 in current implementation)
Returns:
int: Number of channels.
:Low-level C definition:
``int DPxGetAdcNumChans()``
"""
return _DPxGetAdcNumChansCall()
#int DPxGetAdcValue(int channel)
_DPxGetAdcValueCall = DPxDll['DPxGetAdcValue']
_DPxGetAdcValueCall.restype = ctypes.c_int
_DPxGetAdcValueCall.argtypes = [ctypes.c_int]
[docs]def DPxGetAdcValue(channel):
"""Gets the value for one ADC channel.
This method returns the 16-bit 2's complement signed value for one ADC channel. Can be used on channels 0-17.
Args:
channel (int): Channel number.
Returns:
int: Channel value.
:Low-level C definition:
``int DPxGetAdcValue(int channel)``
"""
return _DPxGetAdcValueCall(channel)
# void DPxGetAdcRange(int channel, double *minV, double *maxV)
_DPxGetAdcRangeCall = DPxDll['DPxGetAdcRange']
[docs]def DPxGetAdcRange(channel):
"""Gets the voltage range.
This method returns the voltage range; +-10V for all channels
Args:
channel (int): Channel number.
Returns:
int: Range of channel.
:Low-level C definition:
``void DPxGetAdcRange(int channel, double *minV, double *maxV)``
"""
minV = 0
maxV = 0
p_minV = ctypes.c_double(minV)
p_maxV = ctypes.c_double(maxV)
_DPxGetAdcRangeCall(channel, ctypes.byref(p_minV), ctypes.byref(p_maxV))
return (p_minV.value, p_maxV.value)
#double DPxGetAdcVoltage(int channel)
_DPxGetAdcVoltageCall = DPxDll['DPxGetAdcVoltage']
_DPxGetAdcVoltageCall.restype = ctypes.c_double
_DPxGetAdcVoltageCall.argtypes = [ctypes.c_int]
[docs]def DPxGetAdcVoltage(channel):
"""Gets the voltage for an ADC channel.
Args:
channel (int): Channel number.
Returns:
float: Voltage of channel.
:Low-level C definition:
``double DPxGetAdcVoltage(int channel)``
"""
return _DPxGetAdcVoltageCall(channel)
#void DPxSetAdcBuffChanRef(int channel, int chanRef)
_DPxSetAdcBuffChanRefCall = DPxDll['DPxSetAdcBuffChanRef']
_DPxSetAdcBuffChanRefCall.argtypes = [ctypes.c_int, ctypes.c_int]
_DPxSetAdcBuffChanRefCall.restype = None
[docs]def DPxSetAdcBuffChanRef(channel, reference):
"""Sets a reference to a channel.
This method allows the user to enable or disable ram buffering on a given channel.
When enabled, a given channel is buffered in ram. Enabling RAM buffering can only
be done for channels 0 to 15.
Args:
channel (int): Channel number to associate with a reference.
reference (str): Valid argument is one of the following predefined constants:
- **gnd**: Referenced to ground.
- **diff**: Referenced to adjacent analog input.
- **ref0**: Referenced to REF0 analog input.
- **ref1**: Referenced to REF1 analog input.
:Low-level C definition:
``void DPxSetAdcBuffChanRef(int channel, int chanRef)``
"""
_DPxSetAdcBuffChanRefCall(channel, api_constants[reference.upper()])
#int DPxGetAdcBuffChanRef(int channel)
_DPxGetAdcBuffChanRefCall = DPxDll['DPxGetAdcBuffChanRef']
_DPxGetAdcBuffChanRefCall.restype = ctypes.c_int
_DPxGetAdcBuffChanRefCall.argtypes = [ctypes.c_int]
[docs]def DPxGetAdcBuffChanRef(channel):
"""Gets the reference associated with a channel.
Returns:
reference (string): one of the following predefined constants:
- **gnd**: Referenced to ground.
- **diff**: Referenced to adjacent analog input.
- **ref0**: Referenced to REF0 analog input.
- **ref1**: Referenced to REF1 analog input.
:Low-level C definition:
``int DPxGetAdcBuffChanRef(int channel)``
"""
key = _DPxGetAdcBuffChanRefCall(channel)
return adc_channel_reference[ key ]
#void DPxEnableAdcBuffChan(int channel)
_DPxEnableAdcBuffChanCall = DPxDll['DPxEnableAdcBuffChan']
_DPxEnableAdcBuffChanCall.argtypes = [ctypes.c_int]
_DPxEnableAdcBuffChanCall.restype = None
[docs]def DPxEnableAdcBuffChan(channel):
"""Enables RAM buffering of an ADC channel.
This function is only available for channels 0-15.
Args:
channel (int): Channel number.
:Low-level C definition:
``void DPxEnableAdcBuffChan(int channel)``
See Also:
:class:`DPxDisableAdcBuffChan`, :class:`DPxDisableAdcBuffAllChans`, :class:`DPxIsAdcBuffChan`
"""
_DPxEnableAdcBuffChanCall(ctypes.c_int(channel))
# void DPxDisableAdcBuffChan(int channel)
_DPxDisableAdcBuffChanCall = DPxDll['DPxDisableAdcBuffChan']
_DPxDisableAdcBuffChanCall.argtypes = [ctypes.c_int]
_DPxDisableAdcBuffChanCall.restype = None
[docs]def DPxDisableAdcBuffChan(channel):
"""Disables RAM buffering of an ADC channel.
This function is only available for channels 0-15.
Args:
channel (int): Channel number.
:Low-level C definition:
``void DPxDisableAdcBuffChan(int channel)``
See Also:
:class:`DPxEnableAdcBuffChan`, :class:`DPxDisableAdcBuffAllChans`, :class:`DPxIsAdcBuffChan`
"""
_DPxDisableAdcBuffChanCall(ctypes.c_int(channel))
#void DPxDisableAdcBuffAllChans()
_DPxDisableAdcBuffAllChansCall = DPxDll['DPxDisableAdcBuffAllChans']
_DPxDisableAdcBuffAllChansCall.restype = None
[docs]def DPxDisableAdcBuffAllChans():
"""Disables RAM buffering of all ADC channels.
:Low-level C definition:
``void DPxDisableAdcBuffAllChans()``
See Also:
:class:`DPxEnableAdcBuffChan`, :class:`DPxDisableAdcBuffChan`, :class:`DPxIsAdcBuffChan`
"""
_DPxDisableAdcBuffAllChansCall()
#int DPxIsAdcBuffChan(int channel)
_DPxIsAdcBuffChanCall = DPxDll['DPxIsAdcBuffChan']
_DPxIsAdcBuffChanCall.restype = ctypes.c_int
_DPxIsAdcBuffChanCall.argtypes = [ctypes.c_int]
[docs]def DPxIsAdcBuffChan(channel):
"""Verifies if RAM buffering is enabled for an ADC channel.
This function is only available for channels 0-15.
Args:
channel (int): Channel number.
Returns:
int: Non-zero if RAM buffering is enabled for an ADC channel.
:Low-level C definition:
``int DPxIsAdcBuffChan(int channel)``
See Also:
:class:`DPxEnableAdcBuffChan`, :class:`DPxDisableAdcBuffChan`
"""
return _DPxIsAdcBuffChanCall(ctypes.c_int(channel))
#void DPxEnableAdcCalibRaw()
_DPxEnableAdcCalibRawCall = DPxDll['DPxEnableAdcCalibRaw']
_DPxEnableAdcCalibRawCall.restype = None
[docs]def DPxEnableAdcCalibRaw():
"""Sets the hardware calibration mode.
Enables ADC "raw" mode, causing ADC data to bypass hardware calibration.
:Low-level C definition:
``void DPxEnableAdcCalibRaw()``
See Also:
:class:`DPxDisableAdcCalibRaw`, :class:`DPxIsAdcCalibRaw`
"""
_DPxEnableAdcCalibRawCall()
#void DPxDisableAdcCalibRaw()
_DPxDisableAdcCalibRawCall = DPxDll['DPxDisableAdcCalibRaw']
_DPxDisableAdcCalibRawCall.restype = None
[docs]def DPxDisableAdcCalibRaw():
"""Sets the hardware calibration mode.
Disables ADC "raw" mode, causing normal ADC hardware calibration.
:Low-level C definition:
``void DPxDisableAdcCalibRaw()``
See Also:
:class:`DPxDisableAdcCalibRaw`, :class:`DPxIsAdcCalibRaw`
"""
_DPxDisableAdcCalibRawCall()
#int DPxIsAdcCalibRaw()
_DPxIsAdcCalibRawCall = DPxDll['DPxIsAdcCalibRaw']
_DPxIsAdcCalibRawCall.restype = ctypes.c_int
[docs]def DPxIsAdcCalibRaw():
"""Verifies if the hardware calibration mode is enabled.
Returns:
int: Non-zero if ADC data is bypassing hardware calibration.
:Low-level C definition:
``int DPxIsAdcCalibRaw()``
See Also:
:class:`DPxEnableAdcCalibRaw`, :class:`DPxDisableAdcCalibRaw`
"""
return _DPxIsAdcCalibRawCall()
#void DPxEnableDacAdcLoopback()
_DPxEnableDacAdcLoopbackCall = DPxDll['DPxEnableDacAdcLoopback']
_DPxEnableDacAdcLoopbackCall.restype = None
[docs]def DPxEnableDacAdcLoopback():
"""Sets the loopback between ADC and DAC mode.
ADC data readings are looped back internally from programmed DAC voltages:
- DAC_DATA0 => ADC_DATA0/2/4/6/8/10/12/14
- DAC_DATA1 => ADC_DATA1/3/5/7/9/11/13/15
- DAC_DATA2 => ADC_REF0
- DAC_DATA3 => ADC_REF1
:Low-level C definition:
``void DPxEnableDacAdcLoopback()``
See Also:
:class:`DPxDisableDacAdcLoopback`, :class:`DPxIsDacAdcLoopback`
"""
_DPxEnableDacAdcLoopbackCall()
#`void DPxDisableDacAdcLoopback()
_DPxDisableDacAdcLoopbackCall = DPxDll['DPxDisableDacAdcLoopback']
_DPxDisableDacAdcLoopbackCall.restype = None
[docs]def DPxDisableDacAdcLoopback():
"""Disables the loopback between ADC and DAC, causes ADC readings to reflect real analog inputs.
:Low-level C definition:
``void DPxDisableDacAdcLoopback()``
See Also:
:class:`DPxEnableDacAdcLoopback`, :class:`DPxIsDacAdcLoopback`
"""
_DPxDisableDacAdcLoopbackCall()
#int DPxIsDacAdcLoopback()
_DPxIsDacAdcLoopbackCall = DPxDll['DPxIsDacAdcLoopback']
_DPxIsDacAdcLoopbackCall.restype = ctypes.c_int
[docs]def DPxIsDacAdcLoopback():
"""Verifies if the loopback between ADC and DAC is enabled.
Returns:
int: Non-zero if ADC inputs are looped back from DAC outputs.
:Low-level C definition:
``int DPxIsDacAdcLoopback()``
See Also:
:class:`DPxEnableDacAdcLoopback`, :class:`DPxIsDacAdcLoopback`
"""
return _DPxIsDacAdcLoopbackCall()
#void DPxEnableAdcFreeRun()
_DPxEnableAdcFreeRunCall = DPxDll['DPxEnableAdcFreeRun']
_DPxEnableAdcFreeRunCall.restype = None
[docs]def DPxEnableAdcFreeRun():
"""Sets the ADC in free-run mode, making them convert continuously.
This can add up to 4 microseconds of random latency to scheduled samples.
:Low-level C definition:
``void DPxEnableAdcFreeRun()``
See Also:
:class:`DPxDisableAdcFreeRun`, :class:`DPxIsAdcFreeRun`
"""
_DPxEnableAdcFreeRunCall()
#void DPxDisableAdcFreeRun()
_DPxDisableAdcFreeRunCall = DPxDll['DPxDisableAdcFreeRun']
_DPxDisableAdcFreeRunCall.restype = None
[docs]def DPxDisableAdcFreeRun():
"""Disables ADC free-run mode.
ADCs will only convert on schedule ticks, for microsecond-precise sampling.
:Low-level C definition:
``void DPxDisableAdcFreeRun()``
See Also:
:class:`DPxEnableAdcFreeRun`, :class:`DPxIsAdcFreeRun`
"""
_DPxDisableAdcFreeRunCall()
#void DPxIsAdcFreeRun()
_DPxIsAdcFreeRunCall = DPxDll['DPxIsAdcFreeRun']
_DPxIsAdcFreeRunCall.restype = ctypes.c_int
[docs]def DPxIsAdcFreeRun():
"""Verifies if the loopback between ADC and DAC is enabled.
Returns:
int: Non-zero if ADCs are performing continuous conversions.
:Low-level C definition:
``void DPxIsAdcFreeRun()``
See Also:
:class:`DPxEnableDacAdcLoopback`, :class:`DPxDisableAdcFreeRun`
"""
return _DPxIsAdcFreeRunCall()
#void DPxSetAdcBuffBaseAddr(unsigned buffBaseAddr)
_DPxSetAdcBuffBaseAddrCall = DPxDll['DPxSetAdcBuffBaseAddr']
_DPxSetAdcBuffBaseAddrCall.argtypes = [ctypes.c_uint]
_DPxSetAdcBuffBaseAddrCall.restype = None
[docs]def DPxSetAdcBuffBaseAddr(buffBaseAddr):
"""Sets the ADC RAM buffer start address.
Must be an even value.
Args:
buffBaseAddr (int): Base address.
:Low-level C definition:
``void DPxSetAdcBuffBaseAddr(unsigned buffBaseAddr)``
See Also:
:class:`DPxGetAdcBuffBaseAddr`
"""
return _DPxSetAdcBuffBaseAddrCall(buffBaseAddr)
#unsigned DPxGetDacBuffBaseAddr()
_DPxGetAdcBuffBaseAddrCall = DPxDll['DPxGetAdcBuffBaseAddr']
_DPxGetAdcBuffBaseAddrCall.restype = ctypes.c_uint
[docs]def DPxGetAdcBuffBaseAddr():
"""Gets the ADC RAM buffer start address.
Returns:
int: Base address.
:Low-level C definition:
``unsigned DPxGetDacBuffBaseAddr()``
See Also:
:class:`DPxSetAdcBuffBaseAddr`
"""
return _DPxGetAdcBuffBaseAddrCall()
#void DPxSetAdcBuffWriteAddr(unsigned buffWriteAddr)
_DPxSetAdcBuffWriteAddrCall= DPxDll['DPxSetAdcBuffWriteAddr']
_DPxSetAdcBuffWriteAddrCall.argtypes = [ctypes.c_uint]
_DPxSetAdcBuffWriteAddrCall.restype = None
[docs]def DPxSetAdcBuffWriteAddr(buffWriteAddr):
"""Sets RAM address from which next ADC datum will be written.
Must be an even value.
Args:
buffWriteAddr (int): Write address.
:Low-level C definition:
``void DPxSetAdcBuffWriteAddr(unsigned buffWriteAddr)``
See Also:
:class:`DPxGetAdcBuffWriteAddr`
"""
return _DPxSetAdcBuffWriteAddrCall(buffWriteAddr)
#unsigned DPxGetAdcBuffWriteAddr()
_DPxGetAdcBuffWriteAddrCall = DPxDll['DPxGetAdcBuffWriteAddr']
_DPxGetAdcBuffWriteAddrCall.restype = ctypes.c_uint
[docs]def DPxGetAdcBuffWriteAddr():
"""Gets RAM address from which next ADC datum will be written.
Returns:
int: Write address.
:Low-level C definition:
``unsigned DPxGetAdcBuffWriteAddr()``
See Also:
:class:`DPxSetAdcBuffWriteAddr`
"""
return _DPxGetAdcBuffWriteAddrCall()
#void DPxSetAdcBuffSize(unsigned buffSize)
_DPxSetAdcBuffSizeCall = DPxDll['DPxSetAdcBuffSize']
_DPxSetAdcBuffSizeCall.argtypes = [ctypes.c_uint]
_DPxSetAdcBuffSizeCall.restype = None
[docs]def DPxSetAdcBuffSize(buffSize):
"""Sets ADC RAM buffer size in bytes.
The Buffer size must be an even value. Buffer wraps to Base after Size.
Args:
buffSize (int): Buffer size.
:Low-level C definition:
``void DPxSetAdcBuffSize(unsigned buffSize)``
See Also:
:class:`DPxGetAdcBuffSize`
"""
return _DPxSetAdcBuffSizeCall(buffSize)
#unsigned DPxGetAdcBuffSize()
_DPxGetAdcBuffSizeCall = DPxDll['DPxGetAdcBuffSize']
_DPxGetAdcBuffSizeCall.restype = ctypes.c_uint
[docs]def DPxGetAdcBuffSize():
"""Gets the ADC RAM buffer size in bytes.
Returns:
int: buffer size.
:Low-level C definition:
``unsigned DPxGetAdcBuffSize()``
See Also:
:class:`DPxSetAdcBuffSize`
"""
return _DPxGetAdcBuffSizeCall()
#void DPxSetAdcBuff(unsigned buffAddr, unsigned buffSize)`
_DPxSetAdcBuffCall = DPxDll['DPxSetAdcBuff']
_DPxSetAdcBuffCall.argtypes = [ctypes.c_uint, ctypes.c_uint]
_DPxSetAdcBuffCall.restype = None
[docs]def DPxSetAdcBuff(buffAddr, buffSize):
"""Sets base address, write address and buffer size for ADC schedules.
This function is a shortcut which assigns Size/BaseAddr/WriteAddr
Args:
buffAddr (int): Base address.
buffSize (int): Buffer size.
:Low-level C definition:
``void DPxSetAdcBuff(unsigned buffAddr, unsigned buffSize)``
See Also:
:class:`DPxGetAdcSchedOnset`, :class:`DPxSetAdcBuffSize`, :class:`DPxSetAdcBuffWriteAddr`
"""
return _DPxSetAdcBuffCall(int(buffAddr), buffSize)
#void DPxSetAdcSchedOnset(unsigned onset)
_DPxSetAdcSchedOnsetCall = DPxDll['DPxSetAdcSchedOnset']
_DPxSetAdcSchedOnsetCall.argtypes = [ctypes.c_uint]
_DPxSetAdcSchedOnsetCall.restype = None
[docs]def DPxSetAdcSchedOnset(onset):
"""Sets nanosecond delay between schedule start and first ADC sample.
Args:
onset (int): delay in nanoseconds.
:Low-level C definition:
``void DPxSetAdcSchedOnset(unsigned onset)``
See Also:
:class:`DPxGetAdcSchedOnset`
"""
return _DPxSetAdcSchedOnsetCall(onset)
#unsigned DPxGetAdcSchedOnset()
_DPxGetAdcSchedOnsetCall = DPxDll['DPxGetAdcSchedOnset']
_DPxGetAdcSchedOnsetCall.restype = ctypes.c_uint
[docs]def DPxGetAdcSchedOnset():
"""Gets the nanosecond delay between schedule start and first ADC sample.
Returns:
int: onset.
:Low-level C definition:
``unsigned DPxGetAdcSchedOnset()``
See Also:
:class:`DPxSetAdcSchedOnset`
"""
return _DPxGetAdcSchedOnsetCall()
#void DPxSetAdcSchedRate(unsigned rateValue, int rateUnits)
_DPxSetAdcSchedRateCall = DPxDll['DPxSetAdcSchedRate']
_DPxSetAdcSchedRateCall.argtypes = [ctypes.c_uint, ctypes.c_int]
_DPxSetAdcSchedRateCall.restype = None
[docs]def DPxSetAdcSchedRate(rate, unit):
"""Sets the schedule rate.
This method allows the user to set the schedule rate. Since the rate can be given
with different units, the method also needs to have a unit associated with the rate.
If no delay is required, this method does not need to be used. Default value is 0.
Args:
rate (int): Any positive value equal to or greater than zero.
unit (str): Any of the predefined constants.
- **hz**: rate updates per second, maximum 200 kHz.
- **video**: rate updates per video frame, maximum 200 kHz.
- **nano**: rate updates period in nanoseconds, minimum 5000 ns.
:Low-level C definition:
``void DPxSetAdcSchedRate(unsigned rateValue, int rateUnits)``
"""
return _DPxSetAdcSchedRateCall(rate, api_constants[unit.upper()])
#unsigned DPxGetAdcSchedRate(int *rateUnits)
_DPxGetAdcSchedRateCall = DPxDll['DPxGetAdcSchedRate']
_DPxGetAdcSchedRateCall.restype = ctypes.c_uint
[docs]def DPxGetAdcSchedRate():
"""Returns the ADC schedule rate in hertz.
Returns:
int: schedule rate (Hz)
:Low-level C definition:
``unsigned DPxGetAdcSchedRate(int *rateUnits)``
"""
Var = 0
p_Var = ctypes.c_int(Var)
return (_DPxGetAdcSchedRateCall(ctypes.byref(p_Var)) , rate_constants[p_Var.value])
#void DPxSetAdcSchedCount(unsigned count)
_DPxSetAdcSchedCountCall = DPxDll['DPxSetAdcSchedCount']
_DPxSetAdcSchedCountCall.argtypes = [ctypes.c_uint]
_DPxSetAdcSchedCountCall.restype = None
[docs]def DPxSetAdcSchedCount(count):
"""Sets ADC schedule update count.
Args:
count (int): Schedule count.
:Low-level C definition:
``void DPxSetAdcSchedCount(unsigned count)``
See Also:
:class:`DPxGetAdcSchedCount`
"""
return _DPxSetAdcSchedCountCall(count)
#`unsigned DPxGetAdcSchedCount()
_DPxGetAdcSchedCountCall = DPxDll['DPxGetAdcSchedCount']
_DPxGetAdcSchedCountCall.restype = ctypes.c_uint
[docs]def DPxGetAdcSchedCount():
"""Gets ADC schedule update count.
Returns:
int: Schedule sample count.
:Low-level C definition:
``unsigned DPxGetAdcSchedCount()``
See Also:
:class:`DPxSetAdcSchedCount`
"""
return _DPxGetAdcSchedCountCall()
#void DPxEnableAdcSchedCountdown()
_DPxEnableAdcSchedCountdownCall = DPxDll['DPxEnableAdcSchedCountdown']
_DPxEnableAdcSchedCountdownCall.restype = None
[docs]def DPxEnableAdcSchedCountdown():
"""Enables ADC schedule count down.
SchedCount decrements at SchedRate, and schedule stops automatically when count hits 0.
:Low-level C definition:
``void DPxEnableAdcSchedCountdown()``
See Also:
:class:`DPxDisableAdcSchedCountdown`, :class:`DPxIsAdcSchedCountdown`
"""
_DPxEnableAdcSchedCountdownCall()
#void DPxDisableAdcSchedCountdown()
_DPxDisableAdcSchedCountdownCall = DPxDll['DPxDisableAdcSchedCountdown']
_DPxDisableAdcSchedCountdownCall.restype = None
[docs]def DPxDisableAdcSchedCountdown():
"""Disables ADC schedule count down.
SchedCount increments at SchedRate, and schedule is stopped by calling SchedStop.
:Low-level C definition:
``void DPxDisableAdcSchedCountdown()``
See Also:
:class:`DPxEnableAdcSchedCountdown`, :class:`DPxIsAdcSchedCountdown`
"""
_DPxDisableAdcSchedCountdownCall()
#int DPxIsAdcSchedCountdown()
_DPxIsAdcSchedCountdownCall = DPxDll['DPxIsAdcSchedCountdown']
_DPxIsAdcSchedCountdownCall.restype = ctypes.c_int
[docs]def DPxIsAdcSchedCountdown():
"""Verifies if RAM buffering is enabled for an ADC channel.
Returns:
int: Non-zero if SchedCount decrements to 0 and automatically stops schedule.
:Low-level C definition:
``int DPxIsAdcSchedCountdown()``
See Also:
:class:`DPxEnableAdcSchedCountdown`, :class:`DPxDisableAdcSchedCountdown`
"""
return _DPxIsAdcSchedCountdownCall()
#void DPxSetAdcSched(unsigned onset, unsigned rateValue, int rateUnits, unsigned count)
_DPxSetAdcSchedCall = DPxDll['DPxSetAdcSched']
_DPxSetAdcSchedCall.restype = None
[docs]def DPxSetAdcSched(onset, rateValue, rateUnits, count):
"""Sets ADC schedule onset, count and rate.
This function is a shortcut which assigns Onset/Rate/Count. If ``count`` is greater than zero, the count
down mode is enabled.
Args:
onset (int): Schedule onset.
rateValue (int): Rate value.
rateUnits (str): Usually ``hz``. Can also be ``video`` to update every ``rateValue`` video frames or ``nano`` to update every ``rateValue`` nanoseconds.
count (int): Schedule count.
:Low-level C definition:
``void DPxSetAdcSched(unsigned onset, unsigned rateValue, int rateUnits, unsigned count)``
"""
return _DPxSetAdcSchedCall(onset, rateValue, api_constants[rateUnits.upper()], count)
# Recording (16 inputs)
[docs]def DPxSetAdcSchedule(onSet, rateValue, rateUnits, maxScheduleFrames, channelList = None, bufferBaseAddr = 4e6, numberBufferFrames=None):
"""Configure a schedule for autonomous ADC analog signal acquisition.
This function is used to fully setup an acquisition schedule on the device. Regardless of the actual format chosen, the resulting sample rate cannot exceed 200 kHz.
It returns a dictionary that is needed when reading data or updating the buffer.
Use ReadAdcBuffer to upload the acquired data from this address after calling StartAdcSchedule.
Note that every call to StartAdcSchedule must be preceeded by a call to
SetAdcSchedule (ie: multiple calls to StartAdcSchedule each require their own call to SetAdcSchedule).
Args:
onSet (float): The desired delay (in double precision seconds) between schedule initiation, and the first ADC sample acquisition.
rateValue (int): The rate at which the ADC's acquire successive samples.
rateUnits (str): This can have three values: "Hz" for samples/seconds, "video" for samples/video frame or "nano" for seconds/samples
maxScheduleFrames (int): If the dataset has a known length, then maxScheduleFrames should be that number. If it is a dynamic length, pass 0.
channelList (list): The channelList can have two formats, a list of the channels you want to use, or a list of the channels you want to use in the first row, and the 2nd row contains the differential.
The first row of the list contains 1 or more integers in the range 0 to GetAdcNumChannels-1. This is the list of ADC channels which will be acquired. The second row of the matrix indicates the differential
voltage references for each acquired channel. The list must have this format: [[chanNum, ref]...] or 1D list [chanNum, chanNum2, ...]. The reference is selected using a string with value "gnd", "diff", "ref0" or "ref1".
Code "gnd" is used when no differential subtraction is required during acquisition. All analog inputs are referenced to ground, also known as single-ended acquisition.
Code "diff" implements fully differential inputs, subtracting the adjacent channel's voltage before acquiring (eg: acquiring ADC0 with code = "diff" would subtract the ADC1 voltage from the ADC0 voltage, writing the
result to the acquisition buffer). When using this mode, data is typically acquired only on the even channels, effectively halving the number of available channels. Code "ref0" implements a differential input referenced to the REF0 analog
input (see the Datapixx user manual for pinouts). This has the benefits of high-impedance differential inputs, without having to sacrifice half of the channels as with fully differential inputs. Code "ref1" implements a differential
input referenced to the REF1 analog input. It is possible to use different codes for different analog channels in a single acquisition schedule. For example ADC0 and ADC1 could be acquired single-ended while ADC2 is referenced to ADC3, and
ADC4/5/6/7 could be referenced to REF0. It is also possible to pass only a single row of ADC channels to channelList. In this case, all of the ADC channels will be acquired single-ended.
bufferBaseAddress (int): The start of the RAM buffer which should hold the acquired data inside the Datapixx. Default value is 4e6.
numBufferFrames (int): Specifies the desired size of the acquisition buffer in the Datapixx RAM. Default value of maxScheduleFrames. If maxScheduleFrames is larger than numBufferFrames (or 0), then each time the acquisition frame counter
reaches a multiple of numBufferFrames, the acquisition buffer address automatically wraps back to bufferBaseAddress. This circular buffer effect can be used for acquiring arbitrarily long analog datasets.
Simply monitor newBufferFrames returned by GetAdcStatus, and use ReadAdcBuffer in streaming mode to upload newly acquired data from the Datapixx RAM to the host.
Returns:
AdcDictionary (dict): Returns a dictionary which has some global information which must be passed to other ADC functions.
"""
#NumBufferFrames
if numberBufferFrames == None:
numberBufferFrames = maxScheduleFrames
retList = {}
# OnSet
if (onSet < 0):
print('onSet must be a single number > 0.')
return
if (onSet > 4.30):
print('onSet must be smaller than 4.29 seconds.')
return
#RateUnits (either 1,2 or 3 or "video", "hz" or "nano"
if (rateUnits in [1,2,3]):
if rateUnits == 1:
rateUnitNumber = DPXREG_SCHED_CTRL_RATE_HZ
rateUnits = 'Hz'
if rateUnits == 2:
rateUnitNumber = DPXREG_SCHED_CTRL_RATE_XVID
rateUnits = 'video'
if rateUnits == 3:
rateUnitNumber = DPXREG_SCHED_CTRL_RATE_NANO
rateUnits = 'nano'
elif (rateUnits.upper() in api_constants):
rateUnitNumber = api_constants[rateUnits.upper()]
else:
print('rateUnits must be "hz", "video" or "nano".')
return
#RateCheck
if rateUnitNumber == DPXREG_SCHED_CTRL_RATE_HZ: #Hz
schedRateHz = rateValue;
elif rateUnitNumber == DPXREG_SCHED_CTRL_RATE_XVID: #Rate per video frame
schedRateHz = rateValue * DPxGetVidVFreq();
elif rateUnitNumber == DPXREG_SCHED_CTRL_RATE_NANO: #Seconds/samples
schedRateHz = 1 / rateValue;
if (schedRateHz > 2.0e5):
print('Frequncy too high')
return
if (rateValue < 0):
print('Frequency < 0')
return
if (rateValue > 0xffffffff):
print('Period too large')
return
#maxScheduleFrames
if maxScheduleFrames < 0:
print('MaxSchedFrames must be a positive number')
return
#channelList
nChans = 1; # Default
DPxDisableAdcBuffAllChans()
if channelList == None:
nChans = 1;
DPxEnableAdcBuffChan(0);
DPxSetAdcBuffChanRef(0, 'gnd');
else: # check shape of the channelList argument
dimensions = np.shape(channelList)
if (len(dimensions) == 1):
# Only channels
nChans = len(channelList)
for i in range(nChans):
chan = channelList[i]
DPxEnableAdcBuffChan(chan);
DPxSetAdcBuffChanRef(chan, 'gnd');
elif (len(dimensions) == 2):
# Channels and REF, need to ensure that we have tuples
if np.shape(channelList)[1] != 2:
print('Channel List is not shaped properly, should be a 2D List of this form [[chanNum, ref]...] or 1D list [chanNum, chanNum2, ...]')
return
nChans = len(channelList)
for i in range(nChans):
channel, ref = channelList[i]
DPxEnableAdcBuffChan(channel);
if (ref.upper() in api_constants):
DPxSetAdcBuffChanRef(channel, ref)
else:
print('Reference must be gnd, diff, ref0 or ref1')
return
else:
print('Channel List is not shaped properly, should be a 2D List of this form [[chanNum, ref]...] or 1D list [chanNum, chanNum2, ...]')
return
#BufferBaseAddress
if bufferBaseAddr < 0:
print('BufferBaseAddr must be > 0.')
return
# Now the fun begins
bufferSize = numberBufferFrames * (8 + nChans * 2); # in bytes
# bufferSize too big?
if (bufferBaseAddr + bufferSize > DPxGetRamSize()):
print('Device Ram not big enough for this buffer')
return
# Implement
DPxSetAdcSched(onSet, rateValue, rateUnits, maxScheduleFrames);
DPxSetAdcBuff(bufferBaseAddr, bufferSize);
DPxEnableAdcLogTimetags();
retList['bufferBaseAddr'] = bufferBaseAddr
retList['bufferSize'] = bufferSize
retList['numAdcSchedChans'] = nChans
retList['maxAdcSchedFrames'] = maxScheduleFrames
retList['currAdcReadFrame'] = 0
retList['numAdcStreamUnderflows'] = 0
retList['numAdcStreamOverflows'] = 0
retList['channelList'] = channelList
retList['newBufferFrames'] = 0 # No new frames at the start
return retList
[docs]def DPxReadAdcBuffer(inDict, numFrames = 0, customReadAddr = None):
"""Reads data from the ADC buffer.
Args:
inDict (dict): The dictionary returned by the schedule setup
numFrames (int): Number of frames of information to retrieve from the ADC buffer. Leave to 0 to read the full buffer, which is the default argument.
customReadAddr (int): The byte address in Datapixx RAM where the buffered data can be found. If this argument is not provided, it will take on the value of bufferBaseAddress passed to the last call to SetAdcSchedule.
Specifying abufferAddress of -1 will cause data to be streamed from the buffer which was defined in the last call to SetAdcSchedule.
Returns:
[data], [timetag] (list,list): Returns a tuple of list, where the first one is the data and the second one are its timetags. The data will be nChan*numFrames, where nChan is the number of channels activated for recording.
See Also:
:class:`DPxEnableAdcSchedCountdown`, :class:`DPxSetAdcSchedule`
"""
# In this, we want to get:
# BaseAddr + BuffSize = Total Size
#
if customReadAddr == None:
currAdcReadFrame = inDict['currAdcReadFrame']
else:
# From the dict, this is where we currently are due to read
currAdcReadFrame = customReadAddr
# Where does the buffer start in RAM Space and how much space do we have?
baseAddr = DPxGetAdcBuffBaseAddr()
bufferSize = DPxGetAdcBuffSize()
# Where is the device at in terms of writting data
adcWriteAddr = DPxGetAdcBuffWriteAddr()
# How many channels are we using? This was determined when setting up the ADC
nChans = inDict['numAdcSchedChans']
# Each channel will take 2 bytes, and every frame also includes a timetag. This gives that
# One frame is 8 + nChans*2
frameSize = 8 + nChans * 2
# Now we must figure out where do we start reading
# currAdcReadFrame is in ~frames~ not in address, we must convert back.
readAddr = baseAddr + (((currAdcReadFrame * frameSize) % bufferSize) if bufferSize != 0 else 0) # the if is to prevent a division per 0
# Still in address space, we check the overflow
newLogSize = (adcWriteAddr - readAddr) if (adcWriteAddr >= readAddr) else (adcWriteAddr + bufferSize - readAddr)
# Convert back to frames (so buffer Size in bytes devided by bytes per frame)
newLogFrames = newLogSize // frameSize
# We only read need everything possible if argument passed in was 0
nReadFrames = newLogFrames if (numFrames == 0) else numFrames
#print('Reading {0} frames in ADC, new log size: {1}, readAddr: {2}, baseAddr: {3}, bufferSize: {4}, adcWriteAddr: {5}'.format(nReadFrames, newLogSize, hex(readAddr), hex(baseAddr), bufferSize, hex(adcWriteAddr)))
# Update our dictionary to what we will be reading
currAdcReadFrame += nReadFrames
inDict['currAdcReadFrame'] = currAdcReadFrame
if (nReadFrames > newLogFrames): # If we tried to read more than availible.
inDict['underflow'] = True
inDict['numAdcStreamUnderflows'] = inDict['numAdcStreamUnderflows'] + 1
# Now that the setup is done, let's read the actual data!
# We're going to read at the rate of 16 bits (2bytes) per read, so we need to read half as much as the number of total bytes we have
nReadShorts = nReadFrames * (8+nChans*2) // 2;
retValTT = []
retValData = [ [] for _ in range(nChans)]
while (nReadShorts > 0) :
# How many shorts should we read in this iteration?
nCopyShorts = nReadShorts
# check if buffer is too big??
nShortsUntilWrap = (baseAddr + bufferSize - readAddr) // 2
if (nCopyShorts > nShortsUntilWrap):
nCopyShorts = nShortsUntilWrap
nReadShorts -= nCopyShorts;
ramBuff = DPxReadRam(readAddr, nCopyShorts)
# And treat the uploaded data
# Data is: tt, tt, tt, tt, Channel 0, Channel 1, ..., Channel n-1.
# therefore we need to start reading the first 4 (iCopyShort, iCopyShort+1, +2, +3) for the time tag,
# and then we read +4 + 0 for the first channel, +4 +1 for the 2nd channel, until we reach 4+nChans
#print(ramBuff)
# Then the next data is a timetag again.
for iCopyShort in range(0, nCopyShorts, 4+nChans):
tt = (ramBuff[iCopyShort] + (ramBuff[iCopyShort+1] << np.uint64(16)) + (ramBuff[iCopyShort+2]<< np.uint64(32)) + (ramBuff[iCopyShort+3]<< np.uint64(48))) / 1e9
retValTT.append(tt)
for u in range(0, nChans):
#print('Reading values in channel {0}'.format(nChans))
# Right now the data returned to us is "unsigned", but it actually is signed.
signed_valu = -(ramBuff[iCopyShort+4+u] & 0x8000) | (ramBuff[iCopyShort+4+u] & 0x7fff)
data = signed_valu * 10 / 32768
retValData[u].append(data)
#Update the Datapixx buffer read address for the next read
readAddr += nCopyShorts*2
if (readAddr >= baseAddr + bufferSize):
readAddr -= bufferSize
return retValData, retValTT
[docs]def DPxGetAdcStatus(inDict):
"""Updates the information dictionary for the ADC schedule.
Args:
inDict (dict): The dictionary returned by the schedule setup
Updates the dictionary with the following information:
"dacAdcLoopback" is True if ADC inputs are driven internally by DAC outputs, or False if ADC inputs report real analog inputs.
"freeRunning" is True if ADC hardware is sampling continuously, or False if it only samples on ADC acquisition schedule ticks.
"scheduleRunning" is True if the analog acquisition schedule is currently running, or False if stopped.
"scheduleOnset" is the programmed delay in seconds between StartAdcSchedule execution, and the first ADC sample acquisition.
"scheduleRate" is the rate at which subsequent ADC samples are acquired.
"scheduleRateUnits" is the programmed units of scheduleRate: "Hz" is samples per second, "video" is samples per video frame, "nano" is seconds per sample
"numAdcSchedChans" is the number of ADC channels scheduled for acquisition.
"channelList" is the list of channels and their reference, if enabled.
"bufferBaseAddress" is the acquisition data buffer base address within the Datapixx.
"bufferSize" is the number of bytes in the acquisition data buffer.
"numBufferFrames" is the total number of samples which fit in the acquisition data buffer.
"currentWriteFrame" is the buffer frame which will be written by the next acquired ADC sample.
"currentReadFrame" is the buffer frame which will be read by the next streaming call to ReadAdcBuffer.
"newBufferFrames" = currentWriteFrame - currentReadFrame. This is the maximum number of frames which can be read by the next call to ReadAdcBuffer in streaming mode, without causing a streaming underflow.
"maxScheduleFrames", if non-0, is the value of currentWriteFrame which will automatically stop the schedule.
"""
inDict['dacAdcLoopback'] = True if DPxIsDacAdcLoopback() != 0 else False
inDict['freeRunning'] = True if DPxIsAdcFreeRun() != 0 else False
inDict['scheduleRunning'] = True if DPxIsAdcSchedRunning() != 0 else False
inDict['scheduleOnset'] = DPxGetAdcSchedOnset() / 1.0e9
rate, units = DPxGetDacSchedRate()
inDict['scheduleRate'] = rate
inDict['scheduleUnits'] = units
# current Status
nChans = inDict['numAdcSchedChans']
currAdcReadFrame = inDict['currAdcReadFrame']
adcBaseAddr = DPxGetAdcBuffBaseAddr()
bufferSize = DPxGetAdcBuffSize()
adcWriteAddr = DPxGetAdcBuffWriteAddr()
inDict['bufferBaseAddress'] = DPxGetAdcBuffBaseAddr()
inDict['bufferSize'] = DPxGetAdcBuffSize()
inDict['numBufferFrames'] = DPxGetAdcBuffSize() // (8 + nChans * 2) # total size
frameSize = 8 + nChans * 2
# count where we should be reading now in addrss
adcReadAddr = adcBaseAddr + (((currAdcReadFrame * frameSize) % bufferSize) if bufferSize != 0 else 0) # the if is to prevent a division per 0
# Size in memory of how many we can read
newLogSize = (adcWriteAddr - adcReadAddr) if (adcWriteAddr >= adcReadAddr) else adcWriteAddr + bufferSize - adcReadAddr;
# size converted to frames
newLogFrames = newLogSize // (8 + 2 * nChans);
inDict['newBufferFrames'] = newLogFrames
# Update where we are writing now with this calculated
currWriteFrame = inDict['currAdcReadFrame'] + newLogFrames;
inDict['currentWriteFrame'] = currWriteFrame
#void DPxStartAdcSched()
_DPxStartAdcSchedCall = DPxDll['DPxStartAdcSched']
_DPxStartAdcSchedCall.restype = None
[docs]def DPxStartAdcSched():
"""Starts running an ADC schedule.
:Low-level C definition:
``void DPxStartAdcSched()``
See Also:
:class:`DPxStopAdcSched`, :class:`DPxIsAdcSchedRunning`
"""
_DPxStartAdcSchedCall()
#void DPxStopAdcSched()
_DPxStopAdcSchedCall = DPxDll['DPxStopAdcSched']
_DPxStopAdcSchedCall.restype = None
[docs]def DPxStopAdcSched():
"""Stops running an ADC schedule.
:Low-level C definition:
``void DPxStopAdcSched()``
See Also:
:class:`DPxStartAdcSched`, :class:`DPxIsAdcSchedRunning`
"""
_DPxStopAdcSchedCall()
#int DPxIsAdcSchedRunning()
_DPxIsAdcSchedRunningCall = DPxDll['DPxIsAdcSchedRunning']
_DPxIsAdcSchedRunningCall.restype = ctypes.c_int
[docs]def DPxIsAdcSchedRunning():
"""Verifies if an ADC schedule is currently running.
Returns:
int: Non-zero if an ADC schedule is currently running, zero if there is one.
:Low-level C definition:
``int DPxIsAdcSchedRunning()``
See Also:
:class:`DPxStartAdcSched`, :class:`DPxStopAdcSched`
"""
return _DPxIsAdcSchedRunningCall()
#void DPxEnableAdcLogTimetags()
_DPxEnableAdcLogTimetagsCall = DPxDll['DPxEnableAdcLogTimetags']
_DPxEnableAdcLogTimetagsCall.restype = None
#void DPxDisableAdcLogTimetags()
_DPxDisableAdcLogTimetagsCall = DPxDll['DPxDisableAdcLogTimetags']
_DPxDisableAdcLogTimetagsCall.restype = None
#int DPxIsAdcLogTimetags()
_DPxIsAdcLogTimetagsCall = DPxDll['DPxIsAdcLogTimetags']
_DPxIsAdcLogTimetagsCall.restype = ctypes.c_int
#int DPxGetDinNumBits()
_DPxGetDinNumBitsCall = DPxDll['DPxGetDinNumBits']
_DPxGetDinNumBitsCall.restype = ctypes.c_int
[docs]def DPxGetDinNumBits():
"""Gets the number of bits available.
This method returns the number of digital input bits in the system (24 in current implementation).
Returns:
int: Number of bits.
:Low-level C definition:
``int DPxGetDinNumBits()``
"""
return _DPxGetDinNumBitsCall()
[docs]def DPxWriteDacBuffer(bufferData, bufferAddress=0, channelList=None):
"""Writes the data that will be used by the DAC buffer to drive the analogue outputs.
Args:
bufferData (multi-dimension list): nChans x nFrame list where each row of the matrix contains the sample data for one DAC channel. Each column of the list contains one sample for each DAC channel.
bufferAddress (int): The byte address in Datapixx RAM where the buffer should start. Default value of zero. Streaming value of -1 not implemented yet.
channelList (list): channelList by default is channel 0...nChans channels. If provided, it needs to be a list of size nChans.
Returns:
int: nextBufferAddress, the next address availible to write to memory after the DAC buffer.
"""
# buffer DAta is an nChans x n matrix
# bufferAddress is the place where the data should be saved
# channelList by default is channel 0...nChans channel
# it needs to be a list of size nChans
# Ex: [0,2,3] for DAC0,2 and 3 with a 3x N bufferData
# First check the size of bufferData which will give us the number of channels
dimensions = np.shape(bufferData)
nChans = 0
nFrames = 0
if (len(dimensions) == 1): # Only 1 channel
nChans = 1
nFrames = len(bufferData)
else:
nChans = dimensions[0]
nFrames = dimensions[1]
nData = nChans * nFrames # Number of datum total
if (nChans > 4):
print('Only 4 DAC availible')
return
#Check bufferAddr
if (bufferAddress < -1):
print('BufferAddress must be a positive number)')
if bufferAddress == -1:
# Streaming, TODO
return
currentDacWriteFrame = nFrames
if (bufferAddress + (nData * 2) > DPxGetRamSize()):
print("Too big for ram")
return
if (channelList == None):
channelList = list(range(nChans))
elif (len(channelList) > 4):
print('Too many channels, should be 4 at most')
return
# Some channels are 10V and some are 5V, so we need to get this information.
minVolt = [0]*nChans
maxVolt = [0]*nChans
for i in range(nChans):
minVolt[i], maxVolt[i] = DPxGetDacRange(channelList[i])
# Generate an array of the max size, if needed
# Divide by 2 because 32 bytes --> 16 bytes
maxSize = DPxGetWriteRamBuffSize() // 2;
# Defaults to size of number of data.
ramBuffer = [0]*nData;
if nData >= maxSize:
ramBuffer = [0]*(maxSize)
else:
ramBuffer = [0]*nData
iChans = 0
# Use a flag to know how many times we reached the max
bufferMaxFlag = 0
for iCopyShort in range(0, nData):
# If we are not on the first element, and when we are at a maxSize Block
if (iCopyShort != 0) and ((iCopyShort % maxSize) == 0):
# Write to ram now what we have so far
# Update the next address
DPxWriteRam(bufferAddress, ramBuffer[0:maxSize])
bufferAddress = bufferAddress + 2*maxSize # *2 to match back to dpxAddr
bufferMaxFlag = bufferMaxFlag + 1
if nChans == 1:
dacValueUnconverted = bufferData[iCopyShort // nChans]
else:
dacValueUnconverted = bufferData[iChans][iCopyShort // nChans]
dacValue = (dacValueUnconverted - minVolt[iChans]) / (maxVolt[iChans] - minVolt[iChans]) * 65536 - 32768;
dacValue = math.floor(dacValue + 0.5); # Rounding, and no bias around 0V.
if (dacValue > 32767):
dacValue = 32767
elif (dacValue < -32768):
dacValue = -32768
ramBuffer[iCopyShort - bufferMaxFlag*maxSize] = dacValue
iChans = (iChans + 1) % nChans
# Write what we have left or the full data if nData was < maxSize.
DPxWriteRam(bufferAddress, ramBuffer)
return bufferAddress + nData * nChans
[docs]def DPxSetDacSchedule(scheduleOnset, scheduleRate, rateUnits, maxScheduleFrames, channelList=None, bufferBaseAddress=0, numBufferFrames=None):
"""Configure a schedule for autonomous DAC analog signal acquisition.
This function is used to fully setup an acquisition schedule on the device. Regardless of the actual format chosen, the resulting sample rate cannot exceed 1 MHz.
It returns a dictionary that is needed when reading data or updating the buffer.
Use ReadAdcBuffer to upload the acquired data from this address after calling StartAdcSchedule.
Note that every call to StartAdcSchedule must be preceeded by a call to
SetAdcSchedule (ie: multiple calls to StartAdcSchedule each require their own call to SetAdcSchedule).
Args:
onSet (float): The desired delay (in double precision seconds) between schedule initiation, and the first ADC sample acquisition.
rateValue (int): The rate at which the ADC's acquire successive samples.
rateUnits (str): This can have three values: "Hz" for samples/seconds, "video" for samples/video frame or "nano" for seconds/samples
maxScheduleFrames (int): If the dataset has a known length, then maxScheduleFrames should be that number. If it is a dynamic length, pass 0.
channelList (list): List of the DAC channels which should be updated from the waveform buffer. The list should contain 1 or more integers in the range 0 toGetDacNumChannels-1.
bufferBaseAddress (int): The start of the RAM buffer which should hold the acquired data inside the Datapixx. Default value is 4e6.
numBufferFrames (int): Specifies the desired size of the acquisition buffer in the Datapixx RAM. Default value of maxScheduleFrames. If maxScheduleFrames is larger than numBufferFrames (or 0), then each time the acquisition frame counter
reaches a multiple of numBufferFrames, the acquisition buffer address automatically wraps back to bufferBaseAddress. This circular buffer effect can be used for acquiring arbitrarily long analog datasets.
Simply monitor newBufferFrames returned by GetAdcStatus, and use ReadAdcBuffer in streaming mode to upload newly acquired data from the Datapixx RAM to the host.
Returns:
DACDictionary (dict): Returns a dictionary which has some global information which must be passed to other DAC functions.
"""
#NumBufferFrames
if numBufferFrames == None:
numBufferFrames = maxScheduleFrames
retList = {}
# OnSet
if (scheduleOnset < 0):
print('onSet must be a single number > 0.')
return
if (scheduleOnset > 4.30):
print('onSet must be smaller than 4.29 seconds.')
return
#RateUnits (either 1,2 or 3 or "video", "hz" or "nano"
if (rateUnits in [1,2,3]):
if rateUnits == 1:
rateUnitNumber = DPXREG_SCHED_CTRL_RATE_HZ
rateUnits = 'Hz'
if rateUnits == 2:
rateUnitNumber = DPXREG_SCHED_CTRL_RATE_XVID
rateUnits = 'video'
if rateUnits == 3:
rateUnitNumber = DPXREG_SCHED_CTRL_RATE_NANO
rateUnits = 'nano'
elif (rateUnits.upper() in api_constants):
rateUnitNumber = api_constants[rateUnits.upper()]
else:
print('rateUnits must be "hz", "video" or "nano".')
return
#RateCheck
if rateUnitNumber == DPXREG_SCHED_CTRL_RATE_HZ: #Hz
schedRateHz = scheduleRate;
elif rateUnitNumber == DPXREG_SCHED_CTRL_RATE_XVID: #Rate per video frame
schedRateHz = scheduleRate * DPxGetVidVFreq();
elif rateUnitNumber == DPXREG_SCHED_CTRL_RATE_NANO: #Seconds/samples
schedRateHz = 1 / scheduleRate;
if (schedRateHz > 1.0e6):
print('Frequncy too high')
return
if (scheduleRate < 0):
print('Frequency < 0')
return
if (scheduleRate > 0xffffffff):
print('Period too large')
return
#maxScheduleFrames
if maxScheduleFrames < 0:
print('MaxSchedFrames must be a positive number')
return
#channelList
nChans = 1; # Default
DPxDisableDacBuffAllChans()
if channelList == None:
nChans = 1;
DPxEnableDacBuffChan(0);
else: # check shape of the channelList argument
dimensions = np.shape(channelList)
if (len(dimensions) == 1):
# Only channels
nChans = len(channelList)
for i in range(nChans):
#print('Enabling the channel {0}'.format(i))
chan = channelList[i]
DPxEnableDacBuffChan(chan);
else:
print('Channel List is not shaped properly, should be a 2D List of this form [chanNum, chanNum2, ...]')
return
#BufferBaseAddress
if bufferBaseAddress < 0:
print('BufferBaseAddr must be > 0.')
return
# Now the fun begins
bufferSize = numBufferFrames * nChans * 2; # in bytes
# Implement
DPxSetDacSched(scheduleOnset, scheduleRate, rateUnits, maxScheduleFrames);
DPxSetDacBuff(bufferBaseAddress, bufferSize);
retList = {}
retList['numDacSchedChans'] = nChans
retList['channelList'] = channelList
retList['numBufferFrames'] = numBufferFrames
retList['currentWriteFrame'] = bufferBaseAddress + bufferSize
retList['maxScheduleFrames'] = maxScheduleFrames
retList['numAdcStreamOverflows'] = 0
retList['newBufferFrames'] = 0 # No new frames at the start
return retList
[docs]def DPxGetDacStatus(inDict):
"""Updates the information dictionary for the DAC schedule.
Args:
inDict (dict): The dictionary returned by the schedule setup
Updates the dictionary with the following information:
"scheduleRunning" is True if the DAC schedule is currently running, or False if stopped.
"scheduleOnset" is the programmed delay in seconds between StartAdcSchedule execution, and the first ADC sample acquisition.
"scheduleRate" is the rate at which subsequent ADC samples are acquired.
"scheduleRateUnits" is the programmed units of scheduleRate: "Hz" is samples per second, "video" is samples per video frame, "nano" is seconds per sample
"numDacSchedChans" is the number of ADC channels scheduled for acquisition.
"channelList" is the list of channels and their reference, if enabled.
"bufferBaseAddress" is the acquisition data buffer base address within the Datapixx.
"bufferSize" is the number of bytes in the acquisition data buffer.
"numBufferFrames" is the total number of samples which fit in the acquisition data buffer.
"currentReadFrame" is the buffer frame which will be read by the next streaming call to ReadAdcBuffer.
"maxScheduleFrames", if non-0, is the value of currentWriteFrame which will automatically stop the schedule.
"""
inDict['scheduleRunning'] = True if DPxIsDacSchedRunning() else False
inDict['scheduleOnset'] = DPxGetDacSchedOnset() / 1.0e9
rate, units = DPxGetAdcSchedRate()
inDict['scheduleRate'] = rate
inDict['scheduleRateUnits'] = units
inDict['bufferBaseAddress'] = DPxGetDacBuffBaseAddr()
inDict['bufferSize'] = DPxGetDacBuffSize()
inDict['currentReadFrame'] = inDict['maxScheduleFrames'] - DPxGetDacSchedCount() if DPxIsDacSchedCountdown() else DPxGetDacSchedCount();
inDict['numStreamUnderflows'] = 0
inDict['numStreamOverflows'] = 0
#int DPxGetDinValue()
_DPxGetDinValueCall = DPxDll['DPxGetDinValue']
_DPxGetDinValueCall.restype = ctypes.c_uint
[docs]def DPxGetDinValue():
"""Gets the values of the 24 DIN bits.
Returns:
int: Bit values.
:Low-level C definition:
``int DPxGetDinValue()``
"""
return _DPxGetDinValueCall()
#void DPxSetDinDataDir(int DirectionMask)
_DPxSetDinDataDirCall = DPxDll['DPxSetDinDataDir']
_DPxSetDinDataDirCall.argtypes = [ctypes.c_int]
_DPxSetDinDataDirCall.restype = None
[docs]def DPxSetDinDataDir(direction_mask):
"""Sets the port direction mask.
Sets the port direction for each bit in ``direction_mask``. The mask is one value representing all bits from the port.
The given ``direction_mask`` will set the direction of all digital input channels. For each bit which should drive its port,
the corresponding ``direction_mask`` value should be set to 1. An hexadecimal ``direction_mask`` can be given.
For example, ``direction_mask = 0x0000F`` will enable the port for the first 4 bits on the right. All other ports will be
disabled.
Args:
int: Value which corresponds in binary to the desired open ports.
:Low-level C definition:
``void DPxSetDinDataDir(int DirectionMask)``
See Also:
:class:`DPxGetDinDataDir`, :class:`DPxSetDinDataDir`
"""
_DPxSetDinDataDirCall(direction_mask)
#int DPxGetDinDataDir()
_DPxGetDinDataDirCall = DPxDll['DPxGetDinDataDir']
_DPxGetDinDataDirCall.restype = ctypes.c_int
[docs]def DPxGetDinDataDir():
"""Gets the port direction mask.
Returns:
int: Bit set to 1 is an enabled port. Bit set to 0 is a disabled port.
:Low-level C definition:
``int DPxGetDinDataDir()``
See Also:
:class:`DPxSetDinDataDir`, :class:`DPxSetDinDataDir`
"""
return _DPxGetDinDataDirCall()
#`void DPxSetDinDataOut(int dataOut)
_DPxSetDinDataOutCall = DPxDll['DPxSetDinDataOut']
_DPxSetDinDataOutCall.restype = ctypes.c_int
_DPxSetDinDataOutCall.restype = None
[docs]def DPxSetDinDataOut(dataOut):
"""Sets the data which should be driven on each port.
In order to be able to drive the ports with the given value, the port direction has to be properly enabled.
This can be done using the ``DPxSetDinDataDir`` with the appropriate bit mask.
Args:
dataOut (int): Set bit to 1 will enable the port for that bit. Set bit to 0 will disable it.
:Low-level C definition:
``void DPxSetDinDataOut(int dataOut)``
See Also:
:class:`DPxGetDinDataDir`, :class:`DPxSetDinDataDir`
"""
_DPxSetDinDataOutCall(dataOut)
#int DPxGetDinDataOut()
_DPxGetDinDataOutCall = DPxDll['DPxGetDinDataOut']
_DPxGetDinDataOutCall.restype = ctypes.c_int
[docs]def DPxGetDinDataOut():
"""Gets the data which is being driven on each output port.
This function allows the user to get the data which is currently driven on the output port.
Returns:
int: Data which is being driven on each output port.
:Low-level C definition:
``int DPxGetDinDataOut()``
See Also:
:class:`DPxSetDinDataDir`, :class:`DPxSetDinDataDir`
"""
return _DPxGetDinDataOutCall()
#`void DPxSetDinDataOutStrength(double strength)
_DPxSetDinDataOutStrengthCall = DPxDll['DPxSetDinDataOutStrength']
_DPxSetDinDataOutStrengthCall.argtypes = [ctypes.c_double]
_DPxSetDinDataOutStrengthCall.restype = None
[docs]def DPxSetDinDataOutStrength(strength):
"""Sets the strength of the driven outputs.
This function allows the user to set the current (Ampere) strength of the driven outputs.
The implementation actual value uses ``1/16`` up to ``16/16``. So minimum strength will be ``0.0625``
and maximum will be ``1``. The strength can be increased by ``0.0625`` up to ``1``. Giving a strength
of ``0`` will thus set it to ``0.0625``. Giving a strength between ``0.0625`` and ``0.125`` will
round the given strength to one of the two increments.
The strength is the same for all channels.
Args:
strength (float): Any value in a range of 0 to 1.
:Low-level C definition:
``void DPxSetDinDataOutStrength(double strength)``
See Also:
:class:`DPxGetDinDataOutStrength`
"""
_DPxSetDinDataOutStrengthCall(strength)
#double DPxSetDinDataOutStrength()
_DPxGetDinDataOutStrengthCall = DPxDll['DPxGetDinDataOutStrength']
_DPxGetDinDataOutStrengthCall.restype = ctypes.c_double
[docs]def DPxGetDinDataOutStrength():
"""Gets the strength of the driven outputs.
This function allows the user to get the strength currently driven by the outputs.
The implementation actual values uses 1/16 up to 16/16. So minimum strength will be 0.0625
and maximum will be 1. The strength can be increased by 0.0625 up to 1.
Returns:
float: Any value in a range of 0 to 1.
:Low-level C definition:
``double DPxSetDinDataOutStrength()``
See Also:
:class:`DPxGetDinDataOutStrength`
"""
return _DPxGetDinDataOutStrengthCall()
#void DPxEnableDinStabilize()
_DPxEnableDinStabilizeCall = DPxDll['DPxEnableDinStabilize']
_DPxEnableDinStabilizeCall.restype = None
[docs]def DPxEnableDinStabilize():
"""Enables the input stabilization mode.
:Low-level C definition:
``void DPxEnableDinStabilize()``
See Also:
:class:`DPxDisableDinStabilize`, :class:`DPxIsDinStabilize`
"""
_DPxEnableDinStabilizeCall()
#void DPxDisableDinStabilize()
_DPxDisableDinStabilizeCall = DPxDll['DPxDisableDinStabilize']
_DPxDisableDinStabilizeCall.restype = None
[docs]def DPxDisableDinStabilize():
"""Disables the input stabilization mode.
Immediately recognize all DIN transitions, possibly with debouncing.
:Low-level C definition:
``void DPxDisableDinStabilize()``
See Also:
:class:`DPxEnableDinStabilize`, :class:`DPxIsDinStabilize`
"""
_DPxDisableDinStabilizeCall()
#int DPxIsDinStabilize()
_DPxIsDinStabilizeCall = DPxDll['DPxIsDinStabilize']
_DPxIsDinStabilizeCall.restype = ctypes.c_int
[docs]def DPxIsDinStabilize():
"""Verifies if the hardware calibration mode is enabled.
Returns:
int: Non-zero if DIN transitions are being stabilized.
:Low-level C definition:
``int DPxIsDinStabilize()``
See Also:
:class:`DPxDisableDinStabilize`, :class:`DPxEnableDinStabilize`
"""
return _DPxIsDinStabilizeCall()
#void DPxEnableDinDebounce()
_DPxEnableDinDebounceall = DPxDll['DPxEnableDinDebounce']
_DPxEnableDinDebounceall.restype = None
[docs]def DPxEnableDinDebounce():
"""Enables the input debounce mode.
When a DIN transitions, ignore further DIN transitions for next 30 milliseconds (good for response buttons)
:Low-level C definition:
``void DPxEnableDinDebounce()``
See Also:
:class:`DPxDisableDinDebounce`, :class:`DPxIsDinDebounce`
"""
_DPxEnableDinDebounceall()
#void DPxDisableDinDebounce()
_DPxDisableDinDebounceCall = DPxDll['DPxDisableDinDebounce']
_DPxDisableDinDebounceCall.restype = None
[docs]def DPxDisableDinDebounce():
"""Enables the input debounce mode.
Immediately recognize all DIN transitions (after possible stabilization).
:Low-level C definition:
``void DPxDisableDinDebounce()``
See Also:
:class:`DPxEnableDinDebounce`, :class:`DPxIsDinDebounce`
"""
_DPxDisableDinDebounceCall()
#int DPxIsDinDebounce()
_DPxIsDinDebounceCall = DPxDll['DPxIsDinDebounce']
_DPxIsDinDebounceCall.restype = ctypes.c_int
[docs]def DPxIsDinDebounce():
"""Verifies if the DIN debounce mode is enabled.
Returns:
int: Non-zero if DIN transitions are being debounced.
:Low-level C definition:
``int DPxIsDinDebounce()``
See Also:
:class:`DPxEnableDinDebounce`, :class:`DPxDisableDinDebounce`
"""
return _DPxIsDinDebounceCall()
#void DPxEnableDoutDinLoopback()
_DPxEnableDoutDinLoopbackCall = DPxDll['DPxEnableDoutDinLoopback']
_DPxEnableDoutDinLoopbackCall.restype = None
[docs]def DPxEnableDoutDinLoopback():
"""Enables loopback between digital output ports and digital inputs.
:Low-level C definition:
``void DPxEnableDoutDinLoopback()``
See Also:
:class:`DPxDisableDoutDinLoopback`, :class:`DPxIsDoutDinLoopback`
"""
_DPxEnableDoutDinLoopbackCall()
#void DPxDisableDoutDinLoopback()
_DPxDisableDoutDinLoopbackCall = DPxDll['DPxDisableDoutDinLoopback']
_DPxDisableDoutDinLoopbackCall.restype = None
[docs]def DPxDisableDoutDinLoopback():
"""Disables loopback between digital outputs and digital inputs.
Immediately recognize all DIN transitions (after possible stabilization).
:Low-level C definition:
``void DPxDisableDoutDinLoopback()``
See Also:
:class:`DPxEnableDoutDinLoopback`, :class:`DPxIsDoutDinLoopback`
"""
_DPxDisableDoutDinLoopbackCall()
#int DPxIsDoutDinLoopback()
_DPxIsDoutDinLoopbackCall = DPxDll['DPxIsDoutDinLoopback']
_DPxIsDoutDinLoopbackCall.restype = ctypes.c_int
[docs]def DPxIsDoutDinLoopback():
"""Verifies if the DIN DOUT loopback is enabled.
Returns:
int: Non-zero if DIN are driven by digital output ports.
:Low-level C definition:
``int DPxIsDoutDinLoopback()``
See Also:
:class:`DPxEnableDoutDinLoopback`, :class:`DPxDisableDoutDinLoopback`
"""
return _DPxIsDoutDinLoopbackCall()
#void DPxSetDinBuffBaseAddr(unsigned buffBaseAddr)
_DPxSetDinBuffBaseAddrCall = DPxDll['DPxSetDinBuffBaseAddr']
_DPxSetDinBuffBaseAddrCall.restype = None
[docs]def DPxSetDinBuffBaseAddr(buffBaseAddr):
"""Sets the DIN RAM buffer start address.
Must be an even value.
Args:
buffBaseAddr (int): Base address.
:Low-level C definition:
``void DPxSetDinBuffBaseAddr(unsigned buffBaseAddr)``
See Also:
:class:`DPxGetDinBuffBaseAddr`
"""
return _DPxSetDinBuffBaseAddrCall(buffBaseAddr)
#unsigned DPxGetDinBuffBaseAddr()
_DPxGetDinBuffBaseAddrCall = DPxDll['DPxGetDinBuffBaseAddr']
_DPxGetDinBuffBaseAddrCall.restype = ctypes.c_uint
[docs]def DPxGetDinBuffBaseAddr():
"""Gets the DIN RAM buffer start address.
Returns:
int: Base address.
:Low-level C definition:
``unsigned DPxGetDinBuffBaseAddr()``
See Also:
:class:`DPxSetDinBuffBaseAddr`
"""
return _DPxGetDinBuffBaseAddrCall()
#void DPxSetDinBuffWriteAddr(unsigned buffWriteAddr)
_DPxSetDinBuffWriteAddrCall = DPxDll['DPxSetDinBuffWriteAddr']
_DPxSetDinBuffWriteAddrCall.argtypes = [ctypes.c_uint]
_DPxSetDinBuffWriteAddrCall.restype = None
[docs]def DPxSetDinBuffWriteAddr(buffWriteAddr):
"""Sets RAM address from which next DIN datum will be written.
Must be an even value.
Args:
buffWriteAddr (int): Write address.
:Low-level C definition:
``void DPxSetDinBuffWriteAddr(unsigned buffWriteAddr)``
See Also:
:class:`DPxGetDinBuffWriteAddr`
"""
return _DPxSetDinBuffWriteAddrCall(buffWriteAddr)
#unsigned DPxGetDinBuffWriteAddr()
_DPxGetDinBuffWriteAddrCall = DPxDll['DPxGetDinBuffWriteAddr']
_DPxGetDinBuffWriteAddrCall.restype = ctypes.c_uint
[docs]def DPxGetDinBuffWriteAddr():
"""Gets RAM address from which next DIN datum will be written.
Returns:
int: Write address.
:Low-level C definition:
``unsigned DPxGetDinBuffWriteAddr()``
See Also:
:class:`DPxSetDinBuffWriteAddr`
"""
return _DPxGetDinBuffWriteAddrCall()
#void DPxSetDinBuffSize(unsigned buffSize)
_DPxSetDinBuffSizeCall = DPxDll['DPxSetDinBuffSize']
_DPxSetDinBuffSizeCall.argtypes = [ctypes.c_uint]
_DPxSetDinBuffSizeCall.restype = None
[docs]def DPxSetDinBuffSize(buffSize):
"""Sets Din RAM buffer size in bytes.
Must be an even value. Buffer wraps to Base after Size.
Args:
buffSize (int): Buffer size.
:Low-level C definition:
``void DPxSetDinBuffSize(unsigned buffSize)``
See Also:
:class:`DPxGetDinBuffSize`
"""
return _DPxSetDinBuffSizeCall(buffSize)
#unsigned DPxGetDinBuffSize()
_DPxGetDinBuffSizeCall = DPxDll['DPxGetDinBuffSize']
_DPxGetDinBuffSizeCall.restype = ctypes.c_uint
[docs]def DPxGetDinBuffSize():
"""Gets the Din RAM buffer size in bytes.
Returns:
int: buffer size.
:Low-level C definition:
``unsigned DPxGetDinBuffSize()``
See Also:
:class:`DPxSetDinBuffSize`
"""
return _DPxGetDinBuffSizeCall()
#void DPxSetDinBuff(unsigned buffAddr, unsigned buffSize)
_DPxSetDinBuffCall = DPxDll['DPxSetDinBuff']
_DPxSetDinBuffCall.argtypes = [ctypes.c_uint, ctypes.c_uint]
_DPxSetDinBuffCall.restype = None
[docs]def DPxSetDinBuff(buffAddr, buffSize):
"""Sets base address, write address and buffer size for Din schedules.
This function is a shortcut which assigns Size/BaseAddr/WriteAddr
Args:
buffAddr (int): Base address.
buffSize (int): Buffer size.
:Low-level C definition:
``void DPxSetDinBuff(unsigned buffAddr, unsigned buffSize)``
See Also:
:class:`DPxGetDinSchedOnset`, :class:`DPxSetDinBuffSize`, :class:`DPxSetDinBuffWriteAddr`
"""
return _DPxSetDinBuffCall(buffAddr, buffSize)
#void DPxSetDinSchedOnset(unsigned onset)
_DPxSetDinSchedOnsetCall = DPxDll['DPxSetDinSchedOnset']
_DPxSetDinSchedOnsetCall.argtypes = [ctypes.c_uint]
_DPxSetDinSchedOnsetCall.restype = None
[docs]def DPxSetDinSchedOnset(onset):
"""Sets nanosecond delay between schedule start and first Din sample.
Args:
onset (int): delay in nanoseconds.
:Low-level C definition:
``void DPxSetDinSchedOnset(unsigned onset)``
See Also:
:class:`DPxGetDinSchedOnset`
"""
return _DPxSetDinSchedOnsetCall(onset)
#`unsigned DPxGetDinSchedOnset()
_DPxGetDinSchedOnsetCall = DPxDll['DPxGetDinSchedOnset']
_DPxGetDinSchedOnsetCall.restype = ctypes.c_uint
[docs]def DPxGetDinSchedOnset():
"""Gets the nanosecond delay between schedule start and first Din sample.
Returns:
int: onset.
:Low-level C definition:
``unsigned DPxGetDinSchedOnset()``
See Also:
:class:`DPxSetDinSchedOnset`
"""
return _DPxGetDinSchedOnsetCall()
#void DPxSetDinSchedRate(unsigned rateValue, int rateUnits)
_DPxSetDinSchedRateCall = DPxDll['DPxSetDinSchedRate']
_DPxSetDinSchedRateCall.argtypes = [ctypes.c_uint, ctypes.c_int]
_DPxSetDinSchedRateCall.restype = None
[docs]def DPxSetDinSchedRate(rate, unit):
"""Sets the schedule rate.
This method allows the user to set the schedule rate. Since the rate can be given
with different units, the method also needs to have a unit associated with the rate.
If no delay is required, this method does not need to be used. Default value is 0.
Args:
rate (int): Any positive value equal to or greater than zero.
unit (str): Any of the predefined constants.
* **hz**: samples per second, maximum 1 MHz.
* **video**: samples per video frame, maximum 1 MHz.
* **nano**: sample period in nanoseconds, minimum 1000 ns.
:Low-level C definition:
``void DPxSetDinSchedRate(unsigned rateValue, int rateUnits)``
"""
_DPxSetDinSchedRateCall(rate, api_constants[unit.upper()])
#unsigned DPxGetDinSchedRate(int *rateUnits)
_DPxGetDinSchedRateCall = DPxDll['DPxGetDinSchedRate']
_DPxGetDinSchedRateCall.restype = ctypes.c_uint
[docs]def DPxGetDinSchedRate():
"""This function gets the Din schedule rate and the rate unit.
Return value: (schedule rate, rate unit)
:Low-level C definition:
``unsigned DPxGetDinSchedRate(int *rateUnits)``
"""
Var = 0
p_Var = ctypes.c_int(Var)
return (_DPxGetDinSchedRateCall(ctypes.byref(p_Var)) , rate_constants[p_Var.value])
#void DPxSetDinSchedCount(unsigned count)
_DPxSetDinSchedCountCall = DPxDll['DPxSetDinSchedCount']
_DPxSetDinSchedCountCall.argtypes = [ctypes.c_uint]
_DPxSetDinSchedCountCall.restype = None
[docs]def DPxSetDinSchedCount(count):
"""Sets Din schedule update count.
Args:
count (int): Schedule count.
:Low-level C definition:
``void DPxSetDinSchedCount(unsigned count)``
See Also:
:class:`DPxGetDinSchedCount`
"""
return _DPxSetDinSchedCountCall(count)
#unsigned DPxGetDinSchedCount()
_DPxGetDinSchedCountCall = DPxDll['DPxGetDinSchedCount']
_DPxGetDinSchedCountCall.restype = ctypes.c_uint
[docs]def DPxGetDinSchedCount():
"""Gets Din schedule update count.
Returns:
int: Schedule sample count.
:Low-level C definition:
``unsigned DPxGetDinSchedCount()``
See Also:
:class:`DPxSetDinSchedCount`
"""
return _DPxGetDinSchedCountCall()
#void DPxEnableDinSchedCountdown()
_DPxEnableDinSchedCountdownCall = DPxDll['DPxEnableDinSchedCountdown']
_DPxEnableDinSchedCountdownCall.restype = None
[docs]def DPxEnableDinSchedCountdown():
"""Enables Din schedule count down.
SchedCount decrements at SchedRate, and schedule stops automatically when count hits 0.
:Low-level C definition:
``void DPxEnableDinSchedCountdown()``
See Also:
:class:`DPxDisableDinSchedCountdown`, :class:`DPxIsDinSchedCountdown`
"""
_DPxEnableDinSchedCountdownCall()
#void DPxDisableDinSchedCountdown()
_DPxDisableDinSchedCountdownCall = DPxDll['DPxDisableDinSchedCountdown']
_DPxDisableDinSchedCountdownCall.restype = None
[docs]def DPxDisableDinSchedCountdown():
"""Disables Din schedule count down.
SchedCount increments at SchedRate, and schedule is stopped by calling SchedStop.
:Low-level C definition:
``void DPxDisableDinSchedCountdown()``
See Also:
:class:`DPxEnableDinSchedCountdown`, :class:`DPxIsDinSchedCountdown`
"""
_DPxDisableDinSchedCountdownCall()
#int DPxIsDinSchedCountdown()
_DPxIsDinSchedCountdownCall = DPxDll['DPxIsDinSchedCountdown']
_DPxIsDinSchedCountdownCall.restype = ctypes.c_int
[docs]def DPxIsDinSchedCountdown():
"""Verifies if RAM buffering is enabled for a Din channel.
Returns:
int: Non-zero if SchedCount decrements to 0 and automatically stops schedule.
:Low-level C definition:
``int DPxIsDinSchedCountdown()``
See Also:
:class:`DPxEnableDinSchedCountdown`, :class:`DPxDisableDinSchedCountdown`
"""
return _DPxIsDinSchedCountdownCall()
#void DPxSetDinSched(unsigned onset, unsigned rateValue, int rateUnits, unsigned count)
_DPxSetDinSchedCall = DPxDll['DPxSetDinSched']
_DPxSetDinSchedCall.restype = None
[docs]def DPxSetDinSched(onset, rateValue, rateUnits, count):
"""Sets Din schedule onset, count and rate.
This function is a shortcut which assigns Onset/Rate/Count. If ``count`` is greater than zero, the count
down mode is enabled.
Args:
onset (int): Schedule onset.
rateValue (int): Rate value.
rateUnits (str): Usually ``hz``. Can also be ``video`` to update every ``rateValue`` video frames or ``nano`` to update every ``rateValue`` nanoseconds.
count (int): Schedule count.
:Low-level C definition:
``void DPxSetDinSched(unsigned onset, unsigned rateValue, int rateUnits, unsigned count)``
"""
return _DPxSetDinSchedCall(onset, rateValue, api_constants[rateUnits.upper()], count)
#void DPxStartDinSched()
_DPxStartDinSchedCall = DPxDll['DPxStartDinSched']
_DPxStartDinSchedCall.restype = None
[docs]def DPxStartDinSched():
"""Starts running a Din schedule.
:Low-level C definition:
``void DPxStartDinSched()``
See Also:
:class:`DPxStopDinSched`, :class:`DPxIsDinSchedRunning`
"""
_DPxStartDinSchedCall()
#void DPxStopDinSched()
_DPxStopDinSchedCall = DPxDll['DPxStopDinSched']
_DPxStopDinSchedCall.restype = None
[docs]def DPxStopDinSched():
"""Stops running a Din schedule.
:Low-level C definition:
``c``
See Also:
:class:`DPxStartDinSched`, :class:`DPxIsDinSchedRunning`
"""
_DPxStopDinSchedCall()
#int DPxIsDinSchedRunning()
_DPxIsDinSchedRunningCall = DPxDll['DPxIsDinSchedRunning']
_DPxIsDinSchedRunningCall.restype = ctypes.c_int
[docs]def DPxIsDinSchedRunning():
"""Verifies if a Din schedule is currently running.
Returns:
int: Non-zero if a Din schedule is currently running, zero otherwise.
:Low-level C definition:
``int DPxIsDinSchedRunning()``
See Also:
:class:`DPxStartDinSched`, :class:`DPxStopDinSched`
"""
return _DPxIsDinSchedRunningCall()
#void DPxEnableDinLogTimetags()
_DPxEnableDinLogTimetagsCall = DPxDll['DPxEnableDinLogTimetags']
_DPxEnableDinLogTimetagsCall.restype = None
#void DPxDisableDinLogTimetags()
_DPxDisableDinLogTimetagsCall = DPxDll['DPxDisableDinLogTimetags']
_DPxDisableDinLogTimetagsCall.restype = None
#int DPxIsDinLogTimetags()
_DPxIsDinLogTimetagsCall = DPxDll['DPxIsDinLogTimetags']
_DPxIsDinLogTimetagsCall.restype = ctypes.c_int
#void DPxEnableDinLogEvents()
_DPxEnableDinLogEventsCall = DPxDll['DPxEnableDinLogEvents']
_DPxEnableDinLogEventsCall.restype = None
[docs]def DPxEnableDinLogEvents():
"""Enables log events mode.
Each DIN transition is automatically logged. No schedule is required. Best way to log response buttons.
:Low-level C definition:
``void DPxEnableDinLogEvents()``
See Also:
:class:`DPxDisableDinLogEvents`, :class:`DPxIsDinLogEvents`
"""
_DPxEnableDinLogEventsCall()
#void DPxDisableDinLogEvents()
_DPxDisableDinLogEventsCall = DPxDll['DPxDisableDinLogEvents']
_DPxDisableDinLogEventsCall.restype = None
[docs]def DPxDisableDinLogEvents():
"""Disables log events mode.
Disables automatic logging of DIN transitions. A schedule is required to look at DIN transitions.
:Low-level C definition:
``void DPxDisableDinLogEvents()``
See Also:
:class:`DPxDisableDinLogEvents`, :class:`DPxIsDinLogEvents`
"""
_DPxDisableDinLogEventsCall()
#int DPxIsDinLogEvents()
_DPxIsDinLogEventsCall = DPxDll['DPxIsDinLogEvents']
_DPxIsDinLogEventsCall.restype = ctypes.c_int
[docs]def DPxIsDinLogEvents():
"""Verifies if the Din timetag mode is enable.
Returns:
int: Non-zero if DIN transitions are being logged to RAM buffer.
:Low-level C definition:
``int DPxIsDinLogEvents()``
See Also:
:class:`DPxDisableDinLogEvents`, :class:`DPxEnableDinLogEvents`
"""
return _DPxIsDinLogEventsCall()
[docs]def DPxSetDinLog(buffBaseAddr = 12000000, numBuffFrames = 1000):
"""Configure digital input transition logging. The log reports rising and falling
edges of the digital inputs, with associated timetags, and is the best way to
monitor button box responses or read parallel port data.
Note that the first call to StartDinLog must be preceeded by a call to SetDinLog
to initialize and clear the log. Once SetDinLog has been called, StartDinLog and
StopDinLog may be called multiple times to enable and disable logging.
Note that logged timetags are implemented in hardware with microsecond
precision.
Args:
bufferBaseAddress (int):Specifies the start of the RAM buffer which should hold the
logged data inside the Datapixx. Use ReadDinLog to upload the logged data from
this address after calling StartDinLog.
numBufferFrames (int): Specifies the desired size of the log buffer in the Datapixx
RAM. This buffer is circular, so it must be large enough to hold all logged
transitions between successive calls to ReadDinLog. newLogFrames returned by
GetDinStatus indicates the number of transitions logged since the last call to ReadDinLog.
See Also:
:class:`EnableDinDebounce`, :class:`StartDinLog`, :class:`StopDinLog`, :class:`GetDinStatus`, :class:`ReadDinLog`
"""
if int(buffBaseAddr) < 0 or int(buffBaseAddr) & 1:
print('bufferBaseAddress must be a single even number >= 0.')
return
if int(numBuffFrames) <= 0:
print('numBufferFrames must be a single number > 0.')
return
retList = {}
retList['currentReadFrame'] = 0
retList['numLogUnderflows'] = 0
buffSize = int(numBuffFrames * 10)
if (buffBaseAddr + buffSize > DPxGetRamSize()):
print('PsychError_user, "Specified buffer exceeds Datapixx RAM.')
DPxSetDinBuff(int(buffBaseAddr), int(buffSize))
DPxEnableDinLogTimetags()
DPxEnableDinStabilize()
return retList
def DPxStartDinLog():
DPxEnableDinLogEvents()
def DPxStopDinLog():
DPxDisableDinLogEvents()
[docs]def DPxGetDinStatus(inDict):
"""Takes a dictionary and populates it with the following digital input status information:
Args:
inDict (Dictionary) :
* "doutDinLoopback" is 1 if digital inputs are driven internally by digital outputs, or 0 if digital inputs report real inputs from db-25 connector.
* "dataDirection" is a mask showing which of the 24 bits are driving their outputs.
* "dataOutStrength" is the drive strength for the ports whose outputs have been enabled by SetDinDataDirection.
* "debounce" is 1 if digital inputs are debounced for 30 milliseconds.
* "logRunning" is 1 if transition logging is currently active, or 0 if stopped.
* "bufferBaseAddress" is the acquisition data buffer base address within the Datapixx.
* "bufferSize" is the number of bytes in the acquisition data buffer.
* "numBufferFrames" is the total number of samples which fit in the acquisition data buffer.
* "currentWriteFrame" is the buffer frame which will be written by the next acquired sample.
* "currentReadFrame" is the buffer frame which will be read by the next call to ReadDinLog.
* "newLogFrames" = currentWriteFrame - currentReadFrame. This is the maximum number of frames which can be read by the next call to ReadDinLog, without causing an underflow.
* "numLogUnderflows" is the number of ReadDinLog underflows which have occurred since SetDinLog. See ReadDinLog for details. See DatapixxSimonGame, DatapixxDin*Demo files for examples.
See Also:
:class:`SetDinLog`, :class:`StartDinLog`, :class:`StopDinLog`, :class:`ReadDinLog`
"""
inDict['doutDinLoopback'] = True if DPxIsDoutDinLoopback() != 0 else False
inDict['dataDirection'] = DPxGetDinDataDir();
inDict['dataOutStrength'] = DPxGetDinDataOutStrength()
inDict['debounce'] = True if DPxIsDinDebounce() != 0 else False
inDict['logRunning'] = True if DPxIsDinLogEvents() != 0 else False
inDict['bufferBaseAddress'] = DPxGetDinBuffBaseAddr()
inDict['bufferSize'] = DPxGetDinBuffSize()
inDict['numBufferFrames'] = DPxGetDinBuffSize() // 10
logBaseAddr = DPxGetDinBuffBaseAddr()
logSize = DPxGetDinBuffSize()
logWriteAddr = DPxGetDinBuffWriteAddr()
logReadAddr = logBaseAddr + (((inDict['currentReadFrame'] * 10) % logSize) if logSize != 0 else 0);
newLogSize = (logWriteAddr - logReadAddr) if (logWriteAddr >= logReadAddr) else logWriteAddr + logSize - logReadAddr;
newLogFrames = newLogSize // 10;
currWriteFrame = inDict['currentReadFrame'] + newLogFrames;
inDict['currentWriteFrame'] = currWriteFrame
inDict['newLogFrames'] = newLogFrames
[docs]def DPxReadDinLog(inDict, nReadFrames = 0):
"""Upload digital input data from a Datapixx internal log buffer to the local host.
Args:
inDict (Dictionary) :
* "logData" is a row vector of acquired digital input values. Each column of the vector contains an unsigned integer with the new state of digital inputs 0 to 15 after a transition.
* "logTimetags" is a row vector of acquisition timetags, indicating when the corresponding transition to the state in logData occurred. The timetags are in double precision seconds since Datapixx powerup. Response times can be calculated by calling SetMarker() at stimulus onset, then subtracting GetMarker() from the logged timetags.
* "underflow" is set to 1 if calls to ReadDinLog read too many frames. The newLogFrames field returned by GetDinStatus indicates the maximum number of frames which can be read by ReadDinLog. If more than this number of frames is read, an underflow occurs and there will be errors in the logged data. In addition to returning an underflow flag, the numLogUnderflows field returned by GetDinStatus will be incremented. See DatapixxSimonGame, DatapixxDin*Demo files for examples.
nReadFrames (int) : The number of frames to upload, and should not exceed
newLogFrames returned by GetDinStatus. If numFrames argument is missing,
ReadDinLog will return all remaining logged data.
See Also:
:class:`SetDinLog`, :class:`StartDinLog`, :class:`StopDinLog`, :class:`GetDinStatus`
"""
currDinReadFrame = inDict['currentReadFrame']
logBaseAddr = DPxGetDinBuffBaseAddr()
logSize = DPxGetDinBuffSize()
logWriteAddr = DPxGetDinBuffWriteAddr()
logReadAddr = logBaseAddr + (((currDinReadFrame * 10) % logSize) if logSize != 0 else 0)
newLogSize = (logWriteAddr - logReadAddr) if (logWriteAddr >= logReadAddr) else (logWriteAddr + logSize - logReadAddr)
newLogFrames = newLogSize // 10
nReadFrames = newLogFrames if (nReadFrames == 0) else nReadFrames
currDinReadFrame += nReadFrames
inDict['currentReadFrame'] = currDinReadFrame
if (nReadFrames > newLogFrames):
inDict['underflow'] = True
inDict['numLogUnderflows'] = inDict['numLogUnderflows'] + 1
dpxRamBufferSize = 0xfff0
#Read back the requested data
nReadShorts = nReadFrames * 5
retVal = []
while (nReadShorts > 0) :
# How many shorts should we read in this iteration?
nCopyShorts = nReadShorts
if (nCopyShorts > dpxRamBufferSize // 2):
nCopyShorts = dpxRamBufferSize // 2
nShortsUntilWrap = (logBaseAddr + logSize - logReadAddr) // 2
if (nCopyShorts > nShortsUntilWrap):
nCopyShorts = nShortsUntilWrap
nReadShorts -= nCopyShorts;
ramBuff = DPxReadRam(logReadAddr, nCopyShorts)
# And treat the uploaded data
for iCopyShort in range(0, nCopyShorts, 5):
retVal.append([(ramBuff[iCopyShort] + (ramBuff[iCopyShort+1] << np.uint64(16)) + (ramBuff[iCopyShort+2]<< np.uint64(32)) + (ramBuff[iCopyShort+3]<< np.uint64(48))) / 1e9, ramBuff[iCopyShort+4]])
#Update the Datapixx buffer read address for the next read
logReadAddr += nCopyShorts*2
if (logReadAddr >= logBaseAddr + logSize):
logReadAddr -= logSize
return retVal
#int DPxGetDoutNumBits()
_DPxGetDoutNumBitsCall = DPxDll['DPxGetDoutNumBits']
_DPxGetDoutNumBitsCall.restype = ctypes.c_int
[docs]def DPxGetDoutNumBits():
"""Gets the number of bits available.
This method returns the number of digital output bits in the system (24 in current implementation).
Returns:
int: Number of bits.
:Low-level C definition:
``int DPxGetDoutNumBits()``
"""
return _DPxGetDoutNumBitsCall()
#void DPxSetDoutValue(int bitValue, int bitMask)
_DPxSetDoutValueCall = DPxDll['DPxSetDoutValue']
_DPxSetDoutValueCall.argtypes = [ctypes.c_int, ctypes.c_int]
_DPxSetDoutValueCall.restype = None
[docs]def DPxSetDoutValue(bit_value, bit_mask):
"""Sets the port direction mask.
Sets the port direction for each bit in ``bit_mask``. The mask is one value representing all bits from the port.
The given ``bit_mask`` will set the direction of all digital input channels. For each bit which should drive its port,
the corresponding ``direction_mask`` value should be set to 1. An hexadecimal ``direction_mask`` can be given.
For example, ``bit_mask = 0x0000F`` will enable the port for the first 4 bits on the right. All other ports will be
disabled.
Args:
bit_value (int): value of bits.
bit_mask (int): Turns on or off the specific Digital Out channel. 1 for on, 0 for off.
:Low-level C definition:
``void DPxSetDoutValue(int bitValue, int bitMask)``
"""
_DPxSetDoutValueCall(bit_value, bit_mask)
#int DPxGetDoutValue()
_DPxGetDoutValueCall = DPxDll['DPxGetDoutValue']
_DPxGetDoutValueCall.restype = ctypes.c_int
[docs]def DPxGetDoutValue():
"""Gets the values of the 24 Dout bits.
Returns:
int: Bit values.
:Low-level C definition:
``int DPxGetDoutValue()``
"""
return _DPxGetDoutValueCall()
#void DPxEnableDoutButtonSchedules()
_DPxEnableDoutButtonSchedulesCall = DPxDll['DPxEnableDoutButtonSchedules']
_DPxEnableDoutButtonSchedulesCall.restype = None
#void DPxDisableDoutButtonSchedules()
_DPxDisableDoutButtonSchedulesCall = DPxDll['DPxDisableDoutButtonSchedules']
_DPxDisableDoutButtonSchedulesCall.restype = None
#void DPxSetDoutButtonSchedulesMode()
_DPxSetDoutButtonSchedulesMode = DPxDll['DPxSetDoutButtonSchedulesMode']
_DPxSetDoutButtonSchedulesMode.restype = None
#int DPxGetDoutButtonSchedulesMode()
_DPxGetDoutButtonSchedulesMode = DPxDll['DPxSetDoutButtonSchedulesMode']
_DPxGetDoutButtonSchedulesMode.restype = ctypes.c_uint16
#int DPxIsDoutButtonSchedules()
_DPxIsDoutButtonSchedulesCall = DPxDll['DPxIsDoutButtonSchedules']
_DPxIsDoutButtonSchedulesCall.restype = ctypes.c_int
#void DPxEnableDoutBacklightPulse()
_DPxEnableDoutBacklightPulseCall = DPxDll['DPxEnableDoutBacklightPulse']
_DPxEnableDoutBacklightPulseCall.restype = None
[docs]def DPxEnableDoutBacklightPulse():
"""Enables the Dout backlight pulse mode.
LCD backlight LED are controlled by DOUT15. Can be used to make a tachistoscope by pulsing DOUT15 with a schedule.
:Low-level C definition:
``void DPxEnableDoutBacklightPulse()``
See Also:
:class:`DPxDisableDoutBacklightPulse`, :class:`DPxIsDoutBacklightPulse`
"""
_DPxEnableDoutBacklightPulseCall()
#void DPxDisableDoutBacklightPulse()
_DPxDisableDoutBacklightPulseCall = DPxDll['DPxDisableDoutBacklightPulse']
_DPxDisableDoutBacklightPulseCall.restype = None
[docs]def DPxDisableDoutBacklightPulse():
"""Disables the Dout backlight pulse mode.
LCD backlight LEDs are unaffected by DOUT system.
:Low-level C definition:
``void DPxDisableDoutBacklightPulse()``
See Also:
:class:`DPxEnableDoutBacklightPulse`, :class:`DPxIsDoutBacklightPulse`
"""
_DPxDisableDoutBacklightPulseCall()
#int DPxIsDoutBacklightPulse()
_DPxIsDoutBacklightPulseCall = DPxDll['DPxIsDoutBacklightPulse']
_DPxIsDoutBacklightPulseCall.restype = ctypes.c_int
[docs]def DPxIsDoutBacklightPulse():
"""Verifies if the Dout backlight pulse mode is enabled.
Returns:
int: Non-zero if LCD backlight LED enables are gated by DOUT15.
:Low-level C definition:
``int DPxIsDoutBacklightPulse()``
See Also:
:class:`DPxEnableDoutBacklightPulse`, :class:`DPxDisableDoutBacklightPulse`
"""
return _DPxIsDoutBacklightPulseCall()
#void DPxSetDoutBuffBaseAddr(unsigned buffBaseAddr)
_DPxSetDoutBuffBaseAddrCall = DPxDll['DPxSetDoutBuffBaseAddr']
_DPxSetDoutBuffBaseAddrCall.argtypes = [ctypes.c_uint]
_DPxSetDoutBuffBaseAddrCall.restype = None
[docs]def DPxSetDoutBuffBaseAddr(buffBaseAddr):
"""Sets the Dout RAM buffer start address.
Must be an even value.
Args:
buffBaseAddr (int): Base address.
:Low-level C definition:
``void DPxSetDoutBuffBaseAddr(unsigned buffBaseAddr)``
See Also:
:class:`DPxGetDoutBuffBaseAddr`
"""
return _DPxSetDoutBuffBaseAddrCall(buffBaseAddr)
#unsigned DPxGetDoutBuffBaseAddr()
_DPxGetDoutBuffBaseAddrCall = DPxDll['DPxGetDoutBuffBaseAddr']
_DPxGetDoutBuffBaseAddrCall.restype = ctypes.c_uint
[docs]def DPxGetDoutBuffBaseAddr():
"""Gets the Dout RAM buffer start address.
Returns:
int: Base address.
:Low-level C definition:
``unsigned DPxGetDoutBuffBaseAddr()``
See Also:
:class:`DPxSetDoutBuffBaseAddr`
"""
return _DPxGetDoutBuffBaseAddrCall()
#void DPxSetDoutBuffReadAddr(unsigned buffReadAddr)
_DPxSetDoutBuffReadAddrCall = DPxDll['DPxSetDoutBuffReadAddr']
_DPxSetDoutBuffReadAddrCall.argtypes = [ctypes.c_uint]
_DPxSetDoutBuffReadAddrCall.restype = None
[docs]def DPxSetDoutBuffReadAddr(buffReadAddr):
"""Sets RAM address from which next Dout datum will be read.
Must be an even value.
Args:
buffReadAddr (int): Read address.
:Low-level C definition:
``void DPxSetDoutBuffReadAddr(unsigned buffReadAddr)``
See Also:
:class:`DPxGetDoutBuffReadAddr`
"""
return _DPxSetDoutBuffReadAddrCall(buffReadAddr)
#unsigned DPxGetDoutBuffReadAddr()
_DPxGetDoutBuffReadAddrCall = DPxDll['DPxGetDoutBuffReadAddr']
_DPxGetDoutBuffReadAddrCall.restype = ctypes.c_uint
[docs]def DPxGetDoutBuffReadAddr():
"""Gets RAM address from which next Dout datum will be read.
Returns:
int: Read address.
:Low-level C definition:
``unsigned DPxGetDoutBuffReadAddr()``
See Also:
:class:`DPxSetDoutBuffReadAddr`
"""
return _DPxGetDoutBuffReadAddrCall()
#void DPxSetDoutBuffSize(unsigned buffSize)
_DPxSetDoutBuffSizeCall = DPxDll['DPxSetDoutBuffSize']
_DPxSetDoutBuffSizeCall.argtypes = [ctypes.c_uint]
_DPxSetDoutBuffSizeCall.restype = None
[docs]def DPxSetDoutBuffSize(buffSize):
"""Sets Dout RAM buffer size in bytes.
Must be an even value. Buffer wraps to Base after Size.
Args:
buffSize (int): Buffer size.
:Low-level C definition:
``void DPxSetDoutBuffSize(unsigned buffSize)``
See Also:
:class:`DPxGetDoutBuffReadAddr`
"""
return _DPxSetDoutBuffSizeCall(buffSize)
#unsigned DPxGetDoutBuffSize()
_DPxGetDoutBuffSizeCall = DPxDll['DPxGetDoutBuffSize']
_DPxGetDoutBuffSizeCall.restype = ctypes.c_uint
[docs]def DPxGetDoutBuffSize():
"""Gets the Dout RAM buffer size in bytes.
Returns:
int: buffer size.
:Low-level C definition:
``unsigned DPxGetDoutBuffSize()``
See Also:
:class:`DPxSetDoutBuffSize`
"""
return _DPxGetDoutBuffSizeCall()
#void DPxSetDoutBuff(unsigned buffAddr, unsigned buffSize)
_DPxSetDoutBuffCall = DPxDll['DPxSetDoutBuff']
_DPxSetDoutBuffCall.argtypes = [ctypes.c_uint, ctypes.c_uint]
_DPxSetDoutBuffCall.restype = None
[docs]def DPxSetDoutBuff(buffAddr, buffSize):
"""Sets base address, read address and buffer size for Dout schedules.
This function is a shortcut which assigns Size/BaseAddr/ReadAddr
Args:
buffAddr (int): Base address.
buffSize (int): Buffer size.
:Low-level C definition:
``void DPxSetDoutBuff(unsigned buffAddr, unsigned buffSize)``
See Also:
:class:`DPxGetDoutSchedOnset`, :class:`DPxSetDoutBuffSize`, :class:`DPxSetDoutBuffReadAddr`
"""
return _DPxSetDoutBuffCall(buffAddr, buffSize)
#void DPxSetDoutSchedOnset(unsigned onset)
_DPxSetDoutSchedOnsetCall = DPxDll['DPxSetDoutSchedOnset']
_DPxSetDoutSchedOnsetCall.argtypes = [ctypes.c_uint]
_DPxSetDoutSchedOnsetCall.restype = None
[docs]def DPxSetDoutSchedOnset(onset):
"""Sets nanosecond delay between schedule start and first Dout update.
Args:
onset (int): delay in nanoseconds.
:Low-level C definition:
``void DPxSetDoutSchedOnset(unsigned onset)``
See Also:
:class:`DPxGetDoutSchedOnset`
"""
return _DPxSetDoutSchedOnsetCall(onset)
#unsigned DPxGetDoutSchedOnset()
_DPxGetDoutSchedOnsetCall = DPxDll['DPxGetDoutSchedOnset']
_DPxGetDoutSchedOnsetCall.restype = ctypes.c_uint
[docs]def DPxGetDoutSchedOnset():
"""Gets the nanosecond delay between schedule start and first Dout update.
Returns:
int: onset.
:Low-level C definition:
``unsigned DPxGetDoutSchedOnset()``
See Also:
:class:`DPxSetDoutSchedOnset`
"""
return _DPxGetDoutSchedOnsetCall()
#void DPxSetDoutSchedRate(unsigned rateValue, int rateUnits)
_DPxSetDoutSchedRateCall = DPxDll['DPxSetDoutSchedRate']
_DPxSetDoutSchedRateCall.argtypes = [ctypes.c_uint, ctypes.c_int]
_DPxSetDoutSchedRateCall.restype = None
[docs]def DPxSetDoutSchedRate(rate, unit):
"""Sets the schedule rate.
This method allows the user to set the schedule rate. Since the rate can be given
with different units, the method also needs to have a unit associated with the rate.
Args:
rate (int): Any positive value equal to or greater than zero.
unit (str): Any of the predefined constants.
* **hz**: rate updates per second, maximum 10 MHz.
* **video**: rate updates per video frame, maximum 10 MHz.
* **nano**: rate updates period in nanoseconds, minimum 100 ns.
:Low-level C definition:
``void DPxSetDoutSchedRate(unsigned rateValue, int rateUnits)``
"""
_DPxSetDoutSchedRateCall(rate, api_constants[unit.upper()])
#unsigned DPxGetDoutSchedRate(int *rateUnits)
_DPxGetDoutSchedRateCall = DPxDll['DPxGetDoutSchedRate']
_DPxGetDoutSchedRateCall.restype = ctypes.c_uint
[docs]def DPxGetDoutSchedRate():
"""Gets Dout schedule update rate and the rate units.
Returns:
tuple: rate and unit.
:Low-level C definition:
``unsigned DPxGetDoutSchedRate(int *rateUnits)``
See Also:
:class:`DPxSetDoutSchedRate`
"""
Var = 0
p_Var = ctypes.c_int(Var)
return (_DPxGetDoutSchedRateCall(ctypes.byref(p_Var)), rate_constants[p_Var.value])
#void DPxSetDoutSchedCount(unsigned count)
_DPxSetDoutSchedCountCall = DPxDll['DPxSetDoutSchedCount']
_DPxSetDoutSchedCountCall.argtypes = [ctypes.c_uint]
_DPxSetDoutSchedCountCall.restype = None
[docs]def DPxSetDoutSchedCount(count):
"""Sets Dout schedule update count.
Args:
count (int): Schedule count.
:Low-level C definition:
``void DPxSetDoutSchedCount(unsigned count)``
See Also:
:class:`DPxGetDoutSchedCount`
"""
return _DPxSetDoutSchedCountCall(count)
#unsigned DPxGetDoutSchedCount()
_DPxGetDoutSchedCountCall = DPxDll['DPxGetDoutSchedCount']
_DPxGetDoutSchedCountCall.restype = ctypes.c_uint
[docs]def DPxGetDoutSchedCount():
"""Gets Dout schedule update count.
Returns:
int: Schedule sample count.
:Low-level C definition:
``unsigned DPxGetDoutSchedCount()``
See Also:
:class:`DPxSetDoutSchedCount`
"""
return _DPxGetDoutSchedCountCall()
#void DPxEnableDoutSchedCountdown()
_DPxEnableDoutSchedCountdownCall = DPxDll['DPxEnableDoutSchedCountdown']
_DPxEnableDoutSchedCountdownCall.restype = None
[docs]def DPxEnableDoutSchedCountdown():
"""Enables Dout schedule count down.
SchedCount decrements at SchedRate, and schedule stops automatically when count hits 0.
:Low-level C definition:
``void DPxEnableDoutSchedCountdown()``
See Also:
:class:`DPxDisableDoutSchedCountdown`, :class:`DPxIsDoutSchedCountdown`
"""
_DPxEnableDoutSchedCountdownCall()
#`void DPxDisableDoutSchedCountdown()
_DPxDisableDoutSchedCountdownCall = DPxDll['DPxDisableDoutSchedCountdown']
_DPxDisableDoutSchedCountdownCall.restype = None
[docs]def DPxDisableDoutSchedCountdown():
"""Disables Dout schedule count down.
SchedCount increments at SchedRate, and schedule is stopped by calling SchedStop.
:Low-level C definition:
``void DPxDisableDoutSchedCountdown()``
See Also:
:class:`DPxEnableDoutSchedCountdown`, :class:`DPxIsDoutSchedCountdown`
"""
_DPxDisableDoutSchedCountdownCall()
#int DPxIsDoutSchedCountdown()
_DPxIsDoutSchedCountdownCall = DPxDll['DPxIsDoutSchedCountdown']
_DPxIsDoutSchedCountdownCall.restype = ctypes.c_int
[docs]def DPxIsDoutSchedCountdown():
"""Verifies if RAM buffering is enabled for a Dout channel.
Returns:
int: Non-zero if SchedCount decrements to 0 and automatically stops schedule.
:Low-level C definition:
``int DPxIsDoutSchedCountdown()``
See Also:
:class:`DPxEnableDoutSchedCountdown`, :class:`DPxDisableDoutSchedCountdown`
"""
return _DPxIsDoutSchedCountdownCall()
#`void DPxSetDoutSched(unsigned onset, unsigned rateValue, int rateUnits, unsigned count)
_DPxSetDoutSchedCall = DPxDll['DPxSetDoutSched']
_DPxSetDoutSchedCall.argtypes = [ctypes.c_uint, ctypes.c_uint, ctypes.c_int, ctypes.c_uint]
_DPxSetDoutSchedCall.restype = None
[docs]def DPxSetDoutSched(onset, rateValue, rateUnits, count):
"""Sets Dout schedule onset, count and rate.
This function is a shortcut which assigns Onset/Rate/Count. If ``count`` is greater than zero, the count
down mode is enabled.
Args:
onset (int): Schedule onset.
rateValue (int): Rate value.
rateUnits (str): Usually ``hz``. Can also be ``video`` to update every ``rateValue`` video frames or ``nano`` to update every ``rateValue`` nanoseconds.
count (int): Schedule count.
:Low-level C definition:
``void DPxSetDoutSched(unsigned onset, unsigned rateValue, int rateUnits, unsigned count)``
"""
return _DPxSetDoutSchedCall(onset, rateValue, api_constants[rateUnits.upper()], count)
[docs]def DPxSetDoutSchedule(scheduleOnset, scheduleRate, maxScheduleFrames, bufferAddress=int(8e6), numBufferFrames=None):
"""
Implements a digital output schedule in a DATAPixx.
Mimics the behavior of Datapixx('SetDoutSchedule') in MATLAB.
Args:
scheduleOnset (float): the audio schedule delay in seconds
scheduleRate (int or list): the sampling rate of the digital output schedule
in one of several formats:
1) 'scheduleRate' is an integer, specifying the sampling rate in Hertz
2) 'scheduleRate' is a list with 2 elements. the first element is an
integer indicating the sampling rate. the second element is either
an integer or a string indicating the sampling rate units. allowable
values for the second element are in the 'int' and 'str' columns below:
int str description
0 'hz' sampling rate specified in Hertz
1 'video' sampling rate specified in DATAPixx video frames
2 'nano' sampling rate specified in nanoseconds
NOTE: regardless of the choosen format, sampling rate cannot exceed 10 MHz
maxScheduleFrames (int): the number of samples after which the digital output schedule stops sampling.
if maxScheduleFrames > numBufferFrames, the digital output schedule loops back
to sample datum at the start address of the digital output buffer.
bufferAddress (int): memory location in DATAPixx RAM
default=int(8e6)
numBufferFrames (int): number of digital output schedule samples written into DATAPixx RAM.
NOTE: these are specified in bytes, while the data
format is int16. therefore, numBufferFrames = maxScheduleFrames*2
default = maxScheduleFrames*2
Exceptions:
1) scheduleOnset is not of type float or is less than 0
2) scheduleOnset is greater than 4.295 seconds
3) scheduleRate does not obey supported format
4) scheduleRate specifies sampling rate greater than 10 MHz, regardless of format
5) maxScheduleFrames is not of type int or is less than 0
6) maxScheduleFrames is zero and numBufferFrames was omitted
7) bufferAddress is not of type int or is less than 0 or is odd
8) numBufferFrames is not of type int or is less than 0
"""
############################## check inputs
# check scheduleOnset
if type(scheduleOnset) is not float or scheduleOnset < 0:
raise Exception("ERROR in %s\n'scheduleOnset' must be a positive float" % sys.argv[0])
scheduleOnset = int(scheduleOnset*10**9) # convert to int nanosecond delay
if scheduleOnset > 0xffffffff:
raise Exception("ERROR in %s\n'scheduleOnset' must be less than 4.295 seconds" % sys.argv[0])
# check scheduleRate
try:
if isinstance(scheduleRate,int): # integer passed
rate = scheduleRate
unit = 'hz'
elif isinstance(scheduleRate,list) and len(scheduleRate)==2: # 2 element list passed
rateUnits = ['hz','video','nano']
rate = scheduleRate[0]
# check integrity integrity of element 2
unit = scheduleRate[1]
if isinstance(unit,int): # integer in position 2
unit = rateUnits[unit] # will raise exception if out of range
elif not( isinstance(unit,str) and unit.lower() in rateUnits ): # element 2 is either not a string or not a valid string
raise Exception
else: # neither a single integer or a 2 element list passed
raise Exception
except:
raise Exception("ERROR in %s\n\nUnsupported format for argument 'scheduleRate'.\n\n" % sys.argv[0]
+"'scheduleRate' may be a single integer specifying the sampling rate in Hertz.\n\n"
+"'scheduleRate' may also be a list with 2 elements. The first element must be an\n"
+"integer indicating the sampling rate. The second element must be either\n"
+"an integer or a string indicating the sampling rate units. Allowable\n"
+"values for the second element are in the 'int' and 'str' columns below:\n\n"
+"\tint\t\tstr\t\t\tdescription\n"
+"\t0\t\t'hz'\t\tsampling rate specified in Hertz\n"
+"\t1\t\t'video'\t\tsampling rate specified in DATAPixx video frames\n"
+"\t2\t\t'nano'\t\tsampling rate specified in nanoseconds\n\n"
+"NOTE: regardless of the choosen format, sampling rate cannot exceed 10 MHz.")
# convert sample rate to Hz
if unit.lower() == 'video':
rate = round( rate * DPxGetVidVFreq() )
elif unit.lower() == 'nano':
rate = round( 10**9 / rate )
# check that sampling rate does not exceed 10 MHz
if rate > 10**7:
raise Exception("ERROR in %s\nr'scheduleRate' must not exceed 10 MHz, regardless of the choosen format" % sys.argv[0])
# check maxScheduleFrames
if type(maxScheduleFrames) is not int or maxScheduleFrames < 0:
raise Exception("ERROR in %s\n'maxScheduleFrames' must be a positive integer" % sys.argv[0])
# check that numBufferFrames is provided if maxScheduleFrames == 0
if maxScheduleFrames==0 and numBufferFrames is None:
raise Exception("ERROR in %s\n'numBufferFrames' must be provided if 'maxScheduleFrames'==0" % sys.argv[0])
# maxScheduleFrames bufferAddress
if type(bufferAddress) is not int or bufferAddress < 0 or bufferAddress & 1:
raise Exception("ERROR in %s\n'bufferAddress' must be a positive, even integer" % sys.argv[0])
# check numBufferFrames
if numBufferFrames is None: # default
numBufferFrames = maxScheduleFrames
elif type(numBufferFrames) is not int or numBufferFrames < 0:
raise Exception("ERROR in %s\n'numBufferFrames' must be a positive integer" % sys.argv[0])
numBufferFrames *= 2
# process ########################################
# schedule digital output
DPxSetDoutSched(scheduleOnset, rate, 'hz', maxScheduleFrames)
# set buffer address and size
DPxSetDoutBuffBaseAddr(bufferAddress)
DPxSetDoutBuffReadAddr(bufferAddress)
# set buffer size
DPxSetDoutBuffSize(numBufferFrames)
[docs]def DPxWriteDoutBuffer(bufferData,bufferAddress=int(8e6)):
"""
Writes the digital output waveform data in 'bufferData' to the DATAPixx RAM at memory
address 'bufferAddress'.
Mimics the behavior of Datapixx('WriteDoutBuffer') in MATLAB.
1) 'bufferData' must be of type int scaled between (0,65535)
2) 'bufferData' can be either a list or a numpy.array
3) 'bufferData' must be shaped as (N,)
Args:
bufferData (list or numpy.array): contains waveform data. if a list, must be castable to a numeric numpy.array
bufferAddress (int): memory location in DATAPixx RAM.
default = int(8e6)
Exceptions:
1) bufferData cannot be casted into a numpy.array of type int
2) bufferData is empty
3) bufferData has more than 1 dimension
4) bufferAddress is not of type int or is less than 0 or is odd
"""
############################## check inputs
# buffer data
try:
# ensure casting to numpy.array
bufferData = np.array(bufferData).squeeze() # collapse (1,N) and (N,1) arrays to (N,)
# ensure bufferData has no non-numeric elements
if not bufferData.dtype.str[1] == 'i':
raise Exception
except:
raise Exception("ERROR in %s\n'bufferData' must be a numpy.array of type int or a list castable to a numpy.array of type int" % sys.argv[0])
if not bool(bufferData.size):
raise Exception("ERROR in %s\nempty 'bufferData' passed. 'bufferData' must contain data" % sys.argv[0])
elif len(bufferData.shape) > 1:
raise Exception("ERROR in %s\n'bufferData' must have a single dimension" % sys.argv[0])
# Datapixx buffer address for writing buffer data
if not isinstance(bufferAddress,int) or bufferAddress < 0 or bufferAddress & 1:
raise Exception("ERROR in %s\n'bufferAddress' must be a positive, even integer" % sys.argv[0])
######################################### process
# Convert to short, convert to list
bufferData = bufferData.astype('int16').tolist()
# write audio wave form bufferData to buffer
chunkSize = 0xFFF0 // 4 # maximum allowable size of data per call to DPxWriteRam()
numberOfChunks = np.ceil(len(bufferData)/chunkSize).astype(int)
for i in range(numberOfChunks):
addr = chunkSize*i*2+bufferAddress
index1 = chunkSize*i
index2 = chunkSize*(i+1) if chunkSize*(i+1) < len(bufferData) else len(bufferData)
DPxWriteRam(addr, bufferData[index1:index2])
#void DPxStartDoutSched()
_DPxStartDoutSchedCall = DPxDll['DPxStartDoutSched']
_DPxStartDoutSchedCall.restype = None
[docs]def DPxStartDoutSched():
"""Starts running a Dout schedule.
:Low-level C definition:
``void DPxStartDoutSched()``
See Also:
:class:`DPxStopDoutSched`, :class:`DPxIsDoutSchedRunning`
"""
_DPxStartDoutSchedCall()
#void DPxStopDoutSched()
_DPxStopDoutSchedCall = DPxDll['DPxStopDoutSched']
_DPxStopDoutSchedCall.restype = None
[docs]def DPxStopDoutSched():
"""Stops running a Dout schedule.
:Low-level C definition:
``void DPxStopDoutSched()``
See Also:
:class:`DPxStartDoutSched`, :class:`DPxIsDoutSchedRunning`
"""
_DPxStopDoutSchedCall()
#int DPxIsDoutSchedRunning()
_DPxIsDoutSchedRunningCall = DPxDll['DPxIsDoutSchedRunning']
_DPxIsDoutSchedRunningCall.restype = ctypes.c_int
[docs]def DPxIsDoutSchedRunning():
"""Verifies if a Dout schedule is currently running.
Returns:
int: Non-zero if a Dout schedule is currently running, zero otherwise.
:Low-level C definition:
``int DPxIsDoutSchedRunning()``
See Also:
:class:`DPxStartDoutSched`, :class:`DPxStopDoutSched`
"""
return _DPxIsDoutSchedRunningCall()
#void DPxEnableDoutPixelMode()
_DPxEnableDoutPixelModeCall = DPxDll['DPxEnableDoutPixelMode']
_DPxEnableDoutPixelModeCall.restype = None
[docs]def DPxEnableDoutPixelMode():
"""Enables pixel mode.
When this function is enabled, the digital outputs show the RGB value of first upper left pixel of the screen.
In which case, digital outputs cannot be used for other purposes.
This feature is only available on VIEWPixx with firmware revision 31 and higher.
:Low-level C definition:
``void DPxEnableDoutPixelMode()``
See Also:
:class:`DPxDisableDoutPixelMode`, :class:`DPxIsDoutPixelMode`
"""
_DPxEnableDoutPixelModeCall()
#void DPxDisableDoutPixelMode()
_DPxDisableDoutPixelModeCall = DPxDll['DPxDisableDoutPixelMode']
_DPxDisableDoutPixelModeCall.restype = None
[docs]def DPxDisableDoutPixelMode():
"""Disables pixel mode.
When this function is called, the digital ouputs do not show the RGB value of first upper left pixel of the screen.
The digital outputs can then be used normally. This is the default mode.
This feature is only available on VIEWPixx with firmware revision 31 and higher.
:Low-level C definition:
``void DPxDisableDoutPixelMode()``
See Also:
:class:`DPxEnableDoutPixelMode`, :class:`DPxIsDoutPixelMode`
"""
_DPxDisableDoutPixelModeCall()
#int DPxIsDoutPixelMode()
_DPxIsDoutPixelModeCall = DPxDll['DPxIsDoutPixelMode']
_DPxIsDoutPixelModeCall.restype = ctypes.c_int
[docs]def DPxIsDoutPixelMode():
"""Verifies if the pixel mode is enabled on digital outputs.
Returns:
int: Non-zero if pixel mode is enabled, 0 if disabled.
:Low-level C definition:
``int DPxIsDoutPixelMode()``
See Also:
:class:`DPxEnableDoutPixelMode`, :class:`DPxDisableDoutPixelMode`
"""
return _DPxIsDoutPixelModeCall()
#void DPxEnableDoutPixelMode()
_DPxEnableDoutPixelModeGBCall = DPxDll['DPxEnableDoutPixelModeGB']
_DPxEnableDoutPixelModeGBCall.restype = None
[docs]def DPxEnableDoutPixelModeGB():
"""Enables pixel mode.
When this function is called, the digital outputs reflects the green and blue components of the RGB value of first upper left pixel of the screen.
In which case, pin 8 onwards of the digital outputs cannot be used for other purposes.
Note:
This feature is only available on VIEWPixx with firmware revision 31 and higher.
:Low-level C definition:
``void DPxEnableDoutPixelMode()``
See Also:
:class:`DPxDisableDoutPixelMode`, :class:`DPxIsDoutPixelMode`
"""
_DPxEnableDoutPixelModeGBCall()
#void DPxDisableDoutPixelMode()
_DPxDisableDoutPixelModeGBCall = DPxDll['DPxDisableDoutPixelModeGB']
_DPxDisableDoutPixelModeGBCall.restype = None
[docs]def DPxDisableDoutPixelModeGB():
"""Disables pixel mode.
When this function is called, the digital ouputs do not show the green and blue components of the RGB value of first upper left pixel of the screen.
The digital outputs can then be used normally. This is the default mode.
Note:
This feature is only available on VIEWPixx with firmware revision 31 and higher.
:Low-level C definition:
``void DPxDisableDoutPixelMode()``
See Also:
:class:`DPxEnableDoutPixelMode`, :class:`DPxIsDoutPixelMode`
"""
_DPxDisableDoutPixelModeGBCall()
#int DPxIsDoutPixelMode()
_DPxIsDoutPixelModeGBCall = DPxDll['DPxIsDoutPixelModeGB']
_DPxIsDoutPixelModeGBCall.restype = ctypes.c_int
[docs]def DPxIsDoutPixelModeGB():
"""Verifies if the pixel mode is enabled on digital outputs.
Returns:
int: Non-zero if pixel mode is enabled, 0 if disabled.
:Low-level C definition:
``int DPxIsDoutPixelMode()``
See Also:
:class:`DPxEnableDoutPixelMode`, :class:`DPxDisableDoutPixelMode`
"""
return _DPxIsDoutPixelModeGBCall()
#int DPxRGBToTrigger()
[docs]def DPxRGBToTrigger(color):
"""Helper function determines expected trigger from a given RGB 255 colour tuple.
Returns:
int: trigger value in decimal (base 10)
:Low-level C definition:
none
See Also:
:class:`DPxEnableDoutPixelMode`, :class:`DPxDisableDoutPixelMode`, :class:`DPxTriggerToRGB`
"""
return int( (color[2]<<16)+(color[1]<<8)+color[0] )
#list DPxTriggertoRGB()
[docs]def DPxTriggerToRGB(trigger):
"""Helper function determines pixel mode RGB 255 colour value based on desired 24-bit trigger (in decimal, base 10)
Returns:
list: list of containint [R, G, B] in RGB 255
:Low-level C definition:
none
See Also:
:class:`DPxEnableDoutPixelMode`, :class:`DPxDisableDoutPixelMode`, :class:`DPxRGBToTrigger`
"""
return [ trigger%256, (trigger>>8)%256, (trigger>>16)%256]
#void DPxEnableTouchpixx()
_DPxEnableTouchpixxCall = DPxDll['DPxEnableTouchpixx']
_DPxEnableTouchpixxCall.restype = None
[docs]def DPxEnableTouchpixx():
"""Enables the TOUCHPixx touch panel hardware subsystem.
:Low-level C definition:
``void DPxEnableTouchpixx()``
See Also:
:class:`DPxDisableTouchpixx`, :class:`DPxIsTouchpixx`
"""
_DPxEnableTouchpixxCall()
#void DPxDisableTouchpixx()
_DPxDisableTouchpixxCall = DPxDll['DPxDisableTouchpixx']
_DPxDisableTouchpixxCall.restype = None
[docs]def DPxDisableTouchpixx():
"""Disables the TOUCHPixx touch panel hardware subsystem.
:Low-level C definition:
``void DPxDisableTouchpixx()``
See Also:
:class:`DPxEnableTouchpixx`, :class:`DPxIsTouchpixx`
"""
_DPxDisableTouchpixxCall()
#int DPxIsTouchpixx()
_DPxIsTouchpixxCall = DPxDll['DPxIsTouchpixx']
_DPxIsTouchpixxCall.restype = ctypes.c_int
[docs]def DPxIsTouchpixx():
"""Verifies if a Dout schedule is currently running.
Returns:
int: Non-zero if TOUCHPixx touch panel hardware is present and enabled.
:Low-level C definition:
``int DPxIsTouchpixx()``
See Also:
:class:`DPxEnableTouchpixx`, :class:`DPxDisableTouchpixx`
"""
return _DPxIsTouchpixxCall()
#void DPxSetTouchpixxBuffBaseAddr(unsigned buffBaseAddr)
_DPxSetTouchpixxBuffBaseAddrCall = DPxDll['DPxSetTouchpixxBuffBaseAddr']
_DPxSetTouchpixxBuffBaseAddrCall.argtypes = [ctypes.c_uint]
_DPxSetTouchpixxBuffBaseAddrCall.restype = None
[docs]def DPxSetTouchpixxBuffBaseAddr(buffBaseAddr):
"""Sets the Touchpixx RAM buffer start address.
The address must be an even value.
Args:
buffBaseAddr (int): Base address.
:Low-level C definition:
``void DPxSetTouchpixxBuffBaseAddr(unsigned buffBaseAddr)``
See Also:
:class:`DPxGetTouchpixxBuffBaseAddr`
"""
return _DPxSetTouchpixxBuffBaseAddrCall(buffBaseAddr)
#unsigned DPxGetDacBuffBaseAddr()
_DPxGetTouchpixxBuffBaseAddrCall = DPxDll['DPxGetTouchpixxBuffBaseAddr']
_DPxGetTouchpixxBuffBaseAddrCall.restype = ctypes.c_uint
[docs]def DPxGetTouchpixxBuffBaseAddr():
"""Gets the Touchpixx RAM buffer start address.
Returns:
int: Base address.
:Low-level C definition:
``unsigned DPxGetDacBuffBaseAddr()``
See Also:
:class:`DPxSetTouchpixxBuffBaseAddr`
"""
return _DPxGetTouchpixxBuffBaseAddrCall()
#void DPxSetTouchpixxBuffWriteAddr(unsigned buffWriteAddr)
_DPxSetTouchpixxBuffWriteAddrCall = DPxDll['DPxSetTouchpixxBuffWriteAddr']
_DPxSetTouchpixxBuffWriteAddrCall.argtypes = [ctypes.c_uint]
_DPxSetTouchpixxBuffWriteAddrCall.restype = None
[docs]def DPxSetTouchpixxBuffWriteAddr(buffWriteAddr):
"""Sets RAM address from which next Touchpixx datum will be written.
The address must be an even value.
Args:
buffWriteAddr (int): Write address.
:Low-level C definition:
``void DPxSetTouchpixxBuffWriteAddr(unsigned buffWriteAddr)``
See Also:
:class:`DPxGetTouchpixxBuffWriteAddr`
"""
return _DPxSetTouchpixxBuffWriteAddrCall(buffWriteAddr)
#unsigned DPxGetTouchpixxBuffWriteAddr()
_DPxGetTouchpixxBuffWriteAddrCall = DPxDll['DPxGetTouchpixxBuffWriteAddr']
_DPxGetTouchpixxBuffWriteAddrCall.restype = ctypes.c_uint
[docs]def DPxGetTouchpixxBuffWriteAddr():
"""Gets RAM address from which the next TOUCHPixx datum will be written.
Returns:
int: Write address.
:Low-level C definition:
``unsigned DPxGetTouchpixxBuffWriteAddr()``
See Also:
:class:`DPxSetTouchpixxBuffWriteAddr`
"""
return _DPxGetTouchpixxBuffWriteAddrCall()
#void DPxSetTouchpixxBuffSize(unsigned buffSize)
_DPxSetTouchpixxBuffSizeCall = DPxDll['DPxSetTouchpixxBuffSize']
_DPxSetTouchpixxBuffSizeCall.argtypes = [ctypes.c_uint]
_DPxSetTouchpixxBuffSizeCall.restype = None
[docs]def DPxSetTouchpixxBuffSize(buffSize):
"""Sets Touchpixx RAM buffer size in bytes.
The size must be an even value. Buffer wraps to Base when it reaches the size.
Args:
buffSize (int): Buffer size.
:Low-level C definition:
``void DPxSetTouchpixxBuffSize(unsigned buffSize)``
See Also:
:class:`DPxGetTouchpixxBuffSize`
"""
return _DPxSetTouchpixxBuffSizeCall(buffSize)
#unsigned DPxGetTouchpixxBuffSize()
_DPxGetTouchpixxBuffSizeCall = DPxDll['DPxGetTouchpixxBuffSize']
_DPxGetTouchpixxBuffSizeCall.restype = ctypes.c_uint
[docs]def DPxGetTouchpixxBuffSize():
"""Gets the Touchpixx RAM buffer size in bytes.
Returns:
int: buffer size.
:Low-level C definition:
``unsigned DPxGetTouchpixxBuffSize()``
See Also:
:class:`DPxSetTouchpixxBuffSize`
"""
return _DPxGetTouchpixxBuffSizeCall()
#void DPxSetTouchpixxBuff(unsigned buffAddr, unsigned buffSize)
_DPxSetTouchpixxBuffCall = DPxDll['DPxSetTouchpixxBuff']
_DPxSetTouchpixxBuffCall.argtypes = [ctypes.c_uint, ctypes.c_uint]
_DPxSetTouchpixxBuffCall.restype = None
[docs]def DPxSetTouchpixxBuff(buffAddr, buffSize):
"""Sets base address, write address and buffer size for Touchpixx schedules.
This function is a shortcut which assigns Size/BaseAddr/WriteAddr
Args:
buffAddr (int): Base address.
buffSize (int): Buffer size.
:Low-level C definition:
``void DPxSetTouchpixxBuff(unsigned buffAddr, unsigned buffSize)``
See Also:
:class:`DPxSetTouchpixxBuffSize`, :class:`DPxSetTouchpixxBuffWriteAddr`
"""
return _DPxSetTouchpixxBuffCall(buffAddr, buffSize)
#void DPxEnableTouchpixxLogEvents()
_DPxEnableTouchpixxLogEventsCall = DPxDll['DPxEnableTouchpixxLogEvents']
_DPxEnableTouchpixxLogEventsCall.restype = None
[docs]def DPxEnableTouchpixxLogEvents():
"""Enables log events mode.
Each Touchpixx transition is automatically logged. No schedule is required, so this is the best way to log response buttons.
:Low-level C definition:
``void DPxEnableTouchpixxLogEvents()``
See Also:
:class:`DPxDisableTouchpixxLogEvents`, :class:`DPxIsTouchpixxLogEvents`
"""
_DPxEnableTouchpixxLogEventsCall()
#void DPxDisableTouchpixxLogEvents()
_DPxDisableTouchpixxLogEventsCall = DPxDll['DPxDisableTouchpixxLogEvents']
_DPxDisableTouchpixxLogEventsCall.restype = None
[docs]def DPxDisableTouchpixxLogEvents():
"""Disables log events mode.
Disables automatic logging of Touchpixx transitions. A schedule is needed to log transitions.
:Low-level C definition:
``void DPxDisableTouchpixxLogEvents()``
See Also:
:class:`DPxDisableTouchpixxLogEvents`, :class:`DPxIsTouchpixxLogEvents`
"""
_DPxDisableTouchpixxLogEventsCall()
#int DPxIsTouchpixxLogEvents()
_DPxIsTouchpixxLogEventsCall = DPxDll['DPxIsTouchpixxLogEvents']
_DPxIsTouchpixxLogEventsCall.restype = ctypes.c_int
[docs]def DPxIsTouchpixxLogEvents():
"""Verifies if the Touchpixx timetag mode is enabled.
Returns:
int: Non-zero if Touchpixx transitions are being logged to RAM buffer.
:Low-level C definition:
``int DPxIsTouchpixxLogEvents()``
See Also:
:class:`DPxDisableTouchpixxLogEvents`, :class:`DPxEnableTouchpixxLogEvents`
"""
return _DPxIsTouchpixxLogEventsCall()
#void DPxEnableTouchpixxLogTimetags()
_DPxEnableTouchpixxLogTimetagsCall = DPxDll['DPxEnableTouchpixxLogTimetags']
_DPxEnableTouchpixxLogTimetagsCall.restype = None
#void DPxDisableTouchpixxLogTimetags()
_DPxDisableTouchpixxLogTimetagsCall = DPxDll['DPxDisableTouchpixxLogTimetags']
_DPxDisableTouchpixxLogTimetagsCall.restype = None
#int DPxIsTouchpixxLogTimetags()
_DPxIsTouchpixxLogTimetagsCall = DPxDll['DPxIsTouchpixxLogTimetags']
_DPxIsTouchpixxLogTimetagsCall.restype = ctypes.c_int
#void DPxEnableTouchpixxLogContinuousMode()
_DPxEnableTouchpixxLogContinuousModeCall = DPxDll['DPxEnableTouchpixxLogContinuousMode']
_DPxEnableTouchpixxLogContinuousModeCall.restype = None
[docs]def DPxEnableTouchpixxLogContinuousMode():
"""Enables Touchpixx continuous logging mode.
TOUCHPixx logging returns continuous position updates during a panel press.
:Low-level C definition:
``void DPxEnableTouchpixxLogContinuousMode()``
See Also:
:class:`DPxDisableTouchpixxLogContinuousMode`, :class:`DPxIsTouchpixxLogContinuousMode`
"""
_DPxEnableTouchpixxLogContinuousModeCall()
#void DPxDisableTouchpixxLogContinuousMode()
_DPxDisableTouchpixxLogContinuousModeCall = DPxDll['DPxDisableTouchpixxLogContinuousMode']
_DPxDisableTouchpixxLogContinuousModeCall.restype = None
[docs]def DPxDisableTouchpixxLogContinuousMode():
"""Disables Touchpixx continuous logging mode.
TOUCHPixx logging only returns initial press and release events.
:Low-level C definition:
``void DPxDisableTouchpixxLogContinuousMode()``
See Also:
:class:`DPxDisableTouchpixxLogContinuousMode`, :class:`DPxIsTouchpixxLogContinuousMode`
"""
_DPxDisableTouchpixxLogContinuousModeCall()
#void DPxIsTouchpixxLogContinuousMode()
_DPxIsTouchpixxLogContinuousModeCall = DPxDll['DPxIsTouchpixxLogContinuousMode']
_DPxIsTouchpixxLogContinuousModeCall.restype = ctypes.c_int
[docs]def DPxIsTouchpixxLogContinuousMode():
"""Verifies if the TOUCHPixx continuous logging mode is enabled.
Returns:
int: Non-zero if the TOUCHPixx is in continuous logging mode, zero otherwise.
:Low-level C definition:
``void DPxIsTouchpixxLogContinuousMode()``
See Also:
:class:`DPxDisableTouchpixxLogContinuousMode`, :class:`DPxEnableTouchpixxLogContinuousMode`
"""
return _DPxIsTouchpixxLogContinuousModeCall()
#`void DPxSetTouchpixxStabilizeDuration(double duration)
_DPxSetTouchpixxStabilizeDurationCall = DPxDll['DPxSetTouchpixxStabilizeDuration']
_DPxSetTouchpixxStabilizeDurationCall.argtypes = [ctypes.c_double]
_DPxSetTouchpixxStabilizeDurationCall.restype = None
[docs]def DPxSetTouchpixxStabilizeDuration(duration):
"""Sets the Touchpixx stabilization duration.
This function sets duration in seconds that TOUCHPixx panel coordinates must be stable before being recognized as a touch in :class:`DPxGetTouchpixxCoords`
Args:
duration (double): Duration in seconds.
:Low-level C definition:
``void DPxSetTouchpixxStabilizeDuration(double duration)``
See Also:
:class:`DPxGetTouchpixxStabilizeDuration`
"""
return _DPxSetTouchpixxStabilizeDurationCall(duration)
#unsigned DPxGetTouchpixxStabilizeDuration()
_DPxGetTouchpixxStabilizeDurationCall = DPxDll['DPxGetTouchpixxStabilizeDuration']
_DPxGetTouchpixxStabilizeDurationCall.restype = ctypes.c_double
[docs]def DPxGetTouchpixxStabilizeDuration():
"""Gets the Touchpixx stabilization duration.
Gets the duration in seconds that TOUCHPixx panel coordinates must be stable before being recognized as a touch in :class:`DPxGetTouchpixxCoords`
Returns:
float: duration in seconds.
:Low-level C definition:
``unsigned DPxGetTouchpixxStabilizeDuration()``
See Also:
:class:`DPxSetTouchpixxStabilizeDuration`
"""
return _DPxGetTouchpixxStabilizeDurationCall()
#int DPxIsTouchpixxPressed()
_DPxIsTouchpixxPressedCall = DPxDll['DPxIsTouchpixxPressed']
_DPxIsTouchpixxPressedCall.restype = ctypes.c_int
[docs]def DPxIsTouchpixxPressed():
"""Returns Non-zero if touch panel is currently pressed
:Low-level C definition:
``int DPxIsTouchpixxPressed()``
"""
return _DPxIsTouchpixxPressedCall()
# void DPxGetTouchpixxCoords(int* x, int* y)
# Get the current touch panel X/Y coordinates. Returns (0,0) if panel not pressed.
_DPxGetTouchpixxCoordsCall = DPxDll['DPxGetTouchpixxCoords']
[docs]def DPxGetTouchpixxCoords():
"""Gets the current touch panel ``(X,Y)`` coordinates. Returns ``(0,0)`` if panel not pressed.
Returns:
A tuple that contains the current pressed ``(X,Y)`` coordinate. ``(0,0)`` is returned when nothing is pressed. If there are multiple presses, it returns an average.
:Low-level C definition:
``void DPxGetTouchpixxCoords(int* x, int* y)``
"""
X = 0
Y = 0
p_X = ctypes.c_int(X)
p_Y = ctypes.c_int(Y)
_DPxGetTouchpixxCoordsCall(ctypes.byref(p_X), ctypes.byref(p_Y))
return (p_X.value, p_Y.value)
# void DPxInitAudCodec()
# Call this once before other Aud/Mic routines to configure initial audio CODEC state
_DPxInitAudCodecCall = DPxDll['DPxInitAudCodec']
_DPxInitAudCodecCall.restype = None
[docs]def DPxInitAudCodec():
"""Initialize the required subsystems to play audio.
You are required to call this once before other audio or microphone routines
to configure initial audio CODEC state.
:Low-level C definition:
``void DPxInitAudCodec()``
"""
return _DPxInitAudCodecCall()
# void DPxSetAudLeftValue(int value)
# Set the 16-bit 2's complement signed value for the Left audio output channel
_DPxSetAudLeftValueCall = DPxDll['DPxSetAudLeftValue']
_DPxSetAudLeftValueCall.argtypes = [ctypes.c_int]
_DPxSetAudLeftValueCall.restype = None
[docs]def DPxSetAudLeftValue(volume):
"""Set the 16-bit 2's complement signed value for the Left audio output channel
Args:
volume (float): Value for the desired volume, between 0 and 1.
:Low-level C definition:
``void DPxSetAudLeftValue(int value)``
"""
return _DPxSetAudLeftValueCall(volume)
# void DPxSetAudRightValue(int value)
# Set the 16-bit 2's complement signed value for the Right audio output channel
_DPxSetAudRightValueCall = DPxDll['DPxSetAudRightValue']
_DPxSetAudRightValueCall.argtypes = [ctypes.c_int]
_DPxSetAudRightValueCall.restype = None
[docs]def DPxSetAudRightValue(volume):
"""Set the 16-bit 2's complement signed value for the Right audio output channel
Args:
volume (float): Value for the desired volume, between 0 and 1.
:Low-level C definition:
``void DPxSetAudRightValue(int value)``
"""
return _DPxSetAudRightValueCall(volume)
# int DPxGetAudLeftValue()
# Get the 16-bit 2's complement signed value for the Left audio output channel
_DPxGetAudLeftValueCall = DPxDll['DPxGetAudLeftValue']
_DPxGetAudLeftValueCall.restype = ctypes.c_int
[docs]def DPxGetAudLeftValue():
"""Get the 16-bit 2's complement signed value for the Left audio output channel
:Low-level C definition:
``int DPxGetAudLeftValue()``
"""
return _DPxGetAudLeftValueCall()
# int DPxGetAudRightValue()
# Get the 16-bit 2's complement signed value for the Right audio output channel
_DPxGetAudRightValueCall = DPxDll['DPxGetAudRightValue']
_DPxGetAudRightValueCall.restype = ctypes.c_int
[docs]def DPxGetAudRightValue():
"""Get the 16-bit 2's complement signed value for the Right audio output channel
:Low-level C definition:
``int DPxGetAudRightValue()``
"""
return _DPxGetAudRightValueCall()
# void DPxSetAudLeftVolume(double volume)
# Set volume for the Left audio output channel, range 0-1
_DPxSetAudLeftVolumeCall = DPxDll['DPxSetAudLeftVolume']
_DPxSetAudLeftVolumeCall.argtypes = [ctypes.c_double]
_DPxSetAudLeftVolumeCall.restype = None
[docs]def DPxSetAudLeftVolume(volume):
""" Sets volume for the Right audio channels, range 0-1
Args:
volume (float): Value for the desired volume, between 0 and 1.
:Low-level C definition:
``void DPxSetAudRightVolume(double volume)``
"""
_DPxSetAudLeftVolumeCall(volume)
# void DPxSetAudRightVolume(double volume)
# Set volume for the Right audio output channel, range 0-1
_DPxSetAudRightVolumeCall = DPxDll['DPxSetAudRightVolume']
_DPxSetAudRightVolumeCall.restype = None
_DPxSetAudRightVolumeCall.argtypes = [ctypes.c_double]
[docs]def DPxSetAudRightVolume(volume):
""" Sets volume for the Right audio channels, range 0-1
Args:
volume (float): Value for the desired volume, between 0 and 1.
:Low-level C definition:
``void DPxSetAudRightVolume(double volume)``
"""
_DPxSetAudRightVolumeCall(volume)
# void DPxSetAudVolume(double volume)
# Set volume for both Left/Right audio channels, range 0-1
_DPxSetAudVolumeCall = DPxDll['DPxSetAudVolume']
_DPxSetAudVolumeCall.argtypes = [ctypes.c_double]
_DPxSetAudVolumeCall.restype = None
[docs]def DPxSetAudVolume(volume):
""" Sets the volume for both Left/Right audio channels, range 0-1
Args:
volume (float): Value for the desired volume, between 0 and 1.
:Low-level C definition:
``void DPxSetAudVolume(double volume)``
"""
_DPxSetAudVolumeCall(volume)
# double DPxGetAudLeftVolume()
# Get volume for the Left audio output channel, range 0-1
_DPxGetAudLeftVolumeCall = DPxDll['DPxGetAudLeftVolume']
_DPxGetAudLeftVolumeCall.restype = ctypes.c_double
[docs]def DPxGetAudLeftVolume():
""" Get volume for the Left audio output channel, range 0-1
Returns:
double: volume
:Low-level C definition:
``double DPxGetAudLeftVolume()``
"""
return _DPxGetAudLeftVolumeCall()
# double DPxGetAudRightVolume()
# Get volume for the Right audio output channel, range 0-1
_DPxGetAudRightVolumeCall = DPxDll['DPxGetAudRightVolume']
_DPxGetAudRightVolumeCall.restype = ctypes.c_double
[docs]def DPxGetAudRightVolume():
"""Get volume for the Right audio output channel, range 0-1
Returns:
double: volume
:Low-level C definition:
``double DPxGetAudRightVolume()``
"""
return _DPxGetAudRightVolumeCall()
# double DPxGetAudVolume()
# Get volume for both Left/Right audio channels
# The floating point volume parameter is in the range 0-1.
# The actual Left/Right volume controls are implemented as 16-bit unsigned FPGA registers.
# The audio samples read from the RAM buffer are multiplied by the volume registers
# (then right-shifted 16 bits) before forwarding the samples to the CODEC.
# Volume value 1.0 is a special case which bypasses this multiplication.
# NOTE: For safety's sake, reset value of L/R volumes = 0, so must set volume before playback.
#GetAudVolume = DPxDll['DPxGetAudVolume']
[docs]def DPxGetAudVolume():
""" Gets the volume for both Left/Right audio channels
Returns:
A tuple containing floats: [left Speaker Volume, Right speaker Volume]
:Low-level C definition:
``double DPxGetAudVolume()``
"""
return (DPxGetAudLeftVolume(), DPxGetAudRightVolume())
# The audio output API has two groups of volume control functions.
# See the above paragraph for a description of the first group of volume control functions.
# This second group uses CODEC internal registers to independently attenuate L/R audio outputs to the DATAPixx speaker and Audio OUT ports.
# These CODEC volume registers have a precision (step size) of about 0.5 dB (see TI TLV320AIC32 datasheet for details).
# These routines can use either ratio units (0 to 1), or the corresponding dB values (-inf to 0).
# To minimize hiss, it is a good idea to do ball-park attenuation using these CODEC registers.
# Then, for ultra-precise stimulus volume manipulation, use the above SetAudVolume() functions.
# Those functions very precisely attenuate the digital audio data _before_ sending to the CODEC.
#
# void DPxSetAudCodecOutLeftVolume(double volume, # int DBUnits)
# Set volume for the DATAPixx Audio OUT Left channel, range 0-1 (or dB)
# dBUnits is one of the following value:
# 0 : Set dBUnits in linear scale
# 1 : Set dBUnits in dB scale
_DPxSetAudCodecOutLeftVolumeCall = DPxDll['DPxSetAudCodecOutLeftVolume']
_DPxSetAudCodecOutLeftVolumeCall.argtypes = [ctypes.c_double, ctypes.c_int]
_DPxSetAudCodecOutLeftVolumeCall.restype = None
[docs]def DPxSetAudCodecOutLeftVolume(volume, dBUnits=0):
"""Sets the volume for the DATAPixx Audio OUT Right channel
Args:
volume (float): The value for the desired volume, between 0 and 1 or in dB.
dBUnits (int, optional): Set non-zero to return the gain in dB. Defaults to 0
:Low-level C definition:
``void DPxSetAudCodecOutLeftVolume(double volume, int DBUnits)``
"""
return _DPxSetAudCodecOutLeftVolumeCall(volume, dBUnits)
# double DPxGetAudCodecOutLeftVolume( int DBUnits)
# Gets volume for the DATAPixx Audio OUT Left channel, range 0-1 (or dB)
_DPxGetAudCodecOutLeftVolumeCall = DPxDll['DPxGetAudCodecOutLeftVolume']
_DPxGetAudCodecOutLeftVolumeCall.restype = ctypes.c_double
_DPxGetAudCodecOutLeftVolumeCall.argtypes = [ctypes.c_int]
[docs]def DPxGetAudCodecOutLeftVolume(dBUnits=0):
"""Gets the volume for the DATAPixx Audio OUT Left channel
Args:
dBUnits (int, optional): Set non-zero to return the gain in dB. Defaults to 0
Returns:
double: volume
:Low-level C definition:
``double DPxGetAudCodecOutLeftVolume(int DBUnits)``
"""
return _DPxGetAudCodecOutLeftVolumeCall(dBUnits)
# void DPxSetAudCodecOutRightVolume(double volume, int DBUnits)
# Set volume for the DATAPixx Audio OUT Right channel, range 0-1 (or dB)
_DPxSetAudCodecOutRightVolumeCall = DPxDll['DPxSetAudCodecOutRightVolume']
_DPxSetAudCodecOutRightVolumeCall.argtypes = [ctypes.c_double, ctypes.c_int]
_DPxSetAudCodecOutRightVolumeCall.restype = None
[docs]def DPxSetAudCodecOutRightVolume(volume, dBUnits=0):
"""Sets the volume for the DATAPixx Audio OUT Right channel
Args:
volume (float): The value for the desired volume, between 0 and 1 or in dB.
dBUnits (int, optional): Set non-zero to return the gain in dB. Defaults to 0
:Low-level C definition:
``void DPxSetAudCodecOutRightVolume(double volume, int DBUnits)``
"""
return _DPxSetAudCodecOutRightVolumeCall(volume, dBUnits)
# double DPxGetAudCodecOutRightVolume(int DBUnits)
# Get volume for the DATAPixx Audio OUT Right channel, range 0-1 (or dB)
_DPxGetAudCodecOutRightVolumeCall = DPxDll['DPxGetAudCodecOutRightVolume']
_DPxGetAudCodecOutRightVolumeCall.restype = ctypes.c_double
_DPxGetAudCodecOutRightVolumeCall.argtypes = [ctypes.c_int]
[docs]def DPxGetAudCodecOutRightVolume(dBUnits=0):
"""Gets the volume for the DATAPixx Audio OUT Right channel
Args:
dBUnits (int, optional): Set non-zero to return the gain in dB. Defaults to 0
Returns:
double: volume
:Low-level C definition:
``double DPxGetAudCodecOutRightVolume(int DBUnits)``
"""
return _DPxGetAudCodecOutRightVolumeCall(dBUnits)
# void DPxSetAudCodecOutVolume(double volume, int DBUnits)
# Set volume for the DATAPixx Audio OUT Left and Right channels, range 0-1 (or dB)
# dBUnits is one of the following value:
# 0 : Set dBUnits in linear scale
# 1 : Set dBUnits in dB scale
_DPxSetAudCodecOutVolumeCall = DPxDll['DPxSetAudCodecOutVolume']
_DPxSetAudCodecOutVolumeCall.argtypes = [ctypes.c_double, ctypes.c_int]
_DPxSetAudCodecOutVolumeCall.restype = None
[docs]def DPxSetAudCodecOutVolume(volume, dBUnits=0):
"""Sets the volume for the DATAPixx Audio OUT Left and Right channels
Args:
volume (float): The value for the desired volume, between 0 and 1 or in dB.
dBUnits (int, optional): Set non-zero to return the gain in dB. Defaults to 0
:Low-level C definition:
``void DPxSetAudCodecOutVolume(double volume, int DBUnits)``
"""
return _DPxSetAudCodecOutVolumeCall(volume, dBUnits)
# double DPxGetAudCodecOutVolume(int DBUnits)
# Get volume for the DATAPixx Audio OUT Left and Right channels
[docs]def DPxGetAudCodecOutVolume(dBUnits=0):
""" Gets the volume for the DATAPixx Audio OUT Left and Right channels
Args:
dBUnits (int, optional): Set non-zero to return the gain in dB. Defaults to 0
Returns:
A tuple containing floats: [left Speaker Volume, Right speaker Volume]
:Low-level C definition:
``double DPxGetAudCodecOutVolume(int DBUnits)``
"""
return (DPxGetAudCodecOutLeftVolume(dBUnits), DPxGetAudCodecOutRightVolume(dBUnits))
# void DPxSetAudCodecSpeakerLeftVolume(double volume, int DBUnits)
# Set volume for the DATAPixx Speaker Left channel, range 0-1 (or dB)
_DPxSetAudCodecSpeakerLeftVolumeCall = DPxDll['DPxSetAudCodecSpeakerLeftVolume']
_DPxSetAudCodecSpeakerLeftVolumeCall.argtypes = [ctypes.c_double, ctypes.c_int]
_DPxSetAudCodecSpeakerLeftVolumeCall.restype = None
[docs]def DPxSetAudCodecSpeakerLeftVolume(volume, dBUnits=0):
"""Sets volume for the DATAPixx Speaker LEft channels
Args:
volume (float): The value for the desired volume, between 0 and 1 or in dB.
dBUnits (int, optional): Set non-zero to set the gain in dB. Defaults to 0.
:Low-level C definition:
``void DPxSetAudCodecSpeakerLeftVolume(double volume, int DBUnits)``
"""
return _DPxSetAudCodecSpeakerLeftVolumeCall(volume, dBUnits)
# double DPxGetAudCodecSpeakerLeftVolume(int DBUnits)
# Get volume for the DATAPixx Speaker Left channel, range 0-1 (or dB)
_DPxGetAudCodecSpeakerLeftVolumeCall = DPxDll['DPxGetAudCodecSpeakerLeftVolume']
_DPxGetAudCodecSpeakerLeftVolumeCall.restype = ctypes.c_double
_DPxGetAudCodecSpeakerLeftVolumeCall.argtypes = [ctypes.c_int]
[docs]def DPxGetAudCodecSpeakerLeftVolume(dBUnits=0):
"""Gets the volume for the DATAPixx Speaker Left channel
Args:
dBUnits (int, optional): Set non-zero to return the gain in dB. Defaults to 0
Returns:
double: volume
:Low-level C definition:
``double DPxGetAudCodecSpeakerLeftVolume(int DBUnits)``
"""
return _DPxGetAudCodecSpeakerLeftVolumeCall(dBUnits)
# void DPxSetAudCodecSpeakerRightVolume(double volume, int DBUnits)
# Set volume for the DATAPixx Speaker Right channel, range 0-1 (or dB)
# dBUnits is one of the following value:
# 0 : Set dBUnits in linear scale
# 1 : Set dBUnits in dB scale
_DPxSetAudCodecSpeakerRightVolumeCall = DPxDll['DPxSetAudCodecSpeakerRightVolume']
_DPxSetAudCodecSpeakerRightVolumeCall.argtypes = [ctypes.c_double, ctypes.c_int]
_DPxSetAudCodecSpeakerRightVolumeCall.restype = None
[docs]def DPxSetAudCodecSpeakerRightVolume(volume, dBUnits=0):
"""Sets volume for the DATAPixx Speaker Right channels
Args:
volume (float): The value for the desired volume, between 0 and 1 or in dB.
dBUnits (int, optional): Set non-zero to set the gain in dB. Defaults to 0
:Low-level C definition:
``void DPxSetAudCodecSpeakerRightVolume(double volume, int DBUnits)``
"""
return _DPxSetAudCodecSpeakerRightVolumeCall(volume, dBUnits)
# double DPxGetAudCodecSpeakerRightVolume( int DBUnits)
# Get volume for the DATAPixx Speaker Right channel, range 0-1 (or dB)
_DPxGetAudCodecSpeakerRightVolumeCall = DPxDll['DPxGetAudCodecSpeakerRightVolume']
_DPxGetAudCodecSpeakerRightVolumeCall.restype = ctypes.c_double
_DPxGetAudCodecSpeakerRightVolumeCall.argtypes = [ctypes.c_int]
[docs]def DPxGetAudCodecSpeakerRightVolume(dBUnits=0):
"""Gets the volume for the DATAPixx Speaker Right channel
Args:
dBUnits (int, optional): Set non-zero to return the gain in dB. Defaults to 0.
Returns:
double: Volume
:Low-level C definition:
``double DPxGetAudCodecSpeakerRightVolume(int DBUnits)``
"""
return _DPxGetAudCodecSpeakerRightVolumeCall(dBUnits)
# void DPxSetAudCodecSpeakerVolume(double volume, int DBUnits)
# Set volume for the DATAPixx Speaker Left and Right channels, range 0-1 (or dB)
# dBUnits is one of the following value:
# 0 : Set dBUnits in linear scale
# 1 : Set dBUnits in dB scale
_DPxSetAudCodecSpeakerVolumeCall = DPxDll['DPxSetAudCodecSpeakerVolume']
_DPxSetAudCodecSpeakerVolumeCall.argtypes = [ctypes.c_double, ctypes.c_int]
_DPxSetAudCodecSpeakerVolumeCall.restype = None
[docs]def DPxSetAudCodecSpeakerVolume(volume, dBUnits=0):
"""Sets volume for the DATAPixx Speaker Left and Right channels
Args:
volume (float): The value for the desired volume, between 0 and 1 or in dB.
dBUnits (int, optional): Set non-zero to return the gain in dB. Defaults to 0.
:Low-level C definition:
``void DPxSetAudCodecSpeakerVolume(double volume, int DBUnits)``
"""
return _DPxSetAudCodecSpeakerVolumeCall(volume, dBUnits)
# double DPxGetAudCodecSpeakerVolume(int DBUnits)
# Get volume for the DATAPixx Speaker Left and Right channels
[docs]def DPxGetAudCodecSpeakerVolume(dBUnits=0):
""" Gets volume for the DATAPixx Speaker Left and Right channels
Args:
dBUnits (int, optional): Set non-zero to return the gain in dB. Defaults to 0.
Returns:
A tuple containing floats: [left Speaker Volume, Right speaker Volume]
:Low-level C definition:
``double DPxGetAudCodecSpeakerVolume(int DBUnits)``
"""
return (DPxGetAudCodecSpeakerLeftVolume(dBUnits),DPxGetAudCodecSpeakerRightVolume(dBUnits))
#void DPxSetAudLRMode(int lrMode)
_DPxSetAudLRModeCall = DPxDll['DPxSetAudLRMode']
_DPxSetAudLRModeCall.argtypes = [ctypes.c_int]
_DPxSetAudLRModeCall.restype = None
[docs]def DPxSetAudLRMode(mode):
"""Sets how audio data are updated by schedules.
Args:
mode (str): Any of the following predefined constants.
* **mono**: Each AUD schedule datum goes to left and right channels
* **left**: Each AUD schedule datum goes to left channel only
* **right**: Each AUD schedule datum goes to right channel only
* **stereo1**: Pairs of AUD data are copied to left/right channels
* **stereo2**: AUD data goes to left channel, AUX data goes to right
:Low-level C definition:
``void DPxSetAudLRMode(int lrMode)``
"""
_DPxSetAudLRModeCall(api_constants[mode.upper()])
#int DPxGetAudLRMode()
_DPxGetAudLRModeCall = DPxDll['DPxGetAudLRMode']
_DPxGetAudLRModeCall.restype = ctypes.c_int
[docs]def DPxGetAudLRMode():
"""Gets the audio schedule update mode.
Returns:
String: Any of the following predefined constants.
* **mono**: Each AUD schedule datum goes to left and right channels
* **left**: Each AUD schedule datum goes to left channel only
* **right**: Each AUD schedule datum goes to right channel only
* **stereo1**: Pairs of AUD data are copied to left/right channels
* **stereo2**: AUD data goes to left channel, AUX data goes to right
:Low-level C definition:
``int DPxGetAudLRMode()``
"""
return audio_mode_constants[ _DPxGetAudLRModeCall() ]
# void DPxSetAudBuffBaseAddr(unsigned buffBaseAddr)
# Set AUD RAM buffer start address. Must be an even value.
_DPxSetAudBuffBaseAddrCall = DPxDll['DPxSetAudBuffBaseAddr']
_DPxSetAudBuffBaseAddrCall.argtypes = [ctypes.c_uint]
_DPxSetAudBuffBaseAddrCall.restype = None
[docs]def DPxSetAudBuffBaseAddr(buffBaseAddr):
"""Sets the AUD RAM buffer start address.
The address must be an even value.
Args:
buffBaseAddr (int): Base address.
:Low-level C definition:
``void DPxSetAudBuffBaseAddr(unsigned buffBaseAddr)``
"""
return _DPxSetAudBuffBaseAddrCall(buffBaseAddr)
# unsigned DPxGetAudBuffBaseAddr()
# Get AUD RAM buffer start address
_DPxGetAudBuffBaseAddrCall = DPxDll['DPxGetAudBuffBaseAddr']
_DPxGetAudBuffBaseAddrCall.restype = ctypes.c_uint
[docs]def DPxGetAudBuffBaseAddr():
"""Gets the AUD RAM buffer start address.
Returns:
int: Base address
:Low-level C definition:
``unsigned DPxGetAudBuffBaseAddr()``
"""
return _DPxGetAudBuffBaseAddrCall()
# void DPxSetAudBuffReadAddr(unsigned buffReadAddr)
# Set RAM address from which next AUD datum will be read. Must be an even value.
_DPxSetAudBuffReadAddrCall = DPxDll['DPxSetAudBuffReadAddr']
_DPxSetAudBuffReadAddrCall.argtypes = [ctypes.c_uint]
_DPxSetAudBuffReadAddrCall.restype = None
[docs]def DPxSetAudBuffReadAddr(buffReadAddr):
"""Sets RAM address from which next AUD datum will be read.
The address must be an even value.
Args:
buffReadAddr (int): Read address.
:Low-level C definition:
``void DPxSetAudBuffReadAddr(unsigned buffReadAddr)``
"""
return _DPxSetAudBuffReadAddrCall(buffReadAddr)
# unsigned DPxGetAudBuffReadAddr()
# Get RAM address from which next AUD datum will be read
_DPxGetAudBuffReadAddrCall = DPxDll['DPxGetAudBuffReadAddr']
_DPxGetAudBuffReadAddrCall.restype = ctypes.c_uint
[docs]def DPxGetAudBuffReadAddr():
"""Gets AUD address from which next AUD datum will be read.
Returns:
int: Read address.
:Low-level C definition:
``unsigned DPxGetAudBuffReadAddr()``
"""
return _DPxGetAudBuffReadAddrCall()
# void DPxSetAudBuffSize(unsigned buffSize)
# Set AUD RAM buffer size in bytes. Must be an even value. Buffer wraps to Base after Size.
_DPxSetAudBuffSizeCall = DPxDll['DPxSetAudBuffSize']
_DPxSetAudBuffSizeCall.argtypes = [ctypes.c_uint]
_DPxSetAudBuffSizeCall.restype = None
[docs]def DPxSetAudBuffSize(buffSize):
"""Sets AUD RAM buffer size in bytes.
The size must be an even value. Buffer wraps to Base once it reaches the size.
Args:
buffSize (int): Buffer size.
:Low-level C definition:
``void DPxSetAudBuffSize(unsigned buffSize)``
"""
return _DPxSetAudBuffSizeCall(buffSize)
# unsigned DPxGetAudBuffSize()
# Get AUD RAM buffer size in bytes
_DPxGetAudBuffSizeCall = DPxDll['DPxGetAudBuffSize']
_DPxGetAudBuffSizeCall.restype = ctypes.c_uint
[docs]def DPxGetAudBuffSize():
"""Gets the AUD RAM buffer size in bytes.
Returns:
int: buffer size.
:Low-level C definition:
``unsigned DPxGetAudBuffSize()``
"""
return _DPxGetAudBuffSizeCall()
# void DPxSetAudBuff(unsigned buffAddr, unsigned buffSize)
# Shortcut which assigns Size/BaseAddr/ReadAddr
_DPxSetAudBuffCall = DPxDll['DPxSetAudBuff']
_DPxSetAudBuffCall.argtypes = [ctypes.c_uint, ctypes.c_uint]
_DPxSetAudBuffCall.restype = None
[docs]def DPxSetAudBuff(buffAddr, buffSize):
"""Sets base address, reads address and buffer size for AUD schedules.
This function is a shortcut which assigns Size/BaseAddr/ReadAddr
Args:
buffAddr (int): Base address.
buffSize (int): Buffer size.
:Low-level C definition:
``void DPxSetAudBuff(unsigned buffAddr, unsigned buffSize)``
"""
return _DPxSetAudBuffCall(buffAddr, buffSize)
# void DPxSetAuxBuffBaseAddr(unsigned buffBaseAddr)
# Set AUX RAM buffer start address. Must be an even value.
_DPxSetAuxBuffBaseAddrCall = DPxDll['DPxSetAuxBuffBaseAddr']
_DPxSetAuxBuffBaseAddrCall.argtypes = [ctypes.c_uint]
_DPxSetAuxBuffBaseAddrCall.restype = None
[docs]def DPxSetAuxBuffBaseAddr(buffBaseAddr):
"""Sets the AUX RAM buffer start address.
The address must be an even value.
Args:
buffBaseAddr (int): Base address.
:Low-level C definition:
``void DPxSetAuxBuffBaseAddr(unsigned buffBaseAddr)``
"""
return _DPxSetAuxBuffBaseAddrCall(buffBaseAddr)
# unsigned DPxGetAuxBuffBaseAddr()
# Get AUX RAM buffer start address
_DPxGetAuxBuffBaseAddrCall = DPxDll['DPxGetAuxBuffBaseAddr']
_DPxGetAuxBuffBaseAddrCall.restype = ctypes.c_uint
[docs]def DPxGetAuxBuffBaseAddr():
"""Gets the AUX RAM buffer start address.
Returns:
int: Base address.
:Low-level C definition:
``unsigned DPxGetAuxBuffBaseAddr()``
"""
return _DPxGetAuxBuffBaseAddrCall()
# void DPxSetAuxBuffReadAddr(unsigned buffReadAddr)
# Set RAM address from which next AUX datum will be read. Must be an even value.
_DPxSetAuxBuffReadAddrCall = DPxDll['DPxSetAuxBuffReadAddr']
_DPxSetAuxBuffReadAddrCall.argtypes = [ctypes.c_uint]
_DPxSetAuxBuffReadAddrCall.restype = None
[docs]def DPxSetAuxBuffReadAddr(buffReadAddr):
"""Sets RAM address from which next AUX datum will be read.
The address must be an even value.
Args:
buffReadAddr (int): Read address.
:Low-level C definition:
``void DPxSetAuxBuffReadAddr(unsigned buffReadAddr)``
"""
return _DPxSetAuxBuffReadAddrCall(buffReadAddr)
# unsigned DPxGetAuxBuffReadAddr()
# Get RAM address from which next AUX datum will be read
_DPxGetAuxBuffReadAddrCall = DPxDll['DPxGetAuxBuffReadAddr']
_DPxGetAuxBuffReadAddrCall.restype = ctypes.c_uint
[docs]def DPxGetAuxBuffReadAddr():
"""Gets RAM address from which next AUX datum will be read.
Returns:
int: Read address.
:Low-level C definition:
``unsigned DPxGetAuxBuffReadAddr()``
"""
return _DPxGetAuxBuffReadAddrCall()
# void DPxSetAuxBuffSize(unsigned buffSize)
# Set AUX RAM buffer size in bytes. Must be an even value. Buffer wraps to Base after Size.
_DPxSetAuxBuffSizeCall = DPxDll['DPxSetAuxBuffSize']
_DPxSetAuxBuffSizeCall.argtypes = [ctypes.c_uint]
_DPxSetAuxBuffSizeCall.restype = None
[docs]def DPxSetAuxBuffSize(buffSize):
"""Sets AUX RAM buffer size in bytes.
The size must be an even value. Buffer wraps to Base once it reaches the size.
Args:
buffSize (int): Buffer size.
:Low-level C definition:
``void DPxSetAuxBuffSize(unsigned buffSize)``
"""
return _DPxSetAuxBuffSizeCall(buffSize)
# unsigned DPxGetAuxBuffSize()
# Get AUX RAM buffer size in bytes
_DPxGetAuxBuffSizeCall = DPxDll['DPxGetAuxBuffSize']
_DPxGetAuxBuffSizeCall.restype = ctypes.c_uint
[docs]def DPxGetAuxBuffSize():
"""Gets the AUX RAM buffer size in bytes.
Returns:
int: buffer size.
:Low-level C definition:
``unsigned DPxGetAuxBuffSize()``
"""
return _DPxGetAuxBuffSizeCall()
# void DPxSetAuxBuff(unsigned buffAddr, unsigned buffSize)
# Shortcut which assigns Size/BaseAddr/ReadAddr
_DPxSetAuxBuffCall = DPxDll['DPxSetAuxBuff']
_DPxSetAuxBuffCall.argtypes = [ctypes.c_uint, ctypes.c_uint]
_DPxSetAuxBuffCall.restype = None
[docs]def DPxSetAuxBuff(buffAddr, buffSize):
"""Sets base address, reads address and buffer size for AUX schedules.
This function is a shortcut which assigns Size/BaseAddr/ReadAddr
Args:
buffAddr (int): Base address.
buffSize (int): Buffer size.
:Low-level C definition:
``void DPxSetAuxBuff(unsigned buffAddr, unsigned buffSize)``
"""
return _DPxSetAuxBuffCall(buffAddr, buffSize)
# void DPxSetAudSchedOnset(unsigned onset)
# Set nanosecond delay between schedule start and first AUD update
_DPxSetAudSchedOnsetCall = DPxDll['DPxSetAudSchedOnset']
_DPxSetAudSchedOnsetCall.argtypes = [ctypes.c_uint]
_DPxSetAudSchedOnsetCall.restype = None
[docs]def DPxSetAudSchedOnset(onset):
"""Sets nanosecond delay between schedule start and first MIC update.
Args:
onset (int): The onset value.
:Low-level C definition:
``void DPxSetAudSchedOnset(unsigned onset)``
"""
return _DPxSetAudSchedOnsetCall(onset)
# unsigned DPxGetAudSchedOnset()
# Get nanosecond delay between schedule start and first AUD update
_DPxGetAudSchedOnsetCall = DPxDll['DPxGetAudSchedOnset']
_DPxGetAudSchedOnsetCall.restype = ctypes.c_uint
[docs]def DPxGetAudSchedOnset():
"""Gets the nanosecond delay between schedule start and first AUD update.
Returns:
int: The nanosecond onset between the first update and the start of schedule.
:Low-level C definition:
``unsigned DPxGetAudSchedOnset()``
"""
return _DPxGetAudSchedOnsetCall()
_DPxSetAudSchedRateCall = DPxDll['DPxSetAudSchedRate']
_DPxSetAudSchedRateCall.argtypes = [ctypes.c_uint, ctypes.c_int]
_DPxSetAudSchedRateCall.restype = None
[docs]def DPxSetAudSchedRate(rate, unit):
"""Sets the schedule rate.
This method allows the user to set the schedule rate. Since the rate can be given
with different units, the method also needs to have a unit associated with the rate.
If no delay is required, this method does not need to be used. Default value is 0.
Args:
rate (int): Any positive value equal to or greater than zero.
unit (str): Any of the following predefined constants.
* **hz**: rate updates per second, maximum 96 kHz.
* **video**: rate updates per video frame, maximum 96 kHz.
* **nano**: rate updates period in nanoseconds, minimum 10417 ns.
:Low-level C definition:
``void DPxSetAudSchedRate(unsigned rateValue, int rateUnits)``
"""
_DPxSetAudSchedRateCall(rate, api_constants[unit.upper()])
_DPxGetAudSchedRateCall = DPxDll['DPxGetAudSchedRate']
_DPxGetAudSchedRateCall.restype = ctypes.c_uint
[docs]def DPxGetAudSchedRate():
"""Gets the audio schedule update rate and optionally get rate units.
This method allows the user to get the audio's left schedule update rate and optionally get rate units.
The return value is a tuple containing the rate and the rate unit.
The unit can be any of the following predefined constants.
* **hz**: Updates per second, maximum 96 kHz.
* **video**: Updates per video frame, maximum 96 kHz.
* **nano**: Update period in nanoseconds, minimum 10417 ns.
Returns:
Tuple: Rate, Unit
:Low-level C definition:
``unsigned DPxGetAudSchedRate(int *rateUnits)``
"""
temp = 0
p_temp = ctypes.c_int(temp)
return (_DPxGetAudSchedRateCall(ctypes.byref(p_temp)), rate_constants[ p_temp.value ])
# void DPxSetAudSchedCount(unsigned count)
# Set AUD schedule update count
_DPxSetAudSchedCountCall = DPxDll['DPxSetAudSchedCount']
_DPxSetAudSchedCountCall.argtypes = [ctypes.c_uint]
_DPxSetAudSchedCountCall.restype = None
[docs]def DPxSetAudSchedCount(count):
"""Sets MIC schedule update count.
Args:
count (int): Schedule count.
:Low-level C definition:
``void DPxSetAudSchedCount(unsigned count)``
"""
return _DPxSetAudSchedCountCall(count)
# unsigned DPxGetAudSchedCount()
# Get AUD schedule update count
_DPxGetAudSchedCountCall = DPxDll['DPxGetAudSchedCount']
_DPxGetAudSchedCountCall.restype = ctypes.c_uint
[docs]def DPxGetAudSchedCount():
"""Gets AUD schedule update count.
Returns:
int: The current MIC schedule count.
:Low-level C definition:
``unsigned DPxGetAudSchedCount()``
"""
return _DPxGetAudSchedCountCall()
# void DPxEnableAudSchedCountdown()
# SchedCount decrements at SchedRate, and schedule stops automatically when count hits 0
_DPxEnableAudSchedCountdownCall = DPxDll['DPxEnableAudSchedCountdown']
_DPxEnableAudSchedCountdownCall.restype = None
[docs]def DPxEnableAudSchedCountdown():
"""Enables MIC schedule countdown.
SchedCount increments at SchedRate, and schedule is stopped by calling SchedStop.
:Low-level C definition:
``void DPxEnableAudSchedCountdown()``
"""
return _DPxEnableAudSchedCountdownCall()
# void DPxDisableAudSchedCountdown()
# SchedCount increments at SchedRate, and schedule is stopped by calling SchedStop
_DPxDisableAudSchedCountdownCall = DPxDll['DPxDisableAudSchedCountdown']
_DPxDisableAudSchedCountdownCall.restype = None
[docs]def DPxDisableAudSchedCountdown():
"""Disables AUD schedule countdown.
SchedCount increments at SchedRate, and schedule is stopped by calling SchedStop.
:Low-level C definition:
``void DPxDisableAudSchedCountdown()``
"""
return _DPxDisableAudSchedCountdownCall()
# int DPxIsAudSchedCountdown()
# Returns Non-zero if SchedCount decrements to 0 and automatically stops schedule
_DPxIsAudSchedCountdownCall = DPxDll['DPxIsAudSchedCountdown']
_DPxIsAudSchedCountdownCall.restype = ctypes.c_int
[docs]def DPxIsAudSchedCountdown():
"""Returns non-zero if SchedCount decrements to 0 and automatically stops schedule.
Returns:
int: non-zero if ShedCount is 0
:Low-level C definition:
``int DPxIsAudSchedCountdown()``
"""
return _DPxIsAudSchedCountdownCall()
# void DPxSetAudSched(unsigned onset, unsigned rateValue, int rateUnits, unsigned count)
# Shortcut which assigns Onset/Rate/Count. If Count > 0, enables Countdown mode.
_DPxSetAudSchedCall = DPxDll['DPxSetAudSched']
_DPxSetAudSchedCall.argtypes = [ctypes.c_uint, ctypes.c_uint, ctypes.c_int, ctypes.c_uint]
_DPxSetAudSchedCall.restype = None
[docs]def DPxSetAudSched(onset, rateValue, rateUnits, count):
"""Sets AUD schedule onset, count and rate.
This function is a shortcut which assigns Onset/Rate/Count. If ``count`` is greater than zero, the count
down mode is enabled.
Args:
onset (int): Schedule onset.
rateValue (int): Rate value.
rateUnits (str): Usually ``hz``. Can also be ``video`` to update every ``rateValue`` video frames or ``nano`` to update every ``rateValue`` nanoseconds.
count (int): Schedule count.
:Low-level C definition:
``void DPxSetAudSched(unsigned onset, unsigned rateValue, int rateUnits, unsigned count)``
"""
return _DPxSetAudSchedCall(onset, rateValue, api_constants[rateUnits.upper()], count)
# void DPxStartAudSched()
# Start running a AUD schedule
_DPxStartAudSchedCall = DPxDll['DPxStartAudSched']
_DPxStartAudSchedCall.restype = None
[docs]def DPxStartAudSched():
"""Starts running an AUD schedule
:Low-level C definition:
``void DPxStartAudSched()``
"""
return _DPxStartAudSchedCall()
# void DPxStopAudSched()
# Stop running a AUD schedule
_DPxStopAudSchedCall = DPxDll['DPxStopAudSched']
_DPxStopAudSchedCall.restype = None
[docs]def DPxStopAudSched():
"""Stops running an AUD schedule
:Low-level C definition:
``void DPxStopAudSched()``
"""
return _DPxStopAudSchedCall()
# int DPxIsAudSchedRunning()
# Returns non-0 if AUD schedule is currently running
_DPxIsAudSchedRunningCall = DPxDll['DPxIsAudSchedRunning']
_DPxIsAudSchedRunningCall.restype = ctypes.c_int
[docs]def DPxIsAudSchedRunning():
"""Returns non-zero if AUD schedule is currently running.
:Low-level C definition:
``int DPxIsAudSchedRunning()``
"""
return _DPxIsAudSchedRunningCall()
# void DPxSetAuxSchedOnset(unsigned onset)
# Set nanosecond delay between schedule start and first AUX update
_DPxSetAuxSchedOnsetCall = DPxDll['DPxSetAuxSchedOnset']
_DPxSetAuxSchedOnsetCall.argtypes = [ctypes.c_uint]
_DPxSetAuxSchedOnsetCall.restype = None
[docs]def DPxSetAuxSchedOnset(onset):
"""Sets nanosecond delay between schedule start and first AUX update.
Args:
onset (int): The nanosecond onset between the first update and the start of schedule.
:Low-level C definition:
``void DPxSetAuxSchedOnset(unsigned onset)``
"""
return _DPxSetAuxSchedOnsetCall(onset)
# unsigned DPxGetAuxSchedOnset()
# Get nanosecond delay between schedule start and first AUX update
_DPxGetAuxSchedOnsetCall = DPxDll['DPxGetAuxSchedOnset']
_DPxGetAuxSchedOnsetCall.restype = ctypes.c_uint
[docs]def DPxGetAuxSchedOnset():
"""Gets the nanosecond delay between schedule start and the first AUX update.
Returns:
int: The nanosecond onset between the first update and the start of the schedule.
:Low-level C definition:
``unsigned DPxGetAuxSchedOnset()``
"""
return _DPxGetAuxSchedOnsetCall()
_DPxSetAuxSchedRateCall = DPxDll['DPxSetAuxSchedRate']
_DPxSetAuxSchedRateCall.argtypes = [ctypes.c_uint, ctypes.c_int]
_DPxSetAuxSchedRateCall.restype = None
[docs]def DPxSetAuxSchedRate(rate, unit):
"""Sets the schedule rate.
This method allows the user to set the schedule rate. Since the rate can be given
with different units, the method also needs to have a unit associated with the rate.
If no delay is required, this method does not need to be used. Default value is 0.
Args:
rate (int): Any positive value equal to or greater than zero.
unit (str): Any of the following predefined constants.
* **hz**: rate updates per second, maximum 96 kHz.
* **video**: rate updates per video frame, maximum 96 kHz.
* **nano**: rate updates period in nanoseconds, minimum 10417 ns.
:Low-level C definition:
``void DPxSetAuxSchedRate(unsigned rateValue, int rateUnits)``
"""
_DPxSetAuxSchedRateCall(rate, api_constants[unit.upper()])
# unsigned DPxGetAuxSchedRate(int *rateUnits)
# Get AUX schedule update rate (and optionally get rate units)
_DPxGetAuxSchedRateCall = DPxDll['DPxGetAuxSchedRate']
_DPxGetAuxSchedRateCall.restype = ctypes.c_uint
[docs]def DPxGetAuxSchedRate():
"""Gets AUX schedule update rate and the rate units.
Returns:
tuple: rate and unit.
:Low-level C definition:
``unsigned DPxGetAuxSchedRate(int *rateUnits))``
"""
Var = 0
p_Var = ctypes.c_int(Var)
return (_DPxGetAuxSchedRateCall(ctypes.byref(p_Var)), rate_constants[p_Var.value])
# void DPxSetAuxSchedCount(unsigned count)
# Set AUX schedule update count
_DPxSetAuxSchedCountCall = DPxDll['DPxSetAuxSchedCount']
_DPxSetAuxSchedCountCall.argtypes = [ctypes.c_uint]
_DPxSetAuxSchedCountCall.restype = None
[docs]def DPxSetAuxSchedCount(count):
"""Sets the AUX schedule update count
Args:
count (int): Schedule count.
:Low-level C definition:
``void DPxSetAuxSchedCount(unsigned count)``
"""
return _DPxSetAuxSchedCountCall(count)
# unsigned DPxGetAuxSchedCount()
# Get AUX schedule update count
_DPxGetAuxSchedCountCall = DPxDll['DPxGetAuxSchedCount']
_DPxGetAuxSchedCountCall.restype = ctypes.c_uint
[docs]def DPxGetAuxSchedCount():
"""Gets AUX schedule update count.
Returns:
int: The schdule update total count.
:Low-level C definition:
``unsigned DPxGetAuxSchedCount()``
"""
return _DPxGetAuxSchedCountCall()
# void DPxEnableAuxSchedCountdown()
# SchedCount decrements at SchedRate, and schedule stops automatically when count hits 0
_DPxEnableAuxSchedCountdownCall = DPxDll['DPxEnableAuxSchedCountdown']
_DPxEnableAuxSchedCountdownCall.restype = None
[docs]def DPxEnableAuxSchedCountdown():
"""Enables the AUX Schedule count down.
SchedCount increments at SchedRate, and schedule is stopped by calling Sched
:Low-level C definition:
``void DPxEnableAuxSchedCountdown()``
"""
return _DPxEnableAuxSchedCountdownCall()
# void DPxDisableAuxSchedCountdown()
# SchedCount increments at SchedRate, and schedule is stopped by calling SchedStop
_DPxDisableAuxSchedCountdownCall = DPxDll['DPxDisableAuxSchedCountdown']
_DPxDisableAuxSchedCountdownCall.restype = None
[docs]def DPxDisableAuxSchedCountdown():
"""Disables the AUX Schedule Countdown
SchedCount increments at SchedRate, and schedule is stopped by calling Sched
:Low-level C definition:
``void DPxDisableAuxSchedCountdown()``
"""
return _DPxDisableAuxSchedCountdownCall()
# int DPxIsAuxSchedCountdown()
# Returns non-0 if SchedCount decrements to 0 and automatically stops schedule
_DPxIsAuxSchedCountdownCall = DPxDll['DPxIsAuxSchedCountdown']
_DPxIsAuxSchedCountdownCall.restype = ctypes.c_int
[docs]def DPxIsAuxSchedCountdown():
"""Returns non-zero if SchedCount decrements to 0 and automatically stops the schedule.
Returns:
int: non-zero if ShedCount is 0
:Low-level C definition:
``int DPxIsAuxSchedCountdown()``
"""
return _DPxIsAuxSchedCountdownCall()
# void DPxSetAuxSched(unsigned onset, unsigned rateValue, int rateUnits, unsigned count)
# Shortcut which assigns Onset/Rate/Count. If Count > 0, enables Countdown mode.
_DPxSetAuxSchedCall= DPxDll['DPxSetAuxSched']
_DPxSetAuxSchedCall.argtypes = [ctypes.c_uint, ctypes.c_uint, ctypes.c_int, ctypes.c_uint]
_DPxSetAuxSchedCall.restype = None
[docs]def DPxSetAuxSched(onset, rateValue, rateUnits, count):
"""Sets AUX schedule onset, count and rate.
This function is a shortcut which assigns Onset/Rate/Count. If ``count`` is greater than zero, the count
down mode is enabled.
Args:
onset (int): Schedule onset.
rateValue (int): Rate value.
rateUnits (str): Usually ``hz``. Can also be ``video`` to update every ``rateValue`` video frames or ``nano`` to update every ``rateValue`` nanoseconds.
count (int): Schedule count.
:Low-level C definition:
``void DPxSetAuxSched(unsigned onset, unsigned rateValue, int rateUnits, unsigned count)``
"""
_DPxSetAuxSchedCall(onset, rateValue, api_constants[rateUnits.upper()], count)
# void DPxStartAuxSched()
# Start running a AUX schedule
_DPxStartAuxSchedCall = DPxDll['DPxStartAuxSched']
_DPxStartAuxSchedCall.restype = None
[docs]def DPxStartAuxSched():
"""Starts running an AUX schedule.
:Low-level C definition:
``void DPxStartAuxSched()``
"""
return _DPxStartAuxSchedCall()
# void DPxStopAuxSched()
# Stop running a AUX schedule
_DPxStopAuxSchedCall = DPxDll['DPxStopAuxSched']
_DPxStopAuxSchedCall.restype = None
[docs]def DPxStopAuxSched():
"""Stops running an AUX schedule.
:Low-level C definition:
``void DPxStopAuxSched()``
"""
return _DPxStopAuxSchedCall()
# int DPxIsAuxSchedRunning()
# Returns non-0 if AUX schedule is currently running
_DPxIsAuxSchedRunningCall = DPxDll['DPxIsAuxSchedRunning']
_DPxIsAuxSchedRunningCall.restype = ctypes.c_int
[docs]def DPxIsAuxSchedRunning():
"""Returns non-zero if an AUX schedule is currently running.
:Low-level C definition:
``int DPxIsAuxSchedRunning()``
"""
return _DPxIsAuxSchedRunningCall()
_DPxGetAudGroupDelayCall = DPxDll['DPxGetAudGroupDelay']
_DPxGetAudGroupDelayCall.restype = ctypes.c_double
_DPxGetAudGroupDelayCall.argtypes = [ctypes.c_double]
[docs]def DPxGetAudGroupDelay(sampleRate):
"""Gets the CODEC Audio OUT group delay in seconds.
Args:
sampleRate (float): The rate at which your schedule is running.
Returns:
float: delay in seconds.
:Low-level C definition:
``double DPxGetAudGroupDelay(double sampleRate)``
"""
return _DPxGetAudGroupDelayCall(sampleRate)
[docs]def DPxWriteAudioBuffer(bufferData,bufferAddress=int(16e6)):
"""
Writes the audio waveform data in 'bufferData' to the DATAPixx RAM at memory
address 'bufferAddress'.
Mimics the behavior of Datapixx('WriteAudioBuffer') in MATLAB, but with more flexibility
in the data format:
1) 'bufferData' can be of type float or of type int.
If 'bufferData' is of type float, it must be scaled between (-1,1).
If 'bufferData' is of type int, it must be scaled between (-32768,32768).
2) 'bufferData' can be either a list or a numpy.array.
3) 'bufferData' can be shaped either (N,), (N,1), (N,2), (1,N), or (2,N)
Args:
bufferData (list or numpy.array): contains waveform data. if a list, must be castable to a numeric numpy.array
bufferAddress (int): memory location in DATAPixx RAM.
default = int(16e6)
Exceptions:
1) bufferData cannot be casted into a numeric numpy.array
2) bufferData is empty
3) bufferData has more than 2 dimensions
4) bufferData has 2 dimensions but has no dimension of size 2
5) bufferAddress is not of type int or is less than 0 or is odd
"""
############################## check inputs
# buffer data
try:
# ensure casting to numpy.array
bufferData = np.array(bufferData).squeeze() # collapse (1,N) and (N,1) arrays to (N,)
# ensure bufferData has no non-numeric elements
# also catches jagged lists, as they will be casted to dtype='object'
if bufferData.dtype.str[1] not in ['i','f']:
raise Exception
except:
raise Exception("ERROR in %s\n'bufferData' must be a numeric numpy.array or a list castable to a numeric numpy.array" % sys.argv[0])
if not bool(bufferData.size):
raise Exception("ERROR in %s\nempty 'bufferData' passed. 'bufferData' must contain data" % sys.argv[0])
elif len(bufferData.shape) > 2:
raise Exception("ERROR in %s\n'bufferData' has more than 2 dimensions. 'bufferData' must be shaped as either (N,), (1,N), (2,N), (N,1), or (N,2)" % sys.argv[0])
elif len(bufferData.shape) == 2 and (2 not in bufferData.shape):
raise Exception("ERROR in %s\n2-dimensional 'bufferData' must have at least one size 2 dimension: (2,N) or (N,2)" % sys.argv[0])
# Datapixx buffer address for writing buffer data
if type(bufferAddress) is not int or bufferAddress < 0 or bufferAddress & 1:
raise Exception("ERROR in %s\n'bufferAddress' must be a positive, even integer" % sys.argv[0])
######################################### process
# Ensure use of columns as channels
if len(bufferData.shape) == 2 and bufferData.shape[0] == 2: # Channels correspond to rows
bufferData = np.transpose(bufferData)
# Rescale floating types to signed 16 bit integer: (-32768,32767)
if bufferData.dtype.str[1] == 'f':
if len(bufferData.shape) == 2:
bufferData[:,0] = bufferData[:,0] * 2**15
bufferData[:,1] = bufferData[:,1] * 2**15
else:
bufferData = bufferData * 2**15
bufferData[bufferData==2**15] -= 1
# Flatten bufferData (has no effect on 1D arrays), convert to short, convert to list
bufferData = bufferData.flatten().astype('int16').tolist()
# write audio wave form bufferData to buffer
chunkSize = 0xFFF0 // 4 # maximum allowable size of data per call to DPxWriteRam()
numberOfChunks = np.ceil(len(bufferData)/chunkSize).astype(int)
for i in range(numberOfChunks):
addr = chunkSize*i*2+bufferAddress
index1 = chunkSize*i
index2 = chunkSize*(i+1) if chunkSize*(i+1) < len(bufferData) else len(bufferData)
DPxWriteRam(addr, bufferData[index1:index2])
[docs]def DPxSetAudioSchedule(scheduleOnset, scheduleRate, maxScheduleFrames, lrMode='mono', bufferAddress=int(16e6), numBufferFrames=None):
"""
Implements an audio schedule in a DATAPixx.
Mimics the behavior of Datapixx('SetAudioSchedule') in MATLAB, but with more flexibility
in the 'lrMode' format. 'lrMode' can be passed as an integer (as in MATLAB), or as a
string.
Args:
scheduleOnset (float): the audio schedule delay in seconds
scheduleRate (int): the audio codec sampling rate in Hz
maxScheduleFrames (int): the number of samples after which the audio codec stops sampling.
if maxScheduleFrames > numBufferFrames, the audio codec loops back
to sample data at the start address of the audio buffer.
lrMode (int/string): the audio stereo mode. acceptable inputs are in the 'int' and 'string' columns:
int string description
0 'mono' same output to left and right speakers
1 'left' output to left speaker only
2 'right' output to right speaker only
3 'stereo1' 1st row of 'bufferData' to left speaker. 2nd row of 'bufferData' to right speaker.
4 'stereo2' audio data to left speaker. auxillary data to right speaker.
default='mono'
bufferAddress (int): memory location in DATAPixx RAM
default=0
numBufferFrames (int): number of audio samples written into DATAPixx RAM.
default = maxScheduleFrames
Exceptions:
1) scheduleOnset is not of type float or is less than 0
2) scheduleOnset * 10**9 is greater than 0xffffffff
3) scheduleRate is not of type int. warning when scheduleRate is not in the interval (8000,96000)
4) maxScheduleFrames is not of type int or is less than 0
5) maxScheduleFrames is zero and numBufferFrames is omitted
6) lrMode is not equal to any acceptable values. acceptable values given in error message
7) bufferAddress is not of type int or is less than 0 or is odd
8) numBufferFrames is not of type int or is less than 0
"""
############################## check inputs
# schedule start time delay
if type(scheduleOnset) is not float or scheduleOnset < 0:
raise Exception("ERROR in %s\n'scheduleOnset' must be a positive float" % sys.argv[0])
scheduleOnset = int(scheduleOnset*10**9) # convert to int nanosecond delay
if scheduleOnset > 0xffffffff:
raise Exception("ERROR in %s\n'scheduleOnset' must be less than 4.295 seconds" % sys.argv[0])
# sampling scheduleRate
if type(scheduleRate) is not int:
raise Exception("ERROR in %s\n'scheduleRate' must be an integer between 8000 and 96000 Hz" % sys.argv[0])
elif scheduleRate < 8e3 or scheduleRate > 96e3:
scheduleRate = int([8e3,96e3][scheduleRate>96e3])
print("\nWARNING in %s\n'scheduleRate' value of '%d' will be defaulted to %d. sampling scheduleRate values must be between 8000 and 96000 Hz.\n" % (sys.argv[0],scheduleRate>96e3,scheduleRate>96e3) )
# number of samples
if type(maxScheduleFrames) is not int or maxScheduleFrames < 0:
raise Exception("ERROR in %s\n'maxScheduleFrames' must be a positive integer" % sys.argv[0])
# check that numBufferFrames is provided if maxScheduleFrames == 0
if maxScheduleFrames==0 and numBufferFrames is None:
raise Exception("ERROR in %s\n'numBufferFrames' must be provided if 'maxScheduleFrames'==0" % sys.argv[0])
# stereo lrModes
lrModes = ["mono","left","right","stereo1","stereo2"]
if (type(lrMode) is str and not(lrMode.lower() in lrModes)) or (type(lrMode) is int and (lrMode<0 or lrMode>4)):
raise Exception("ERROR in %s\n'lrMode' must one of the following integers or corresponding strings:\n0\t'mono'\n1\t'left'\n2\t'right'\n3\t'stereo1'\n4\t'stereo2'" % sys.argv[0])
if type(lrMode) is int:
lrMode = lrModes[lrMode]
# bufferDatapixx buffer address for writing bufferData
if type(bufferAddress) is not int or bufferAddress < 0 or bufferAddress & 1:
raise Exception("ERROR in %s\n'bufferAddress' must be a positive integer" % sys.argv[0])
# buffer size. NOTE: this is the number of bytes. 'bufferData' is formated as signed 16-bit integers, so the length needs to be multiplied by 2
if numBufferFrames is None: # default
numBufferFrames = maxScheduleFrames
elif type(numBufferFrames) is not int or numBufferFrames < 0:
raise Exception("ERROR in %s\n'numBufferFrames' must be a positive integer" % sys.argv[0])
numBufferFrames *= 2
# process ########################################
# schedule audio
DPxSetAudSched(scheduleOnset, scheduleRate, 'hz', maxScheduleFrames)
# set speaker lrMode
DPxSetAudLRMode(lrMode)
# set buffer address and size
DPxSetAudBuffBaseAddr(bufferAddress)
DPxSetAudBuffReadAddr(bufferAddress)
# set buffer size
DPxSetAudBuffSize(numBufferFrames)
# void DPxSetMicSource(int source, double gain, int dBUnits)
# Select the source of the microphone input. Typical gain values would be around 100 for a
# microphone input, and probably 1 for line-level input.
#
# Return value:
# N/A
# Arguments:
# source is one of the following predefined constants:
# DPX_MIC_SRC_MIC_IN : Microphone level input
# DPX_MIC_SRC_LINE_IN : Line level audio input.
# gain can take the following values:
# linear scale : min = 1, max = 1000
# dB scale : min = 0, max = 60 dB
# dBUnits is one of the following value:
# 0 : Set dBUnits in linear scale
# 1 : Set dBUnits in dB scale
_DPxSetMicSourceCall = DPxDll['DPxSetMicSource']
_DPxSetMicSourceCall.argtypes = [ctypes.c_int, ctypes.c_double, ctypes.c_int]
_DPxSetMicSourceCall.restype = None
[docs]def DPxSetMicSource(source, gain, dBUnits=0):
"""Sets the source for the microphone.
Selects the source of the microphone input. Typical gain values would be around 100 for a
microphone input, and around 1 for line-level input.
Args:
source (str): One of the following:
* ``MIC``: Microphone level input
* ``LINE``: Line level audio input.
gain (int): The gain can take the following values depnding on the scale:
* linear scale : [1, 1000]
* dB scale : [0, 60] dB
dBUnits (int, optional): Set non-zero to return the gain in dB. Defaults to 0.
:Low-level C definition:
``void DPxSetMicSource(int source, double gain, int dBUnits)``
"""
return _DPxSetMicSourceCall(api_constants[source.upper()], gain, dBUnits)
# int DPxGetMicSource(int DBUnits)
# Get the source and the gain of the microphone input
_DPxGetMicSourceCall = DPxDll['DPxGetMicSource']
_DPxGetMicSourceCall.restype = ctypes.c_int
[docs]def DPxGetMicSource(dBUnits=0):
"""Gets the source and the gain of the microphone input.
Args:
dBUnits (int, optional): Set to non-zero to return the gain in dB. Defaults to 0.
Returns:
list: A list containing the [gain value, microphone source]
:Low-level C definition:
``int DPxGetMicSource(int DBUnits)``
"""
gain = 0
p_gain = ctypes.c_double(gain)
dbUnit = _DPxGetMicSourceCall(ctypes.byref(p_gain), dBUnits)
return [p_gain.value, dbUnit]
# int DPxGetMicLeftValue()
# Get the 16-bit 2's complement signed value for left MIC channel
_DPxGetMicLeftValueCall = DPxDll['DPxGetMicLeftValue']
_DPxGetMicLeftValueCall.restype = ctypes.c_int
[docs]def DPxGetMicLeftValue():
"""Get the 16-bit 2's complement signed value for left MIC channel
Returns:
int: value for left MIC channel
:Low-level C definition:
``int DPxGetMicLeftValue()``
"""
return _DPxGetMicLeftValueCall()
# int DPxGetMicRightValue()
# Get the 16-bit 2's complement signed value for right MIC channel
_DPxGetMicRightValueCall = DPxDll['DPxGetMicRightValue']
_DPxGetMicRightValueCall.restype = ctypes.c_int
[docs]def DPxGetMicRightValue():
"""Get the 16-bit 2's complement signed value for right MIC channel
Returns:
int: value for right MIC channel
:Low-level C definition:
``int DPxGetMicRightValue()``
"""
return _DPxGetMicRightValueCall()
_DPxSetMicLRModeCall = DPxDll['DPxSetMicLRMode']
_DPxSetMicLRModeCall.restype = None
_DPxSetMicLRModeCall.restype = None
[docs]def DPxSetMicLRMode(mode):
"""Sets the schedule buffer storing mode.
This method allows the user to configure how the microphone left and right channels are stored to the schedule buffer.
Args:
mode (str) : Any of the following predefined constants.
* **mono**: Mono data is written to the schedule buffer. The average of Left/Right CODEC data.
* **left**: Left data is written to the schedule buffer.
* **right**: Right data is written to the schedule buffer.
* **stereo**: Left and Right data are both written to the schedule buffer.
:Low-level C definition:
``void DPxSetMicLRMode(int lrMode)``
"""
_DPxSetMicLRModeCall(api_constants[mode.upper()])
_DPxGetMicLRModeCall = DPxDll['DPxGetMicLRMode']
_DPxGetMicLRModeCall.restype = ctypes.c_int
[docs]def DPxGetMicLRMode():
"""Gets the microphone Left/Right configuration mode.
This method allows the user to get the microphone left and right channels schedule buffer mode.
Returns:
String: Any of the following predefined constants.
* **mono**: Mono data is written to the schedule buffer. The average of the Left/Right CODEC data.
* **left**: Left data is written to the schedule buffer.
* **right**: Right data is written to the schedule buffer.
* **stereo**: Left and Right data are both written to the schedule buffer.
:Low-level C definition:
``int DPxGetMicLRMode()``
"""
return mic_mode_constants[ _DPxGetMicLRModeCall()]
# void DPxEnableAudMicLoopback()
# Enable loopback between audio outputs and microphone inputs
_DPxEnableAudMicLoopbackCall = DPxDll['DPxEnableAudMicLoopback']
_DPxEnableAudMicLoopbackCall.restype = None
[docs]def DPxEnableAudMicLoopback():
"""Enables loopback between audio outputs and microphone inputs
:Low-level C definition:
``void DPxEnableAudMicLoopback()``
"""
return _DPxEnableAudMicLoopbackCall()
# void DPxDisableAudMicLoopback()
# Disable loopback between audio outputs and microphone inputs
_DPxDisableAudMicLoopbackCall = DPxDll['DPxDisableAudMicLoopback']
_DPxDisableAudMicLoopbackCall.restype = None
[docs]def DPxDisableAudMicLoopback():
"""Disables loopback between audio outputs and microphone inputs
:Low-level C definition:
``void DPxDisableAudMicLoopback()``
"""
return _DPxDisableAudMicLoopbackCall()
# int DPxIsAudMicLoopback()
# Returns non-0 if microphone inputs are driven by audio outputs
_DPxIsAudMicLoopbackCall = DPxDll['DPxIsAudMicLoopback']
_DPxIsAudMicLoopbackCall.restype = ctypes.c_int
[docs]def DPxIsAudMicLoopback():
"""Returns non-zero if microphone inputs are driven by audio outputs.
:Low-level C definition:
``int DPxIsAudMicLoopback()``
"""
return _DPxIsAudMicLoopbackCall()
# void DPxSetMicBuffBaseAddr(unsigned buffBaseAddr)
# Set MIC RAM buffer start address. Must be an even value.
_DPxSetMicBuffBaseAddrCall = DPxDll['DPxSetMicBuffBaseAddr']
_DPxSetMicBuffBaseAddrCall.argtypes = [ctypes.c_uint]
_DPxSetMicBuffBaseAddrCall.restype = None
[docs]def DPxSetMicBuffBaseAddr(buffBaseAddr):
"""Sets the MIC RAM buffer start address.
The address must be an even value.
Args:
buffBaseAddr (int): Base address.
:Low-level C definition:
``void DPxSetMicBuffBaseAddr(unsigned buffBaseAddr)``
"""
return _DPxSetMicBuffBaseAddrCall(buffBaseAddr)
# unsigned DPxGetMicBuffBaseAddr()
# Get MIC RAM buffer start address
_DPxGetMicBuffBaseAddrCall = DPxDll['DPxGetMicBuffBaseAddr']
_DPxGetMicBuffBaseAddrCall.restype = ctypes.c_uint
[docs]def DPxGetMicBuffBaseAddr():
"""Gets the MIC RAM buffer start address.
Returns:
int: Base address.
:Low-level C definition:
``unsigned DPxGetMicBuffBaseAddr()``
"""
return _DPxGetMicBuffBaseAddrCall()
# void DPxSetMicBuffWriteAddr(unsigned buffWriteAddr)
# Set RAM address to which next MIC datum will be written. Must be an even value.
_DPxSetMicBuffWriteAddrCall = DPxDll['DPxSetMicBuffWriteAddr']
_DPxSetMicBuffWriteAddrCall.argtypes = [ctypes.c_uint]
_DPxSetMicBuffWriteAddrCall.restype = None
[docs]def DPxSetMicBuffWriteAddr(buffWriteAddr):
"""Sets RAM address from which next MIC datum will be written.
The address must be an even value.
:Low-level C definition:
``void DPxSetMicBuffWriteAddr(unsigned buffWriteAddr)``
"""
return _DPxSetMicBuffWriteAddrCall(buffWriteAddr)
# double DPxGetMicGroupDelay(double sampleRate)
# Returns CODEC MIC IN group delay in seconds
_DPxGetMicGroupDelayCall = DPxDll['DPxGetMicGroupDelay']
_DPxGetMicGroupDelayCall.restype = ctypes.c_double
_DPxGetMicGroupDelayCall.argtypes = [ctypes.c_double]
[docs]def DPxGetMicGroupDelay(sampleRate):
"""Gets the CODEC Audio OUT group delay in seconds.
Args:
sampleRate (float): The sample rate of your schedule
Returns:
float: delay in seconds.
:Low-level C definition:
``double DPxGetMicGroupDelay(double sampleRate)``
"""
return _DPxGetMicGroupDelayCall(sampleRate)
# unsigned DPxGetMicBuffWriteAddr()
# Get RAM address to which next MIC datum will be written
_DPxGetMicBuffWriteAddrCall = DPxDll['DPxGetMicBuffWriteAddr']
_DPxGetMicBuffWriteAddrCall.restype = ctypes.c_uint
[docs]def DPxGetMicBuffWriteAddr():
"""Gets RAM address from which next MIC datum will be written.
Returns:
int: Write address.
:Low-level C definition:
``unsigned DPxGetMicBuffWriteAddr()``
"""
return _DPxGetMicBuffWriteAddrCall()
# unsigned DPxGetMicBuffSize()
# Get MIC RAM buffer size in bytes
_DPxGetMicBuffSizeCall = DPxDll['DPxGetMicBuffSize']
_DPxGetMicBuffSizeCall.restype = ctypes.c_uint
[docs]def DPxGetMicBuffSize():
"""Gets the DAC RAM buffer size in bytes.
Returns:
int: buffer size.
:Low-level C definition:
``unsigned DPxGetMicBuffSize()``
"""
return _DPxGetMicBuffSizeCall()
# unsigned DPxGetMicSchedOnset()
# Get nanosecond delay between schedule start and first MIC sample
_DPxGetMicSchedOnsetCall = DPxDll['DPxGetMicSchedOnset']
_DPxGetMicSchedOnsetCall.restype = ctypes.c_uint
[docs]def DPxGetMicSchedOnset():
"""Gets the nanosecond delay between schedule start and first MIC update.
Returns:
int: The nanosecond onset between the first update and the start of schedule.
:Low-level C definition:
``unsigned DPxGetMicSchedOnset()``
"""
return _DPxGetMicSchedOnsetCall()
# unsigned DPxGetMicSchedRate(int *rateUnits)
# Get MIC schedule sample rate (and optionally get rate units)
_DPxGetMicSchedRateCall = DPxDll['DPxGetMicSchedRate']
_DPxGetMicSchedRateCall.restype = ctypes.c_uint
[docs]def DPxGetMicSchedRate():
"""Gets MIC schedule update rate and the rate units.
Returns:
tuple: rate and unit.
:Low-level C definition:
``unsigned DPxGetDacSchedRate(int *rateUnits)``
"""
Var = 0
p_Var = ctypes.c_int(Var)
return (int(_DPxGetMicSchedRateCall(ctypes.byref(p_Var))), rate_constants[p_Var.value])
# unsigned DPxGetMicSchedCount()
# Get MIC schedule sample count
_DPxGetMicSchedCountCall = DPxDll['DPxGetMicSchedCount']
_DPxGetMicSchedCountCall.restype = ctypes.c_uint
[docs]def DPxGetMicSchedCount():
"""Gets MIC schedule update count.
Returns:
int: The current MIC schedule count.
:Low-level C definition:
``unsigned DPxGetMicSchedCount()``
"""
return _DPxGetMicSchedCountCall()
# void DPxSetMicBuffSize(unsigned buffSize)
# Set MIC RAM buffer size in bytes. Must be an even value. Buffer wraps after Size.
_DPxSetMicBuffSizeCall = DPxDll['DPxSetMicBuffSize']
_DPxSetMicBuffSizeCall.argtypes = [ctypes.c_uint]
_DPxSetMicBuffSizeCall.restype = None
[docs]def DPxSetMicBuffSize(buffSize):
"""Sets MIC RAM buffer size in bytes.
Must be an even value. Buffer wraps to Base after Size.
Args:
buffSize (int): Buffer size.
:Low-level C definition:
``void DPxSetMicBuffSize(unsigned buffSize)``
"""
return _DPxSetMicBuffSizeCall(buffSize)
# void DPxSetMicBuff(unsigned buffAddr, unsigned buffSize)
# Shortcut which assigns Size/BaseAddr/ReadAddr
_DPxSetMicBuffCall = DPxDll['DPxSetMicBuff']
_DPxSetMicBuffCall.argtypes = [ctypes.c_uint, ctypes.c_uint]
_DPxSetMicBuffCall.restype = None
[docs]def DPxSetMicBuff(buffAddr, buffSize):
"""Sets base address, reads address and buffer size for MIC schedules.
This function is a shortcut which assigns Size/BaseAddr/ReadAddr.
Args:
buffAddr (int): Base address.
buffSize (int): Buffer size.
:Low-level C definition:
``void DPxSetMicBuff(unsigned buffAddr, unsigned buffSize)``
"""
return _DPxSetMicBuffCall(buffAddr, buffSize)
# void DPxSetMicSchedOnset(unsigned onset)
# Set nanosecond delay between schedule start and first MIC sample
_DPxSetMicSchedOnsetCall = DPxDll['DPxSetMicSchedOnset']
_DPxSetMicSchedOnsetCall.argtypes = [ctypes.c_uint]
_DPxSetMicSchedOnsetCall.restype = None
[docs]def DPxSetMicSchedOnset(onset):
"""Sets nanosecond delay between schedule start and first MIC update.
Args:
onset (int): The onset value.
:Low-level C definition:
``void DPxSetMicSchedOnset(unsigned onset)``
"""
return _DPxSetMicSchedOnsetCall(onset)
_DPxSetMicSchedRateCall = DPxDll['DPxSetMicSchedRate']
_DPxSetMicSchedRateCall.argtypes = [ctypes.c_uint, ctypes.c_int]
_DPxSetMicSchedRateCall.restype = None
[docs]def DPxSetMicSchedRate(rate, unit):
"""Sets the MIC schedule rate.
This method allows the user to set the schedule rate. Since the rate can be given
with different units, the method also needs to have a unit associated with the rate.
If no delay is required, this method does not need to be used. Default value is 0.
Args:
rate (int): Any positive value equal to or greater than zero.
unit (str): Any of the following predefined constants.
* **hz**: rate updates per second, maximum 102.4 kHz.
* **video**: rate updates per video frame, maximum 102.4 kHz.
* **nano**: rate updates period in nanoseconds, minimum 9750 ns.
:Low-level C definition:
``void DPxSetMicSchedRate(unsigned rateValue, int rateUnits)``
"""
_DPxSetMicSchedRateCall(rate, api_constants[unit.upper()])
# void DPxSetMicSchedCount(unsigned count)
# Set MIC schedule sample count
_DPxSetMicSchedCountCall = DPxDll['DPxSetMicSchedCount']
_DPxSetMicSchedCountCall.argtypes = [ctypes.c_uint]
_DPxSetMicSchedCountCall.restype = None
[docs]def DPxSetMicSchedCount(count):
"""Sets MIC schedule update count.
Args:
count (int): Schedule count.
:Low-level C definition:
``void DPxSetMicSchedCount(unsigned count)``
"""
return _DPxSetMicSchedCountCall(count)
# void DPxEnableMicSchedCountdown()
# SchedCount decrements at SchedRate, and schedule stops automatically when count hits 0
_DPxEnableMicSchedCountdownCall = DPxDll['DPxEnableMicSchedCountdown']
_DPxEnableMicSchedCountdownCall.restype = None
[docs]def DPxEnableMicSchedCountdown():
"""Enables MIC schedule count down.
SchedCount increments at SchedRate, and schedule is stopped by calling SchedStop.
:Low-level C definition:
``void DPxEnableMicSchedCountdown()``
"""
return _DPxEnableMicSchedCountdownCall()
# void DPxDisableMicSchedCountdown()
# SchedCount increments at SchedRate, and schedule is stopped by calling SchedStop
_DPxDisableMicSchedCountdownCall = DPxDll['DPxDisableMicSchedCountdown']
_DPxDisableMicSchedCountdownCall.restype = None
[docs]def DPxDisableMicSchedCountdown():
"""Disables MIC schedule count down.
SchedCount increments at SchedRate, and schedule is stopped by calling SchedStop.
:Low-level C definition:
``void DPxDisableMicSchedCountdown()``
"""
return _DPxDisableMicSchedCountdownCall()
# void DPxSetMicSched(unsigned onset, unsigned rateValue, int rateUnits, unsigned count)
# Shortcut which assigns Onset/Rate/Count. If Count > 0, enables Countdown mode.
_DPxSetMicSchedCall = DPxDll['DPxSetMicSched']
_DPxSetMicSchedCall.argtypes = [ctypes.c_uint, ctypes.c_uint, ctypes.c_int, ctypes.c_uint]
_DPxSetMicSchedCall.restype = None
[docs]def DPxSetMicSched(onset, rateValue, rateUnits, count):
"""Sets MIC schedule onset, count and rate.
This function is a shortcut which assigns Onset/Rate/Count. If ``count`` is greater than zero, the count
down mode is enabled.
Args:
onset (int): Schedule onset.
rateValue (int): Rate value.
rateUnits (str): Usually ``hz``. Can also be ``video`` to update every ``rateValue`` video frames or ``nano`` to update every ``rateValue`` nanoseconds.
count (int): Schedule count.
:Low-level C definition:
``void DPxSetMicSched(unsigned onset, unsigned rateValue, int rateUnits, unsigned count)``
"""
return _DPxSetMicSchedCall(onset, rateValue, api_constants[rateUnits.upper()], count)
# void DPxStartMicSched()
# Start running an MIC schedule
_DPxStartMicSchedCall = DPxDll['DPxStartMicSched']
_DPxStartMicSchedCall.restype = None
[docs]def DPxStartMicSched():
"""Starts running a MIC schedule
:Low-level C definition:
``void DPxStartMicSched()``
"""
return _DPxStartMicSchedCall()
# void DPxStopMicSched()
# Stop running an MIC schedule
_DPxStopMicSchedCall= DPxDll['DPxStopMicSched']
_DPxStopMicSchedCall.restype = None
[docs]def DPxStopMicSched():
"""Stops running a MIC schedule.
:Low-level C definition:
``void DPxStopMicSched()``
"""
return _DPxStopMicSchedCall()
# int DPxIsMicSchedCountdown()
# Returns non-0 if SchedCount decrements to 0 and automatically stops schedule
_DPxIsMicSchedCountdownCall = DPxDll['DPxIsMicSchedCountdown']
_DPxIsMicSchedCountdownCall.restype = ctypes.c_int
[docs]def DPxIsMicSchedCountdown():
"""Returns non-zero if SchedCount decrements to 0 and automatically stops schedule
:Low-level C definition:
``int DPxIsMicSchedCountdown()``
"""
return _DPxIsMicSchedCountdownCall()
# int DPxIsMicSchedRunning()
# Returns non-0 if MIC schedule is currently running
_DPxIsMicSchedRunningCall = DPxDll['DPxIsMicSchedRunning']
_DPxIsMicSchedRunningCall.restype = ctypes.c_int
[docs]def DPxIsMicSchedRunning():
"""Returns non-zero if MIC schedule is currently running
:Low-level C definition:
``int DPxIsMicSchedRunning()``
"""
return _DPxIsMicSchedRunningCall()
_DPxSetVidModeCall = DPxDll['DPxSetVidMode']
_DPxSetVidModeCall.restype = None
[docs]def DPxSetVidMode(mode):
"""Sets the video processing mode.
Only available for PROPixx Revision 6 and higher.
Args:
mode (str) : Any of the following predefined constants.
- **L48**: DVI RED[7:0] is used as an index into a 256-entry 16-bit RGB colour lookup table.
- **M16**: DVI RED[7:0] & GREEN[7:0] concatenate into a VGA 16-bit value sent to all three RGB components.
- **C48**: Even/Odd pixel RED/GREEN/BLUE[7:0] concatenate to generate 16-bit RGB components at half the horizontal resolution.
- **L48D**: DVI RED[7:4] & GREEN[7:4] concatenate to form an 8-bit index into a 256-entry 16-bit RGB colour lookup table.
- **M16D**: DVI RED[7:3] & GREEN[7:3] & BLUE[7:2] concatenate into a VGA 16-bit value sent to all three RGB components.
- **C36D**: Even/Odd pixel RED/GREEN/BLUE[7:2] concatenate to generate 12-bit RGB components at half the horizontal resolution.
- **C24**: Straight passthrough from DVI 8-bit (or HDMI "deep" 10/12-bit) RGB to VGA 8/10/12-bit RGB.
:Low-level C definition:
``void DPxSetVidMode(int vidMode)``
"""
_DPxSetVidModeCall( api_constants[mode.upper()] )
_DPxGetVidModeCall = DPxDll['DPxGetVidMode']
_DPxGetVidModeCall.restype = ctypes.c_int
[docs]def DPxGetVidMode():
"""Gets the video processing mode.
Allows the user to know if it is in the correct mode or which mode is currently used on the device.
Returns:
String: Any of the following predefined constants.
- **L48**: DVI RED[7:0] is used as an index into a 256-entry 16-bit RGB colour lookup table.
- **M16**: DVI RED[7:0] & GREEN[7:0] concatenate into a VGA 16-bit value sent to all three RGB components.
- **C48**: Even/Odd pixel RED/GREEN/BLUE[7:0] concatenate to generate 16-bit RGB components at half the horizontal resolution.
- **L48D**: DVI RED[7:4] & GREEN[7:4] concatenate to form an 8-bit index into a 256-entry 16-bit RGB colour lookup table.
- **M16D**: DVI RED[7:3] & GREEN[7:3] & BLUE[7:2] concatenate into a VGA 16-bit value sent to all three RGB components.
- **C36D**: Even/Odd pixel RED/GREEN/BLUE[7:2] concatenate to generate 12-bit RGB components at half the horizontal resolution.
- **C24**: Straight passthrough from DVI 8-bit (or HDMI "deep" 10/12-bit) RGB to VGA 8/10/12-bit RGB.
:Low-level C definition:
``int DPxGetVidMode()``
"""
videoM = _DPxGetVidModeCall()
return video_mode_constants[_DPxGetVidModeCall()] if (videoM in video_mode_constants) else "UNKNOWN"
# void DPxSetVidClut(UInt16* clutData)
# Pass 256*3 (=768) 16-bit video DAC data, in order R0,G0,B0,R1,G1,B1...
# DPxSetVidClut() returns immediately, and CLUT is implemented at next vertical blanking interval.
_DPxSetVidClutCall = DPxDll['DPxSetVidClut']
_DPxSetVidClutCall.restype = None
[docs]def DPxSetVidClut(CLUT):
"""Sets the video color lookup table (CLUT).
This function returns immediately; the CLUT is implemented at the next vertical blanking interval.
Args:
CLUT (list): A list of 3 lists representing the colors [[RED], [GREEN], [BLUE]]
:Low-level C definition:
``void DPxSetVidClut(UInt16* clutData)``
"""
# First we need to unpack the CLUT
unpacked_CLUT = []
for i in range(len(CLUT[0])):
unpacked_CLUT.append(CLUT[0][i])
unpacked_CLUT.append(CLUT[1][i])
unpacked_CLUT.append(CLUT[2][i])
# Then we need to convert it to a proper Uint16 array
item_count = len(unpacked_CLUT)
packed_data = (ctypes.c_uint16 * item_count)(*unpacked_CLUT)
_DPxSetVidClutCall(packed_data)
# void DPxSetVidCluts(UInt16* clutData)
# Pass 512*3 (=1536) 16-bit video DAC data to fill 2 channel CLUTs with independent data, in order R0,G0,B0,R1,G1,B1...
_DPxSetVidClutsCall = DPxDll['DPxSetVidCluts']
_DPxSetVidClutsCall.restype = None
[docs]def DPxSetVidCluts(CLUTs):
"""Sets the video color lookup tables.
Args:
CLUT (list): A list of 3 lists representing the colors [[RED], [GREEN], [BLUE]]
:Low-level C definition:
``void DPxSetVidCluts(UInt16* clutData)``
"""
unpacked_CLUT = []
for i in range(len(CLUTs[0])):
unpacked_CLUT.append(CLUTs[0][i])
unpacked_CLUT.append(CLUTs[1][i])
unpacked_CLUT.append(CLUTs[2][i])
# Then we need to convert it to a proper Uint16 array
item_count = len(unpacked_CLUT)
packed_data = (ctypes.c_uint16 * item_count)(*unpacked_CLUT)
_DPxSetVidClutsCall(packed_data)
_DPxSetVidClutTransparencyColorCall = DPxDll['DPxSetVidClutTransparencyColor']
_DPxSetVidClutTransparencyColorCall.restype = None
_DPxSetVidClutTransparencyColorCall.argtypes = [ctypes.c_uint16, ctypes.c_uint16, ctypes.c_uint16]
[docs]def DPxSetVidClutTransparencyColor(red, green, blue):
"""Set 48-bit RGB video CLUT transparency color.
This function allows the user to set the value for the RGB video CLUT transparency color.
Args:
red (int): Pixel color value for the red channel.
green (int): Pixel color value for the green channel.
blue (int): Pixel color value for the blue channel.
:Low-level C definition:
``void DPxSetVidClutTransparencyColor(UInt16 red, UInt16 green, UInt16 blue)``
See Also:
:class:`DPxGetVidClutTransparencyColor`
"""
_DPxSetVidClutTransparencyColorCall(red, green, blue)
_DPxGetVidClutTransparencyColorCall = DPxDll['DPxGetVidClutTransparencyColor']
_DPxGetVidClutTransparencyColorCall.restype = None
[docs]def DPxGetVidClutTransparencyColor():
"""Get 48-bit RGB video CLUT transparency color
This function allows the user to know the current register value for the RGB video CLUT transparency color.
The returned value is a tupple which contains the red, green and blue values.
Returns:
red (int): Pixel color value for the red channel.
green (int): Pixel color value for the green channel.
blue (int): Pixel color value for the blue channel.
:Low-level C definition:
``void DPxGetVidClutTransparencyColor(UInt16* red, UInt16* green, UInt16* blue)``
See Also:
:class:`DPxSetVidClutTransparencyColor`
"""
red = 0
green = 0
blue = 0
p_red = ctypes.c_uint16(red)
p_green = ctypes.c_uint16(green)
p_blue = ctypes.c_uint16(blue)
_DPxGetVidClutTransparencyColorCall(ctypes.byref(p_red), ctypes.byref(p_green), ctypes.byref(p_blue))
return (p_red.value, p_green.value, p_blue.value)
_DPxEnableVidClutTransparencyColorModeCall= DPxDll['DPxEnableVidClutTransparencyColorMode']
_DPxEnableVidClutTransparencyColorModeCall.restype = None
[docs]def DPxEnableVidClutTransparencyColorMode():
"""Enables video CLUT transparency color mode.
:Low-level C definition:
``void DPxEnableVidClutTransparencyColorMode()``
See Also:
:class:`DPxDisableVidClutTransparencyColorMode`, :class:`DPxIsVidClutTransparencyColorMode`, :class:`DPxGetVidClutTransparencyColor`,
:class:`DPxSetVidClutTransparencyColor`,
"""
return _DPxEnableVidClutTransparencyColorModeCall()
_DPxDisableVidClutTransparencyColorModeCall= DPxDll['DPxDisableVidClutTransparencyColorMode']
_DPxDisableVidClutTransparencyColorModeCall.restype = None
[docs]def DPxDisableVidClutTransparencyColorMode():
""" Disables video CLUT transparency color mode
:Low-level C definition:
``void DPxDisableVidClutTransparencyColorMode()``
See Also:
:class:`DPxEnableVidClutTransparencyColorMode`, :class:`DPxIsVidClutTransparencyColorMode`, :class:`DPxGetVidClutTransparencyColor`,
:class:`DPxSetVidClutTransparencyColor`
"""
return _DPxDisableVidClutTransparencyColorModeCall()
_DPxIsVidClutTransparencyColorModeCall = DPxDll['DPxIsVidClutTransparencyColorMode']
_DPxIsVidClutTransparencyColorModeCall.restype = ctypes.c_int
[docs]def DPxIsVidClutTransparencyColorMode():
"""Verifies is the video CLUT transparency color mode is enabled.
This function allows the user to know if the video CLUT transparency color mode is enabled or not.
Returns:
int: When the mode is disabled, 0 is returned. When the mode is enabled, it returns Non-zero.
:Low-level C definition:
``int DPxIsVidClutTransparencyColorMode()``
See Also:
:class:`DPxEnableVidClutTransparencyColorMode`, :class:`DPxDisableVidClutTransparencyColorMode`, :class:`DPxGetVidClutTransparencyColor`,
:class:`DPxSetVidClutTransparencyColor`
"""
return _DPxIsVidClutTransparencyColorModeCall()
# void DPxEnableVidHorizSplit()
# VGA 1 shows left half of video image, VGA 2 shows right half of video image. The two VGA outputs are perfectly synchronized.
_DPxEnableVidHorizSplitCall= DPxDll['DPxEnableVidHorizSplit']
_DPxEnableVidHorizSplitCall.restype = None
[docs]def DPxEnableVidHorizSplit():
"""Enables Video Horizontal Split.
VGA 1 shows the left half of video image, VGA 2 shows the right half of video image. The two VGA outputs are perfectly synchronized.
:Low-level C definition:
``void DPxEnableVidHorizSplit()``
"""
return _DPxEnableVidHorizSplitCall()
# void DPxDisableVidHorizSplit()
# VGA 1 and VGA 2 both show entire video image (hardware video mirroring)
_DPxDisableVidHorizSplitCall= DPxDll['DPxDisableVidHorizSplit']
_DPxDisableVidHorizSplitCall.restype = None
[docs]def DPxDisableVidHorizSplit():
"""Disables Video Horizontal Split.
VGA 1 and VGA 2 both show the entire video's image (hardware video mirroring)/
:Low-level C definition:
``void DPxDisableVidHorizSplit()``
"""
return _DPxDisableVidHorizSplitCall()
# void DPxAutoVidHorizSplit()
# DATAPixx will automatically split video across the two VGA outputs if the horizontal resolution is at least twice the vertical resolution (default mode)
_DPxAutoVidHorizSplitCall = DPxDll['DPxAutoVidHorizSplit']
_DPxAutoVidHorizSplitCall.restype = None
[docs]def DPxAutoVidHorizSplit():
""" Sets the Horizontal Split mode automatically
DATAPixx will automatically split video across the two VGA outputs if the horizontal
resolution is at least twice the vertical resolution (default mode).
:Low-level C definition:
``void DPxAutoVidHorizSplit()``
"""
return _DPxAutoVidHorizSplitCall()
# int DPxIsVidHorizSplit()
# Returns non-0 if video is being split across the two VGA outputs.
_DPxIsVidHorizSplitCall = DPxDll['DPxIsVidHorizSplit']
_DPxIsVidHorizSplitCall.restype = ctypes.c_int
[docs]def DPxIsVidHorizSplit():
"""Verifies if the video is being split across the two VGA outputs, or not.
Returns:
int: Returns non-zero if video is being split across the two VGA outputs.
:Low-level C definition:
``int DPxIsVidHorizSplit()``
"""
return _DPxIsVidHorizSplitCall()
# void DPxEnableVidVertStereo()
# Top/bottom halves of input image are output in two sequencial video frames.
# VESA L/R output is set to 1 when first frame (left eye) is displayed,
# and set to 0 when second frame (right eye) is displayed.
_DPxEnableVidVertStereoCall= DPxDll['DPxEnableVidVertStereo']
_DPxEnableVidVertStereoCall.restype = None
[docs]def DPxEnableVidVertStereo():
""" Enables Vertical Stereo Video.
Top/bottom halves of input image are output in two sequencial video frames.
VESA L/R output is set to 1 when first frame (left eye) is displayed,
and set to 0 when second frame (right eye) is displayed.
:Low-level C definition:
``void DPxEnableVidVertStereo()``
"""
return _DPxEnableVidVertStereoCall()
# void DPxDisableVidVertStereo()
# Normal display
_DPxDisableVidVertStereoCall= DPxDll['DPxDisableVidVertStereo']
_DPxDisableVidVertStereoCall.restype = None
[docs]def DPxDisableVidVertStereo():
""" Disables the Video Vertical Stereo.
A normal display will be in this mode.
:Low-level C definition:
``void DPxDisableVidVertStereo()``
"""
return _DPxDisableVidVertStereoCall()
# void DPxAutoVidVertStereo()
# Vertical stereo is enabled automatically when vertical resolution > horizontal resolution (default mode)
_DPxAutoVidVertStereoCall = DPxDll['DPxAutoVidVertStereo']
_DPxAutoVidVertStereoCall.restype = None
[docs]def DPxAutoVidVertStereo():
""" Turns on the automatic mode for Video Vertical Stereo.
Vertical stereo is enabled automatically when vertical resolution > horizontal resolution (default mode)
:Low-level C definition:
``void DPxAutoVidVertStereo()``
"""
return _DPxAutoVidVertStereoCall()
# int DPxIsVidVertStereo()
# Returns non-0 if DATAPixx is separating input into sequencial left/right stereo images.
_DPxIsVidVertStereoCall = DPxDll['DPxIsVidVertStereo']
_DPxIsVidVertStereoCall.restype = ctypes.c_int
[docs]def DPxIsVidVertStereo():
"""Returns non-zero if DATAPixx is separating input into sequencial left/right stereo images.
:Low-level C definition:
``int DPxIsVidVertStereo()``
"""
return _DPxIsVidVertStereoCall()
# void DPxEnableVidHorizOverlay()
# VGA 1 and VGA 2 both show an overlay composite of the left/right halves of the video image
_DPxEnableVidHorizOverlayCall = DPxDll['DPxEnableVidHorizOverlay']
_DPxEnableVidHorizOverlayCall.restype = None
[docs]def DPxEnableVidHorizOverlay():
"""Enables the Horizontal overlay
VGA 1 and VGA 2 both show an overlay composite of the left/right halves of the video image
:Low-level C definition:
``void DPxEnableVidHorizOverlay()``
"""
return _DPxEnableVidHorizOverlayCall()
# void DPxDisableVidHorizOverlay()
# Horizontal overlay is disabled
_DPxDisableVidHorizOverlayCall = DPxDll['DPxDisableVidHorizOverlay']
_DPxDisableVidHorizOverlayCall.restype = None
[docs]def DPxDisableVidHorizOverlay():
"""Disables the Horizontal overlay.
:Low-level C definition:
``void DPxDisableVidHorizOverlay()``
"""
return _DPxDisableVidHorizOverlayCall()
# int DPxIsVidHorizOverlay()
# Returns non-0 if the left/right halves of the video image are being overlayed
_DPxIsVidHorizOverlayCall = DPxDll['DPxIsVidHorizOverlay']
_DPxIsVidHorizOverlayCall.restype = ctypes.c_int
[docs]def DPxIsVidHorizOverlay():
"""Verifies if the left/right halves of the video image are being overlayed
Returns:
Returns non-zero if the left/right halves of the video image are being overlayed, 0 otherwise.
:Low-level C definition:
``int DPxIsVidHorizOverlay()``
"""
return _DPxIsVidHorizOverlayCall()
# void DPxSetVidHorizOverlayBounds(int X1, int Y1, int X2, int Y2)
# Set bounding rectangle within left half image whose contents are composited with right half image
_DPxSetVidHorizOverlayBoundsCall = DPxDll['DPxSetVidHorizOverlayBounds']
_DPxSetVidHorizOverlayBoundsCall.argtypes = [ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int]
_DPxSetVidHorizOverlayBoundsCall.restype = None
[docs]def DPxSetVidHorizOverlayBounds(x1, y1, x2, y2):
"""Sets bounding rectangle within left half image whose contents are composited with right half image.
Args:
x1 (int): Bottom left x position.
y1 (int): Bottom left y position.
x2 (int): Top right x position.
y2 (int): Top right y position.
:Low-level C definition:
``void DPxSetVidHorizOverlayBounds(int X1, int Y1, int X2, int Y2)``
"""
return _DPxSetVidHorizOverlayBoundsCall(x1, y1, x2, y2)
# void DPxGetVidHorizOverlayBounds(int* X1, int* Y1, int* X2, int* Y2)
# Get bounding rectangle of horizontal overlay window
_DPxGetVidHorizOverlayBoundsCall = DPxDll['DPxGetVidHorizOverlayBounds']
_DPxGetVidHorizOverlayBoundsCall.restype = None
[docs]def DPxGetVidHorizOverlayBounds():
"""Gets the bounding rectangle of horizontal overlay window
Returns:
A tuple of the form (X1, Y1, X2, Y2)
:Low-level C definition:
``void DPxGetVidHorizOverlayBounds(int* X1, int* Y1, int* X2, int* Y2)``
"""
X1 = 0
X2 = 0
Y1 = 0
Y2 = 0
p_X1 = ctypes.c_int(X1)
p_X2 = ctypes.c_int(X2)
p_Y1 = ctypes.c_int(Y1)
p_Y2 = ctypes.c_int(Y2)
_DPxGetVidHorizOverlayBoundsCall(ctypes.byref(p_X1), ctypes.byref(p_Y1), ctypes.byref(p_X2), ctypes.byref(p_Y2))
return (p_X1.value, p_Y1.value, p_X2.value, p_Y2.value)
# void DPxSetVidHorizOverlayAlpha(UInt16* alphaData)
# Set 1024 16-bit video horizontal overlay alpha values, in order X0,X1..X511,Y0,Y1...Y511
_DPxSetVidHorizOverlayAlphaCall = DPxDll['DPxSetVidHorizOverlayAlpha']
_DPxSetVidHorizOverlayAlphaCall.restype = None
[docs]def DPxSetVidHorizOverlayAlpha(int_list):
"""Sets 1024 16-bit video horizontal overlay alpha values, in order X0,X1..X511,Y0,Y1...Y511.
Args:
int_list (list): A list of integers to set the overlay alpha values, defaults to all zeros
:Low-level C definition:
``void DPxSetVidHorizOverlayAlpha(UInt16* alphaData)``
"""
item_count = len(int_list)
packed_data = (ctypes.c_uint * item_count)(*int_list)
return _DPxSetVidHorizOverlayAlphaCall(packed_data)
# int DPxGetVidHTotal()
# Get number of video dot times in one horizontal scan line (includes horizontal blanking interval)
_DPxGetVidHTotalCall = DPxDll['DPxGetVidHTotal']
_DPxGetVidHTotalCall.restype = ctypes.c_int
[docs]def DPxGetVidHTotal():
"""Get the number of video dot times in one horizontal scan line (includes horizontal blanking interval)
:Low-level C definition:
``int DPxGetVidHTotal()``
"""
return _DPxGetVidHTotalCall()
# int DPxGetVidVTotal()
# Get number of video lines in one vertical frame (includes vertical blanking interval)
_DPxGetVidVTotalCall = DPxDll['DPxGetVidVTotal']
_DPxGetVidVTotalCall.restype = ctypes.c_int
[docs]def DPxGetVidVTotal():
"""Gets number of video lines in one vertical frame (includes vertical blanking interval)
:Low-level C definition:
``int DPxGetVidVTotal()``
"""
return _DPxGetVidVTotalCall()
# int DPxGetVidHActive()
# Get number of visible pixels in one horizontal scan line
_DPxGetVidHActiveCall = DPxDll['DPxGetVidHActive']
_DPxGetVidHActiveCall.restype = ctypes.c_int
[docs]def DPxGetVidHActive():
"""Gets the number of visible pixels in one horizontal scan line.
:Low-level C definition:
``int DPxGetVidHActive()``
"""
return _DPxGetVidHActiveCall()
# int DPxGetVidVActive()
# Get number of visible lines in one vertical frame
_DPxGetVidVActiveCall = DPxDll['DPxGetVidVActive']
_DPxGetVidVActiveCall.restype = ctypes.c_int
[docs]def DPxGetVidVActive():
"""Gets number of visible lines in one vertical frame.
:Low-level C definition:
``int DPxGetVidVActive()``
"""
return _DPxGetVidVActiveCall()
# unsigned DPxGetVidVPeriod()
# Get video vertical frame period in nanoseconds
_DPxGetVidVPeriodCall = DPxDll['DPxGetVidVPeriod']
_DPxGetVidVPeriodCall.restype = ctypes.c_uint
[docs]def DPxGetVidVPeriod():
"""Gets video vertical frame period in nanoseconds
The period is the inverse of the frequency.
:Low-level C definition:
``unsigned DPxGetVidVPeriod()``
"""
return _DPxGetVidVPeriodCall()
# double DPxGetVidVFreq()
# Get video vertical frame rate in Hz
_DPxGetVidVFreqCall = DPxDll['DPxGetVidVFreq']
_DPxGetVidVFreqCall.restype = ctypes.c_double
[docs]def DPxGetVidVFreq():
"""Gets video vertical line rate in Hz.
The vertical line rate in Hz, which represents the time taken for a whole vertical line to be switched on,
including the blanking time.
:Low-level C definition:
``double DPxGetVidVFreq()``
"""
return _DPxGetVidVFreqCall()
# double DPxGetVidHFreq()
# Get video horizontal line rate in Hz
_DPxGetVidHFreqCall = DPxDll['DPxGetVidHFreq']
_DPxGetVidHFreqCall.restype = ctypes.c_double
[docs]def DPxGetVidHFreq():
"""Gets the video horizontal line rate in Hz
The Horizontal line rate in Hz, which represents the time taken for a whole horizontal line to be switched on,
including the blanking time.
:Low-level C definition:
``double DPxGetVidHFreq()``
"""
return _DPxGetVidHFreqCall()
# double DPxGetVidDotFreq()
# Get video dot frequency in Hz
_DPxGetVidDotFreqCall = DPxDll['DPxGetVidDotFreq']
_DPxGetVidDotFreqCall.restype = ctypes.c_double
[docs]def DPxGetVidDotFreq():
""" Gets the dot frequency for the device in Hz.
The dot frequency represents the time taken for a pixel to be switched on.
It is calculated by considering all pixels (including those in blanking time) times the refresh rate.
:Low-level C definition:
``double DPxGetVidDotFreq()``
"""
return _DPxGetVidDotFreqCall()
# int DPxIsVidDviActive()
# Returns non-0 if DATAPixx is currently receiving video data over DVI link
_DPxIsVidDviActiveCall = DPxDll['DPxIsVidDviActive']
_DPxIsVidDviActiveCall.restype = ctypes.c_int
[docs]def DPxIsVidDviActive():
"""Returns non-zero if DATAPixx is currently receiving video data over DVI link
:Low-level C definition:
``int DPxIsVidDviActive()``
"""
return _DPxIsVidDviActiveCall()
# int DPxIsVidDviActiveDual()
# Returns non-zero if DATAPixx is currently receiving video data over dual-link DVI
_DPxIsVidDviActiveDualCall = DPxDll['DPxIsVidDviActiveDual']
_DPxIsVidDviActiveDualCall.restype = ctypes.c_int
[docs]def DPxIsVidDviActiveDual():
"""Returns non-zero if DATAPixx is currently receiving video data over dual-link DVI
:Low-level C definition:
``int DPxIsVidDviActiveDual()``
"""
return _DPxIsVidDviActiveDualCall()
# int DPxIsVidDviLockable()
# Returns non-zero if VIEWPixx is currently receiving video whose timing can directly drive display.
_DPxIsVidDviLockableCall = DPxDll['DPxIsVidDviLockable']
_DPxIsVidDviLockableCall.restype = ctypes.c_int
[docs]def DPxIsVidDviLockable():
"""Returns non-zero if VIEWPixx is currently receiving video whose timing can directly drive display.
:Low-level C definition:
``int DPxIsVidDviLockable()``
"""
return _DPxIsVidDviLockableCall()
# int DPxIsVidOverClocked()
# Returns non-zero if DATAPixx is receiving video at too high a clock frequency
_DPxIsVidOverClockedCall = DPxDll['DPxIsVidOverClocked']
_DPxIsVidOverClockedCall.restype = ctypes.c_int
[docs]def DPxIsVidOverClocked():
"""Returns non-zero if DATAPixx is receiving video at clock frequency that is higher than normal.
:Low-level C definition:
``int DPxIsVidOverClocked()``
"""
return _DPxIsVidOverClockedCall()
# void DPxSetVidVesaLeft()
# VESA connector outputs left-eye signal
_DPxSetVidVesaLeftCall = DPxDll['DPxSetVidVesaLeft']
_DPxSetVidVesaLeftCall.restype = None
[docs]def DPxSetVidVesaLeft():
"""VESA connector outputs left-eye signal.
:Low-level C definition:
``void DPxSetVidVesaLeft()``
"""
return _DPxSetVidVesaLeftCall()
_DPxSetVidVesaRightCall= DPxDll['DPxSetVidVesaRight']
_DPxSetVidVesaRightCall.restype = None
[docs]def DPxSetVidVesaRight():
"""VESA connector outputs right-eye signal.
:Low-level C definition:
``void DPxSetVidVesaRight()``
"""
return _DPxSetVidVesaRightCall()
# int DPxIsVidVesaLeft()
# Returns non-0 if VESA connector has left-eye signal
_DPxIsVidVesaLeftCall = DPxDll['DPxIsVidVesaLeft']
_DPxIsVidVesaLeftCall.restype = ctypes.c_int
[docs]def DPxIsVidVesaLeft():
"""Returns non-zero if VESA connector has left-eye signal
:Low-level C definition:
``int DPxIsVidVesaLeft()``
"""
return _DPxIsVidVesaLeftCall()
# void DPxEnableVidVesaBlueline()
# VESA 3D output interprets middle pixel on last raster line as a blueline code
_DPxEnableVidVesaBluelineCall = DPxDll['DPxEnableVidVesaBlueline']
_DPxEnableVidVesaBluelineCall.restype = None
[docs]def DPxEnableVidVesaBlueline():
"""Enables the Video blue line mode.
When enabled, the VESA 3D output interprets the middle pixel on last raster line as a blue line code.
When disabled, the VESA 3D output is not dependent on video content.
:Low-level C definition:
``void DPxEnableVidVesaBlueline()``
"""
return _DPxEnableVidVesaBluelineCall()
# void DPxDisableVidVesaBlueline()
# VESA 3D output is not dependent on video content
_DPxDisableVidVesaBluelineCall= DPxDll['DPxDisableVidVesaBlueline']
_DPxDisableVidVesaBluelineCall.restype = None
[docs]def DPxDisableVidVesaBlueline():
"""Disables the Video blue line mode.
When enabled, the VESA 3D output interprets the middle pixel on last raster line as a blue line code.
When disabled, the VESA 3D output is not dependent on video content.
:Low-level C definition:
``void DPxDisableVidVesaBlueline()``
"""
return _DPxDisableVidVesaBluelineCall()
# int DPxIsVidVesaBlueline()
# Returns non-zero if VESA 3D output is dependent on video blueline codes
_DPxIsVidVesaBluelineCall = DPxDll['DPxIsVidVesaBlueline']
_DPxIsVidVesaBluelineCall.restype = ctypes.c_int
[docs]def DPxIsVidVesaBlueline():
"""Returns non-zero if VESA 3D output is dependent on video blueline codes
:Low-level C definition:
``int DPxIsVidVesaBlueline()``
"""
return _DPxIsVidVesaBluelineCall()
_DPxSetVidVesaWaveformCall = DPxDll['DPxSetVidVesaWaveform']
_DPxSetVidVesaWaveformCall.argtypes = [ctypes.c_int]
_DPxSetVidVesaWaveformCall.restype = None
_DPxGetVidVesaWaveformCall = DPxDll['DPxGetVidVesaWaveform']
_DPxGetVidVesaWaveformCall.restype = ctypes.c_int
# void DPxSetVidVesaPhase(int phase)
# Set the 8-bit unsigned phase of the VESA 3D waveform
# Varying this phase from 0-255 will fine tune phase relationship between stereo video and 3D goggle switching
# The following combinations have been found to work well:
# Waveform=DPXREG_VID_VESA_WAVEFORM_NVIDIA, Phase=100, for VIEWPixx/3D + scanning backlight + 3DPixx IR emitter + NVIDIA 3D Vision glasses
# Waveform=DPXREG_VID_VESA_WAVEFORM_NVIDIA, Phase=245, for DATAPixx + CRT + 3DPixx IR emitter + NVIDIA 3D Vision glasses
# Waveform=DPXREG_VID_VESA_WAVEFORM_CRYSTALEYES, Phase=100, for VIEWPixx/3D + scanning backlight + 3DPixx IR emitter + CrystalEyes glasses
_DPxSetVidVesaPhaseCall = DPxDll['DPxSetVidVesaPhase']
_DPxSetVidVesaPhaseCall.argtypes = [ctypes.c_int]
_DPxSetVidVesaPhaseCall.restype = None
[docs]def DPxSetVidVesaPhase(phase):
"""Sets the 8-bit unsigned phase of the VESA 3D waveform.
Varying this phase from 0-255, allows adjustements to the phase relationship between stereo video and 3D goggles switching.
The following combinations have been found to work well:
If you are using a VIEWPIxx/3D, you should set the ``phase`` to ``0x64`` for 3DPixx or ``0x64`` for Volfoni. If you
are using a CTR with our DATAPixx, it should be set to ``0xF5``.
Args:
phase (int): Phase of the VESA 3D waveform
:Low-level C definition:
``void DPxSetVidVesaPhase(int phase)``
"""
return _DPxSetVidVesaPhaseCall(phase)
# int DPxGetVidVesaPhase()
# Get the 8-bit unsigned phase of the VESA 3D waveform
_DPxGetVidVesaPhaseCall = DPxDll['DPxGetVidVesaPhase']
_DPxGetVidVesaPhaseCall.restype = ctypes.c_int
[docs]def DPxGetVidVesaPhase():
"""Gets the 8 bits unsigned phase of the VESA 3D waveform.
Returns:
phase (int): Phase of the VESA 3D waveform.
:Low-level C definition:
``int DPxGetVidVesaPhase()``
"""
return _DPxGetVidVesaPhaseCall()
_DPxGetVidLineCall = DPxDll['DPxGetVidLine']
_DPxGetVidLineCall.restype = ctypes.POINTER( ctypes.c_ushort )
[docs]def DPxGetVidLine(Hex = False):
"""
Reads pixels from the VPixx device line buffer, and returns a list containing the data.
For each pixel, the buffer contains 16 bits R/G/B/U (where U is thrown away). The returned data is a list
containing three lists for the respective R/G/B colors.
Args:
Hex (bool, optional): True returns the value in hexadecimal. Everything else will return the value in decimal.
Return:
lists of list: A list which has [[RED], [GREEN], [BLUE]]
:Low-level C definition:
``short* DPxGetVidLine()``
"""
p_value = _DPxGetVidLineCall()
pixel_values = [[],[],[]]
for pixel_number in range(1920):
pixel_values[0].append(p_value[4*pixel_number] >> 8) # R
pixel_values[1].append(p_value[4*pixel_number + 1]>> 8) # G
pixel_values[2].append(p_value[4*pixel_number + 2]>> 8) # B
return pixel_values
# void DPxSetVidPsyncRasterLine(int line)
# Set the raster line on which pixel sync sequence is expected
_DPxSetVidPsyncRasterLineCall = DPxDll['DPxSetVidPsyncRasterLine']
_DPxSetVidPsyncRasterLineCall.argtypes = [ctypes.c_int]
_DPxSetVidPsyncRasterLineCall.restype = None
[docs]def DPxSetVidPsyncRasterLine(line):
"""Sets the raster line on which the pixel sync sequence is expected.
Args:
line (int): The line which will contain de PSync.
:Low-level C definition:
``void DPxSetVidPsyncRasterLine(int line)``
"""
return _DPxSetVidPsyncRasterLineCall(line)
# int DPxGetVidPsyncRasterLine()
# Get the raster line on which pixel sync sequence is expected
_DPxGetVidPsyncRasterLineCall = DPxDll['DPxGetVidPsyncRasterLine']
_DPxGetVidPsyncRasterLineCall.restype = ctypes.c_int
[docs]def DPxGetVidPsyncRasterLine():
"""Gets the raster line on which pixel sync sequence is expected.
Returns:
An integer which represents the line which has the PSync.
:Low-level C definition:
``int DPxGetVidPsyncRasterLine()``
"""
return _DPxGetVidPsyncRasterLineCall()
# void DPxEnableVidPsyncSingleLine()
# Pixel sync is only recognized on a single raster line
_DPxEnableVidPsyncSingleLineCall= DPxDll['DPxEnableVidPsyncSingleLine']
_DPxEnableVidPsyncSingleLineCall.restype = None
[docs]def DPxEnableVidPsyncSingleLine():
"""Enables Psync for Single (Raster) Line.
:Low-level C definition:
``void DPxEnableVidPsyncSingleLine()``
"""
return _DPxEnableVidPsyncSingleLineCall()
# void DPxDisableVidPsyncSingleLine()
# Pixel sync is recognized on any raster line
_DPxDisableVidPsyncSingleLineCall= DPxDll['DPxDisableVidPsyncSingleLine']
_DPxDisableVidPsyncSingleLineCall.restype = None
[docs]def DPxDisableVidPsyncSingleLine():
"""Disables Psync for Single (Raster) Line.
:Low-level C definition:
``void DPxDisableVidPsyncSingleLine()``
"""
return _DPxDisableVidPsyncSingleLineCall()
# int DPxIsVidPsyncSingleLine()
# Returns non-zero if pixel sync is only recognized on a single raster line
_DPxIsVidPsyncSingleLineCall = DPxDll['DPxIsVidPsyncSingleLine']
_DPxIsVidPsyncSingleLineCall.restype = ctypes.c_int
[docs]def DPxIsVidPsyncSingleLine():
""" Returns non-zero if pixel sync is only recognized on a single raster line.
:Low-level C definition:
``int DPxIsVidPsyncSingleLine()``
"""
return _DPxIsVidPsyncSingleLineCall()
# void DPxEnableVidPsyncBlankLine()
# Pixel sync raster line is always displayed black
_DPxEnableVidPsyncBlankLineCall= DPxDll['DPxEnableVidPsyncBlankLine']
_DPxEnableVidPsyncBlankLineCall.restype = None
[docs]def DPxEnableVidPsyncBlankLine():
"""Enables the PSync Black Line
The sync raster line is always displayed black.
:Low-level C definition:
``void DPxEnableVidPsyncBlankLine()``
"""
return _DPxEnableVidPsyncBlankLineCall()
# void DPxDisableVidPsyncBlankLine()
# Pixel sync raster line is displayed normally
_DPxDisableVidPsyncBlankLineCall= DPxDll['DPxDisableVidPsyncBlankLine']
_DPxDisableVidPsyncBlankLineCall.restype = None
[docs]def DPxDisableVidPsyncBlankLine():
"""Disables the PSync Blank Line.
Pixel sync raster line is displayed normally when this is disabled.
:Low-level C definition:
``void DPxDisableVidPsyncBlankLine()``
"""
return _DPxDisableVidPsyncBlankLineCall()
# int DPxIsVidPsyncBlankLine()
# Returns non-zero if pixel sync raster line is always displayed black
_DPxIsVidPsyncBlankLineCall = DPxDll['DPxIsVidPsyncBlankLine']
_DPxIsVidPsyncBlankLineCall.restype = ctypes.c_int
[docs]def DPxIsVidPsyncBlankLine():
"""Returns non-zero if pixel sync raster line is always displayed black
:Low-level C definition:
``int DPxIsVidPsyncBlankLine()``
"""
return _DPxIsVidPsyncBlankLineCall()
# void DPxSetVidSource(int vidSource)
# Set source of video pattern to be displayed
_DPxSetVidSourceCall = DPxDll['DPxSetVidSource']
_DPxSetVidSourceCall.argtypes = [ctypes.c_int]
_DPxSetVidSourceCall.restype = None
[docs]def DPxSetVidSource(vidSource):
"""Sets the source of video to be displayed.
Args:
vidSource (str): The source we want to display.
- **DVI**: Monitor displays DVI signal.
- **SWTP**: Software test pattern showing image from RAM.
- **SWTP 3D**: 3D Software test pattern flipping between left/right eye images from RAM.
- **RGB SQUARES**: RGB ramps.
- **GRAY**: Uniform gray display having 12-bit intensity.
- **BAR**: Drifting bar.
- **BAR2**: Drifting bar.
- **DOTS**: Drifting dots.
- **RAMP**: Drifting ramp, with dots advancing ``x*2`` pixels per video frame, where ``x`` is a 4-bit signed.
- **RGB**: Uniform display with 8-bit intensity nn, send to RGBA channels enabled by mask m.
- **PROJ**: Projector Hardware test pattern.
:Low-level C definition:
``void DPxSetVidSource(int vidSource)``
"""
if type(vidSource) is str:
_DPxSetVidSourceCall(test_pattern_constants[vidSource.upper()])
else:
_DPxSetVidSourceCall(vidSource)
# int DPxGetVidSource()
# Get source of video pattern being displayed
_DPxGetVidSourceCall = DPxDll['DPxGetVidSource']
_DPxGetVidSourceCall.restype = ctypes.c_int
[docs]def DPxGetVidSource(return_str=False):
"""Gets source of video being displayed.
Args:
return_str (Bool): When True, the return value is a string describing the video source used. Else, an integer is returned.
Returns:
vidSource (str): The source currently displayed.
- **DVI**: Monitor displays DVI signal.
- **SWTP**: Software test pattern showing image from RAM.
- **SWTP 3D**: 3D Software test pattern flipping between left/right eye images from RAM.
- **RGB SQUARES**: RGB ramps.
- **GRAY**: Uniform gray display having 12-bit intensity.
- **BAR**: Drifting bar.
- **BAR2**: Drifting bar.
- **DOTS**: Drifting dots.
- **RAMP**: Drifting ramp, with dots advancing ``x*2`` pixels per video frame, where ``x`` is a 4-bit signed.
- **RGB**: Uniform display with 8-bit intensity nn, send to RGBA channels enabled by mask m.
- **PROJ**: Projector Hardware test pattern.
:Low-level C definition:
``int DPxGetVidSource()``
"""
temp = _DPxGetVidSourceCall()
vidSource = temp
if return_str == True:
vidSource = 'none'#In case we can't find the associated key.
for key, value in test_pattern_constants.items():
if temp == 0:
vidSource = 'DVI'
break
elif value == temp:
vidSource = key
break
return vidSource
# void DPxEnableVidScanningBacklight()
# Enable VIEWPixx scanning backlight
_DPxEnableVidScanningBacklightCall = DPxDll['DPxEnableVidScanningBacklight']
_DPxEnableVidScanningBacklightCall.restype = None
[docs]def DPxEnableVidScanningBacklight():
"""Enables VIEWPixx scanning backlight
:Low-level C definition:
``void DPxEnableVidScanningBacklight()``
"""
return _DPxEnableVidScanningBacklightCall()
# void DPxDisableVidScanningBacklight()
# Disable VIEWPixx scanning backlight
_DPxDisableVidScanningBacklightCall = DPxDll['DPxDisableVidScanningBacklight']
_DPxDisableVidScanningBacklightCall.restype = None
[docs]def DPxDisableVidScanningBacklight():
"""Disables VIEWPixx scanning backlight.
:Low-level C definition:
``void DPxDisableVidScanningBacklight()``
"""
return _DPxDisableVidScanningBacklightCall()
# void DPxEnableVidRescanWarning()
# Enable VIEWPixx Rescan Warning
_DPxEnableVidRescanWarningCall = DPxDll['DPxEnableVidRescanWarning']
_DPxEnableVidRescanWarningCall.restype = None
[docs]def DPxEnableVidRescanWarning():
"""Enables VIEWPixx Rescan Warning
:Low-level C definition:
``void DPxEnableVidRescanWarning()``
"""
return _DPxEnableVidRescanWarningCall()
# void DPxDisableVidScanningBacklight()
# Disable VIEWPixx scanning backlight
_DPxDisableVidRescanWarningCall = DPxDll['DPxDisableVidRescanWarning']
_DPxDisableVidRescanWarningCall.restype = None
[docs]def DPxDisableVidRescanWarning():
"""Disables VIEWPixx Rescan Warning.
:Low-level C definition:
``void DPxDisableVidRescanWarning()``
"""
return _DPxDisableVidRescanWarningCall()
# int DPxIsVidScanningBacklight()
# Returns non-zero if VIEWPixx scanning backlight is enabled
_DPxIsVidScanningBacklightCall = DPxDll['DPxIsVidScanningBacklight']
_DPxIsVidScanningBacklightCall.restype = ctypes.c_int
[docs]def DPxIsVidScanningBacklight():
"""Returns non-zero if VIEWPixx scanning backlight is enabled
:Low-level C definition:
``int DPxIsVidScanningBacklight()``
"""
return _DPxIsVidScanningBacklightCall()
# int DPxIsPPxVidSeqEnabled(void)
_DPxIsPPxVidSeqEnabledCall = DPxDll['DPxIsPPxVidSeqEnabled']
_DPxIsPPxVidSeqEnabledCall.restype = ctypes.c_int
[docs]def DPxIsPPxVidSeqEnabled():
"""Checks to see if the PROPixx Video Sequencer is enabled.
Returns:
int: 0 (False) if the PROPixx Video Sequencer is Disabled, 1 (True) if Enabled.
:Low-level C definition:
``int DPxIsPPxVidSeqEnabled(void)``
"""
return _DPxIsPPxVidSeqEnabledCall()
# double DPxGetPPxVoltageMonitor(int voltageNum)
_DPxGetPPxVoltageMonitorCall = DPxDll['DPxGetPPxVoltageMonitor']
_DPxGetPPxVoltageMonitorCall.restype = ctypes.c_double
_DPxGetPPxVoltageMonitorCall.argtypes = [ctypes.c_int]
[docs]def DPxGetPPxVoltageMonitor(voltageNum):
"""Gets the Voltage for the given sensor.
Args:
voltageNum (int): The number of the sensor.
Returns:
double: The volatage in Volts for the chosen monitor.
:Low-level C definition:
``double DPxGetPPxVoltageMonitor(int voltageNum)``
"""
return _DPxGetPPxVoltageMonitorCall(voltageNum)
# double DPxGetPPxTemperature(int tempNum)
_DPxGetPPxTemperatureCall = DPxDll['DPxGetPPxTemperature']
_DPxGetPPxTemperatureCall.restype = ctypes.c_double
_DPxGetPPxTemperatureCall.argtypes = [ctypes.c_int]
[docs]def DPxGetPPxTemperature(tempNum):
"""Get a PROPixx temperature for a given sensor number.
Args:
tempNum (int): Number of the sensor.
Returns
double: The temperature in Celcius of the sensor.
:Low-level C definition:
``double DPxGetPPxTemperature(int tempNum)``
"""
return _DPxGetPPxTemperatureCall(tempNum)
# double DPxGetPPxLedCurrent(int ledNum)
_DPxGetPPxLedCurrentCall = DPxDll['DPxGetPPxLedCurrent']
_DPxGetPPxLedCurrentCall.restype = ctypes.c_double
_DPxGetPPxLedCurrentCall.argtypes = [ctypes.c_int]
[docs]def DPxGetPPxLedCurrent(ledNum):
"""Get PROPixx LED Current.
Args:
ledNum (int): The number of the LED.
Returns:
double: The value of the current of the selected LED as a double in Amps.
:Low-level C definition:
``double DPxGetPPxLedCurrent(int ledNum)``
"""
return _DPxGetPPxLedCurrentCall(ledNum)
# void DPxSetPPxLedCurrent(int ledNum, double current);
_DPxSetPPxLedCurrentCall = DPxDll['DPxSetPPxLedCurrent']
_DPxSetPPxLedCurrentCall.argtypes = [ctypes.c_int, ctypes.c_double]
def DPxSetPPxLedCurrent(ledNum, current):
return _DPxSetPPxLedCurrentCall(ledNum, current)
# double DPxGetPPxFanTachometer(int fanNum)
_DPxGetPPxFanTachometerCall = DPxDll['DPxGetPPxFanTachometer']
_DPxGetPPxFanTachometerCall.restype = ctypes.c_double
_DPxGetPPxFanTachometerCall.argtypes = [ctypes.c_int]
[docs]def DPxGetPPxFanTachometer(fanNum):
""" Returns the speed at which a fan is rotating.
Args:
fanNum(int): The number of the fan.
:Low-level C definition:
``double DPxGetPPxFanTachometer(int fanNum)``
"""
return _DPxGetPPxFanTachometerCall(fanNum)
# double DPxGetPPxFanPwm(void)
_DPxGetPPxFanPwmCall = DPxDll['DPxGetPPxFanPwm']
_DPxGetPPxFanPwmCall.restype = ctypes.c_double
[docs]def DPxGetPPxFanPwm():
""" Returns the Fans PWN.
Return:
double: Current fan PWN as a double.
:Low-level C definition:
``double DPxGetPPxFanPwm(void)``
"""
return _DPxGetPPxFanPwmCall()
# void DPxEnablePPxCeilingMount(void)
_DPxEnablePPxCeilingMountCall = DPxDll['DPxEnablePPxCeilingMount']
_DPxEnablePPxCeilingMountCall.restype = None
[docs]def DPxEnablePPxCeilingMount():
"""Enables the PROPixx Ceiling Mount mode.
:Low-level C definition:
``void DPxEnablePPxCeilingMount(void)``
"""
return _DPxEnablePPxCeilingMountCall()
# void DPxDisablePPxCeilingMount(void)
_DPxDisablePPxCeilingMountCall = DPxDll['DPxDisablePPxCeilingMount']
_DPxDisablePPxCeilingMountCall.restype = None
[docs]def DPxDisablePPxCeilingMount():
"""Disables the PROPixx Ceiling Mount mode.
:Low-level C definition:
``void DPxDisablePPxCeilingMount(void)``
"""
return _DPxDisablePPxCeilingMountCall()
# int DPxIsPPxCeilingMount(void)
_DPxIsPPxCeilingMountCall = DPxDll['DPxIsPPxCeilingMount']
_DPxIsPPxCeilingMountCall.restype = ctypes.c_int
[docs]def DPxIsPPxCeilingMount():
"""Check to see if the PROPixx is in Ceiling Mount mode.
Returns:
int: 0 (False) if the PROPixx is not in Ceiling Mount mode, 1 (True) otherwise.
:Low-level C definition:
``int DPxIsPPxCeilingMount(void)``
"""
return _DPxIsPPxCeilingMountCall()
# void DPxEnablePPxRearProjection(void)
_DPxEnablePPxRearProjectionCall = DPxDll['DPxEnablePPxRearProjection']
_DPxEnablePPxRearProjectionCall.restype = None
[docs]def DPxEnablePPxRearProjection():
""" Enables the Rear Projection of the PROPixx.
:Low-level C definition:
``void DPxEnablePPxRearProjection(void)``
"""
return _DPxEnablePPxRearProjectionCall()
# void DPxDisablePPxRearProjection(void)
_DPxDisablePPxRearProjectionCall = DPxDll['DPxDisablePPxRearProjection']
_DPxDisablePPxRearProjectionCall.restype = None
[docs]def DPxDisablePPxRearProjection():
"""Disables the Rear Projection of the PROPixx.
:Low-level C definition:
``void DPxDisablePPxRearProjection(void)``
"""
return _DPxDisablePPxRearProjectionCall()
# int DPxIsPPxRearProjection(void)
_DPxIsPPxRearProjectionCall = DPxDll['DPxIsPPxRearProjection']
_DPxIsPPxRearProjectionCall.restype = ctypes.c_int
[docs]def DPxIsPPxRearProjection():
"""Check to see if the PROPixx is in Rear projection
Returns:
int: 0 (False) if the PROPixx is not in rear projection, 1 (True) otherwise.
:Low-level C definition:
``int DPxIsPPxRearProjection(void)``
"""
return _DPxIsPPxRearProjectionCall()
# void DPxSetPPx3dCrosstalk(double crosstalk)
# Set 3D crosstalk (0-1) which should be subtracted from stereoscopic stimuli
_DPxSetPPx3dCrosstalkCall = DPxDll['DPxSetPPx3dCrosstalk']
_DPxSetPPx3dCrosstalkCall.argtypes = [ctypes.c_double]
_DPxSetPPx3dCrosstalkCall.restype = None
[docs]def DPxSetPPx3dCrosstalk(crosstalk):
"""Sets the 3D crosstalk (0-1) which should be subtracted from stereoscopic stimuli.
Note:
This only works with RB3D mode and requires revision 6 of the PROPixx.
Args:
crosstalk (double): A value between 0 and 1 which represents the 3d crosstalk.
:Low-level C definition:
``void DPxSetPPx3dCrosstalk(double crosstalk)``
"""
return _DPxSetPPx3dCrosstalkCall(crosstalk)
# double DPxGetPPx3dCrosstalk(void)
# Get 3D crosstalk (0-1) which is being subtracted from stereoscopic stimuli
_DPxGetPPx3dCrosstalkCall = DPxDll['DPxGetPPx3dCrosstalk']
_DPxGetPPx3dCrosstalkCall.restype = ctypes.c_double
[docs]def DPxGetPPx3dCrosstalk():
"""Gets 3D crosstalk (0-1) which is being subtracted from stereoscopic stimuli.
Warning:
This only works with RB3D mode and requires revision 6 of the PROPixx.
Returns:
double: Value for the 3D Crosstalk.
:Low-level C definition:
``double DPxGetPPx3dCrosstalk(void)``
"""
return _DPxGetPPx3dCrosstalkCall()
#void DPxSetPPxDlpSeqPgrm(int program)
_DPxSetPPxDlpSeqPgrmCall = DPxDll['DPxSetPPxDlpSeqPgrm']
_DPxSetPPxDlpSeqPgrmCall.argtypes = [ctypes.c_int]
_DPxSetPPxDlpSeqPgrmCall.restype = None
[docs]def DPxSetPPxDlpSeqPgrm(program):
"""Sets the PROPixx DLP Sequencer program.
Note:
Only available for PROPixx Revision 6 and higher.
Args:
String : Any of the following predefined constants.
- **RGB**: Default RGB
- **RB3D**: R/B channels drive grayscale 3D
- **RGB240**: Only show the frame for 1/2 a 120 Hz frame duration.
- **RGB180**: Only show the frame for 2/3 of a 120 Hz frame duration.
- **QUAD4X**: Display quadrants are projected at 4x refresh rate.
- **QUAD12X**: Display quadrants are projected at 12x refresh rate with grayscales.
- **GREY3X**: Converts 640x1080@360Hz RGB to 1920x1080@720Hz Grayscale with blank frames.
- **RGB2**: Older RGB Sequencer.
:Low-level C definition:
``void DPxSetPPxDlpSeqPgrm(int program)``
"""
if program in propixx_sequencer_constants.values():
seq = list(propixx_sequencer_constants.keys())[list(propixx_sequencer_constants.values()).index(program)]
else:
seq = list(propixx_sequencer_constants2.keys())[list(propixx_sequencer_constants2.values()).index(program)]
_DPxSetPPxDlpSeqPgrmCall(int(seq))
#int DPxGetPPxDlpSeqPgrm(void)
_DPxGetPPxDlpSeqPgrmCall = DPxDll['DPxGetPPxDlpSeqPgrm']
_DPxGetPPxDlpSeqPgrmCall.restype = ctypes.c_int
[docs]def DPxGetPPxDlpSeqPgrm():
"""Get PROPixx DLP Sequencer program.
This method returns the current program loaded in the PROPixx sequencer.
Returns:
String: Any of the following predefined constants.
- **RGB**: Default RGB
- **RB3D**: R/B channels drive grayscale 3D
- **RGB240**: Only show the frame for 1/2 a 120 Hz frame duration.
- **RGB180**: Only show the frame for 2/3 of a 120 Hz frame duration.
- **QUAD4X**: Display quadrants are projected at 4x refresh rate.
- **QUAD12X**: Display quadrants are projected at 12x refresh rate with grayscales.
- **GREY3X**: Converts 640x1080@360Hz RGB to 1920x1080@720Hz Grayscale with blank frames.
:Low-level C definition:
``int DPxGetPPxDlpSeqPgrm(void)``
"""
return propixx_sequencer_constants[ _DPxGetPPxDlpSeqPgrmCall() ]
#void DPxSetPPxDefaultLedCurrents(void);
_DPxSetPPxDefaultLedCurrentsCall = DPxDll['DPxSetPPxDefaultLedCurrents']
_DPxSetPPxDefaultLedCurrentsCall.restype = None
[docs]def DPxSetPPxDefaultLedCurrents():
""" Set PROPixx default current depending on sequence or T-Scope
:Low-level C definition:
``void DPxSetPPxDefaultLedCurrents(void)``
"""
_DPxSetPPxDefaultLedCurrentsCall()
#void DPxSetPPxRgbCustomLedCurrents(int index);
_DPxSetPPxRgbCustomLedCurrentsCall = DPxDll['DPxSetPPxRgbCustomLedCurrents']
_DPxSetPPxRgbCustomLedCurrentsCall.restype = None
_DPxSetPPxRgbCustomLedCurrentsCall.argtypes = [ctypes.c_int]
[docs]def DPxSetPPxRgbCustomLedCurrents(index):
""" Set LED custom LED currents for RGB sequencer
This method takes the 0 based index of the calibration to apply.
Two calibrations are available:
- index = 0 : Custom RGB #1 (default)
- index = 1 : Custom RGB #2
"""
if index > 1 or index < 0:
index = 0
_DPxSetPPxRgbCustomLedCurrentsCall(index)
#void DPxSetPPxGreyLedCurrents(int index);
_DPxSetPPxGreyLedCurrentsCall = DPxDll['DPxSetPPxGreyLedCurrents']
_DPxSetPPxGreyLedCurrentsCall.restype = None
_DPxSetPPxGreyLedCurrentsCall.argtypes = [ctypes.c_int]
[docs]def DPxSetPPxGreyLedCurrents(index):
""" Set LED calibrated LED currents for grey sequencer
This method takes the 0 based index of the calibration to apply.
Two calibrations are available:
- index = 0 : Greyscale #1 (default)
- index = 1 : Greyscale #2
"""
if index > 1 or index < 0:
index = 0
_DPxSetPPxGreyLedCurrentsCall(index)
#void DPxSetPPxLedMask(int mask)
_DPxSetPPxLedMaskCall = DPxDll['DPxSetPPxLedMask']
_DPxSetPPxLedMaskCall.argtypes = [ctypes.c_int]
_DPxSetPPxLedMaskCall.restype = None
[docs]def DPxSetPPxLedMask(mask):
"""Sets the PROPixx mask to turn off specific LEDs.
Only available for PROPixx Revision 33 and higher.
Args:
Int : Any of the following predefined constants.
- **0**: All LEDs are on.
- **1**: RED is turned off.
- **2**: GREEN is turned off.
- **3**: RED and GREEN are turned off.
- **4**: BLUE is turned off.
- **5**: RED and BLUE are turned off.
- **6**: BLUE and GREEN are turned off.
- **7**: ALL LEDs are off.
:Low-level C definition:
``void DPxSetPPxLedMask(int mask)``
"""
_DPxSetPPxLedMaskCall(mask)
#int DPxGetPPxDlpSeqPgrm()
_DPxGetPPxLedMaskCall = DPxDll['DPxGetPPxLedMask']
_DPxGetPPxLedMaskCall.restype = ctypes.c_int
[docs]def DPxGetPPxLedMask():
"""Get the PROPixx LED mask.
Only available for PROPixx Revision 33 and higher.
Returns:
Int : Any of the following number.
- **0**: All LEDs are on.
- **1**: RED is turned off.
- **2**: GREEN is turned off.
- **3**: RED and GREEN are turned off.
- **4**: BLUE is turned off.
- **5**: RED and BLUE are turned off.
- **6**: BLUE and GREEN are turned off.
- **7**: ALL LEDs are off.
:Low-level C definition:
``int DPxGetPPxDlpSeqPgrm()``
"""
return _DPxGetPPxLedMaskCall()
# void DPxEnablePPxLampLed(void)
_DPxEnablePPxLampLedCall = DPxDll['DPxEnablePPxLampLed']
_DPxEnablePPxLampLedCall.restype = None
[docs]def DPxEnablePPxLampLed():
""" Enables the lamp LED of the PROPixx.
Note:
Only available for PROPixx Revision 12 and higher.
:Low-level C definition:
``void DPxEnablePPxLampLed(void)``
"""
return _DPxEnablePPxLampLedCall()
# void DPxDisablePPxLampLed(void)
_DPxDisablePPxLampLedCall = DPxDll['DPxDisablePPxLampLed']
_DPxDisablePPxLampLedCall.restype = None
[docs]def DPxDisablePPxLampLed():
"""Disables the lamp LED of the PROPixx.
Note:
Only available for PROPixx Revision 12 and higher.
:Low-level C definition:
``void DPxDisablePPxLampLed(void)``
"""
return _DPxDisablePPxLampLedCall()
# int DPxIsPPxLampLedEnabled(void)
_DPxIsPPxLampLedEnabledCall = DPxDll['DPxIsPPxLampLedEnabled']
_DPxIsPPxLampLedEnabledCall.restype = ctypes.c_int
[docs]def DPxIsPPxLampLedEnabled():
"""Check to see if the PROPixx lamp LED is enabled.
Note:
Only available for PROPixx Revision 12 and higher.
Returns:
0 (False) if the PROPixx lamp LED is disabled, 1 (True) otherwise.
:Low-level C definition:
``int DPxIsPPxLampLedEnabled(void)``
"""
return _DPxIsPPxLampLedEnabledCall()
# void DPxEnablePPxQuietFanMode(void)
_DPxEnablePPxQuietFanModeCall = DPxDll['DPxEnablePPxQuietFanMode']
_DPxEnablePPxQuietFanModeCall.restype = None
[docs]def DPxEnablePPxQuietFanMode():
""" Enables the quiet fan mode on the PROPixx.
Enabling this mode reduces the speed of the fans to reduce noise.
Note:
Only available for PROPixx Revision 19 and higher.
:Low-level C definition:
``void DPxEnablePPxQuietFanMode(void)``
"""
return _DPxEnablePPxQuietFanModeCall()
# void DPxDisablePPxQuietFanMode(void)
_DPxDisablePPxQuietFanModeCall = DPxDll['DPxDisablePPxQuietFanMode']
_DPxDisablePPxQuietFanModeCall.restype = None
[docs]def DPxDisablePPxQuietFanMode():
"""Disables the quiet fan mode on the PROPixx.
Disabling this mode sets the fans to maximum speed, thus increasing the noise produced by them.
Note:
Only available for PROPixx Revision 19 and higher.
:Low-level C definition:
``void DPxDisablePPxQuietFanMode(void)``
"""
return _DPxDisablePPxQuietFanModeCall()
# int DPxIsPPxQuietFanMode(void)
_DPxIsPPxQuietFanModeCall = DPxDll['DPxIsPPxQuietFanMode']
_DPxIsPPxQuietFanModeCall.restype = ctypes.c_int
[docs]def DPxIsPPxQuietFanMode():
"""Check to see if the PROPixx quiet mode is enabled.
Note:
Only available for PROPixx Revision 19 and higher.
Returns:
0 (False) if the PROPixx quiet mode is disabled, 1 (True) otherwise.
:Low-level C definition:
``int DPxIsPPxQuietFanMode(void)``
"""
return _DPxIsPPxQuietFanModeCall()
#void DPxSetPPxAwake()
_DPxSetPPxAwakeCall = DPxDll['DPxSetPPxAwake']
_DPxSetPPxAwakeCall.restype = None
[docs]def DPxSetPPxAwake():
"""Turns on the PROPixx.
Note:
Only available for PROPixx Revision 12 and higher.
:Low-level C definition:
``void DPxSetPPxAwake()``
"""
_DPxSetPPxAwakeCall()
#void DPxSetPPxSleep()
_DPxSetPPxSleepCall = DPxDll['DPxSetPPxSleep']
_DPxSetPPxSleepCall.restype = None
[docs]def DPxSetPPxSleep():
"""Turns off the PROPixx.
Note:
Only available for PROPixx Revision 12 and higher.
:Low-level C definition:
``void DPxSetPPxSleep()``
"""
_DPxSetPPxSleepCall()
# int DPxIsPPxAwake(void)
_DPxIsPPxAwakeCall = DPxDll['DPxIsPPxAwake']
_DPxIsPPxAwakeCall.restype = ctypes.c_int
[docs]def DPxIsPPxAwake():
"""Check to see if the PROPixx is awake.
Returns:
0 (False) if the PROPixx is in sleep mode, 1 (True) otherwise.
:Low-level C definition:
``int DPxIsPPxAwake(void)``
"""
return _DPxIsPPxAwakeCall()
#void DPxSetTPxAwake()
_DPxSetTPxAwakeCall = DPxDll['TPxSetAwakePictureRequest']
_DPxSetTPxAwakeCall.restype = None
[docs]def DPxSetTPxAwake():
"""Turns on the TRACKPixx.
:Low-level C definition:
``void DPxSetTPxAwake()``
"""
_DPxSetTPxAwakeCall()
#void DPxSetTPxSleep()
_DPxSetTPxSleepCall = DPxDll['TPxSetSleepPictureRequest']
_DPxSetTPxSleepCall.restype = None
[docs]def DPxSetTPxSleep():
"""Turns off the TRACKPixx.
:Low-level C definition:
``void DPxSetTPxSleep()``
"""
_DPxSetTPxSleepCall()
# int TPxIsPPxAwake(void)
_DPxIsTPxAwakeCall = DPxDll['TPxIsAwakePictureRequest']
_DPxIsTPxAwakeCall.restype = ctypes.c_int
[docs]def DPxIsTPxAwake():
"""Check to see if the PROPixx is awake.
Returns:
0 (False) if the PROPixx is in sleep mode, 1 (True) otherwise.
:Low-level C definition:
``int DPxIsPPxAwake(void)``
"""
return _DPxIsTPxAwakeCall()
#Private exported function from libdpx_i.h
#void DPxEnableTxDviPassthru(void);
# PROPixx Controller Rev >= 24 only
DPxEnableTxDviPassthru = DPxDll['DPxEnableTxDviPassthru']
DPxEnableTxDviPassthru.restype = None
#Private exported function from libdpx_i.h
#void DPxDisableTxDviPassthru(void);
# PROPixx Controller Rev >= 24 only
DPxDisableTxDviPassthru = DPxDll['DPxDisableTxDviPassthru']
DPxDisableTxDviPassthru.restype = None
#Private exported function from libdpx_i.h
#int DPxIsTxDviPassthru(void);
# PROPixx Controller Rev >= 24 only
DPxIsTxDviPassthru = DPxDll['DPxIsTxDviPassthru']
DPxIsTxDviPassthru.restype = ctypes.c_int
#Private exported function from libdpx_i.h
#int DPxIsPPxAsyncResetEnabled(void);
DPxIsPPxAsyncResetEnabled = DPxDll['DPxIsPPxAsyncResetEnabled']
DPxIsPPxAsyncResetEnabled.restype = ctypes.c_int
#Private exported function from libdpx_i.h
#int DPxIsPPxPowerFloatEnabled(void);
DPxIsPPxPowerFloatEnabled = DPxDll['DPxIsPPxPowerFloatEnabled']
DPxIsPPxPowerFloatEnabled.restype = ctypes.c_int
#void DPxSetCustomStartupConfig(void)
_DPxSetCustomStartupConfigCall = DPxDll['DPxSetCustomStartupConfig']
_DPxSetCustomStartupConfigCall.restype = None
[docs]def DPxSetCustomStartupConfig():
"""Saves the current registers to be used on start up.
This can be useful if you set your projector to ceiling mode or rear projection and you
want those settings to persist.
Note:
PROPixx Rev >= 6 only and VIEWPixx/PROPixxCTRL Rev >= 25 only
:Low-level C definition:
``void DPxSetCustomStartupConfig(void)``
"""
return _DPxSetCustomStartupConfigCall()
#void DPxSetFactoryStartupConfig(void)
_DPxSetFactoryStartupConfigCall = DPxDll['DPxSetFactoryStartupConfig']
_DPxSetFactoryStartupConfigCall.restype = None
[docs]def DPxSetFactoryStartupConfig():
"""Returns your device's configurable registers to their default state. This will reset all your customs setting such as
rear projection.
:Low-level C definition:
``void DPxSetFactoryStartupConfig(void)``
"""
_DPxSetFactoryStartupConfigCall()
#int DPxIsCustomStartupConfig(void)
_DPxIsCustomStartupConfigCall = DPxDll['DPxIsCustomStartupConfig']
_DPxIsCustomStartupConfigCall.restype = ctypes.c_int
[docs]def DPxIsCustomStartupConfig():
"""Returns True if VPixx device has loaded custom startup register values
Note:
PROPixx Rev >= 8 only and VIEWPixx/PROPixxCTRL Rev >= 26 only
:Low-level C definition:
``int DPxIsCustomStartupConfig(void)``
"""
temp = DPxSpiRead(SPI_ADDR_VPX_REGDEF, 2)
if (temp[0] == 255) and (temp[1] == 255):
return False
else:
return True
#void DPxEnableVidVesaFreeRun(void)
_DPxEnableVidVesaFreeRunCall = DPxDll['DPxEnableVidVesaFreeRun']
_DPxEnableVidVesaFreeRunCall.restype = None
[docs]def DPxEnableVidVesaFreeRun():
"""Enables PROPixx 3D VESA output freeRun enable bit.
Note:
PROPixx Rev >= 7 only.
:Low-level C definition:
``void DPxEnableVidVesaFreeRun(void)``
"""
return _DPxEnableVidVesaFreeRunCall()
#`void DPxDisableVidVesaFreeRun(void)
_DPxDisableVidVesaFreeRunCall = DPxDll['DPxDisableVidVesaFreeRun']
_DPxDisableVidVesaFreeRunCall.restype = None
[docs]def DPxDisableVidVesaFreeRun():
"""Disables PROPixx 3D VESA output freeRun enable bit
Note:
PROPixx Rev >= 7 only.
:Low-level C definition:
``void DPxDisableVidVesaFreeRun(void)``
"""
return _DPxDisableVidVesaFreeRunCall()
#int DPxIsVidVesaFreeRun(void)
_DPxIsVidVesaFreeRunCall = DPxDll['DPxIsVidVesaFreeRun']
_DPxIsVidVesaFreeRunCall.restype = ctypes.c_int
[docs]def DPxIsVidVesaFreeRun():
"""Returns non-zero if PROPixx VESA 3D output is enabled.
Note:
PROPixx Rev >= 7 only.
:Low-level C definition:
``int DPxIsVidVesaFreeRun(void)``
"""
return _DPxIsVidVesaFreeRunCall()
#void DPxEnableVidLcd3D60Hz(void)
_DPxEnableVidLcd3D60HzCall = DPxDll['DPxEnableVidLcd3D60Hz']
_DPxEnableVidLcd3D60HzCall.restype = None
[docs]def DPxEnableVidLcd3D60Hz():
"""Enables 3D pixel polarity inversion
:Low-level C definition:
``void DPxEnableVidLcd3D60Hz(void)``
"""
return _DPxEnableVidLcd3D60HzCall()
#int DPxIsVidLcd3D60Hz(void)
_DPxDisableVidLcd3D60HzCall = DPxDll['DPxDisableVidLcd3D60Hz']
_DPxDisableVidLcd3D60HzCall.restype = None
[docs]def DPxDisableVidLcd3D60Hz():
"""Returns to normal pixel polarity inversion.
:Low-level C definition:
``int DPxIsVidLcd3D60Hz(void)``
"""
return _DPxDisableVidLcd3D60HzCall()
#int DPxIsVidLcd3D60Hz(void)
_DPxIsVidLcd3D60HzCall = DPxDll['DPxIsVidLcd3D60Hz']
_DPxIsVidLcd3D60HzCall.restype = ctypes.c_int
[docs]def DPxIsVidLcd3D60Hz():
"""Returns non-zero if 3D pixel polarity inversion is enabled
:Low-level C definition:
``int DPxIsVidLcd3D60Hz(void)``
"""
return _DPxIsVidLcd3D60HzCall()
'''
-If an API function detects an error, it will assign a unique error code to a global error variable.
This strategy permits DPxGet*() functions to conveniently return requested values directly,
and still make available a global error code which can be checked when desired.
'''
#void DPxSetError(int error)
_DPxSetErrorCall = DPxDll['DPxSetError']
_DPxSetErrorCall.restype = None
[docs]def DPxSetError(errCode):
"""Sets the device to the given error code.
Args:
errCode (int): Given error code we wish to set the device to.
:Low-level C definition:
``void DPxSetError(int error)``
"""
if errCode in err:
_DPxSetErrorCall(err[errCode])
#void DPxClearError()
_DPxClearErrorCall = DPxDll['DPxClearError']
_DPxClearErrorCall.restype = None
[docs]def DPxClearError():
"""Clear any error on the device.
:Low-level C definition:
``void DPxClearError()``
"""
return _DPxClearErrorCall()
"""
When using "disErr()" or " DPxGetError() ", the last detected error will be returned.
Note that if an error occured long before and wasn't cleared, that error will be returned.
There might not currently be an error, but it will still return an error. So it might be
necessary to clear previous if users want to test if there is an error.
example:
DPx***() call
if disErr() != 0:
...
else:
...
In that case, it might be better to do:
DPxClearError()
DPx***() call
if disErr() != 0:
...
else:
...
"""
#int DPxGetError()
_DPxGetErrorCall= DPxDll['DPxGetError']
_DPxGetErrorCall.restype = ctypes.c_int
[docs]def DPxGetError():
""" Returns the error code
Returns:
int: Error code if an error occured, otherwise 0.
:Low-level C definition:
``int DPxGetError()``
"""
errCode = _DPxGetErrorCall()
if (errCode != ''):
if errCode in err_return:
return err_return[errCode]
else :
return 'Unknown Error: ' + str(errCode)
else: ''
#const char* DPxGetErrorString()
_DPxGetErrorStringCall = DPxDll['DPxGetErrorString']
_DPxGetErrorStringCall.restype = ctypes.c_char_p
[docs]def DPxGetErrorString():
"""Returns the current error string
Returns:
string: Latest error string
:Low-level C definition:
``const char* DPxGetErrorString()``
"""
return _DPxGetErrorStringCall().decode('utf-8')
#int DPxGetDebug()
_DPxGetDebugCall = DPxDll['DPxGetDebug']
_DPxGetDebugCall.restype = ctypes.c_int
[docs]def DPxGetDebug():
""" Returns the current debug level
Returns:
int: Debug level
:Low-level C definition:
``int DPxGetDebug()``
"""
return _DPxGetDebugCall()
#void DPxSetDebug(int level)
_DPxSetDebugCall = DPxDll['DPxSetDebug']
_DPxSetDebugCall.restype = None
[docs]def DPxSetDebug(level):
"""Debugging level controls verbosity of debug and trace messages.
Args:
level (int): Set to ``0`` to disable messages, ``1`` to print libdpx, ``2``, to print libusb debug messages.
:Low-level C definition:
``void DPxSetDebug(int level)``
"""
return _DPxSetDebugCall(level)
#void DPxSaveRegs()
_DPxSaveRegsCall= DPxDll['DPxSaveRegs']
_DPxSaveRegsCall.restype = None
[docs]def DPxSaveRegs():
""" Get all DATAPixx registers, and save them in a local copy
:Low-level C definition:
``void DPxSaveRegs()``
"""
return _DPxSaveRegsCall()
#void DPxRestoreRegs()
_DPxRestoreRegsCall = DPxDll['DPxRestoreRegs']
_DPxRestoreRegsCall.restype = None
[docs]def DPxRestoreRegs():
"""Write the local copy back to the DATAPixx
:Low-level C definition:
``void DPxRestoreRegs()``
"""
return _DPxRestoreRegsCall()
# void DPxStopAllScheds()
# Shortcut to stop running all DAC/ADC/DOUT/DIN/AUD/AUX/MIC schedules
_DPxStopAllSchedsCall = DPxDll['DPxStopAllScheds']
_DPxStopAllSchedsCall.restype = None
[docs]def DPxStopAllScheds():
"""Shortcut to stop running all DAC/ADC/DOUT/DIN/AUD/AUX/MIC schedules.
:Low-level C definition:
``void DPxStopAllScheds()``
"""
return _DPxStopAllSchedsCall()
def DpxStopAllScheds():
print("DEPRECRATED, PLEASE USE DPxStopAllScheds():")
DPxStopAllScheds()
#Private exported function from libdpx_i.h
# void DPxSetReg16(int regAddr, int regValue)
# Set a 16-bit register's value in dpRegisterCache[]
DPxSetReg16 = DPxDll['DPxSetReg16']
DPxSetReg16.restype = None
#Private exported function from libdpx_i.h
# DPxGetReg16(int regAddr);
# Read a 16-bit register's value from dpRegisterCache[]
DPxGetReg16 = DPxDll['DPxGetReg16']
DPxGetReg16.restype = ctypes.c_uint
#Private exported function from libdpx_i.h
# void DPxSetReg32(int regAddr, int regValue)
# Set a 32-bit register's value in dpRegisterCache[]
DPxSetReg32 = DPxDll['DPxSetReg32']
DPxSetReg32.restype = None
#Private exported function from libdpx_i.h
# DPxGetReg32(int regAddr);
# Read a 32-bit register's value from dpRegisterCache[]
DPxGetReg32 = DPxDll['DPxGetReg32']
DPxGetReg32.restype = ctypes.c_uint
#Private exported function from libdpx_i.h
# DPxGetRegSize(int regAddr);
# Returns the size of a register in bytes.
DPxGetRegSize = DPxDll['DPxGetRegSize']
DPxGetRegSize.restype = ctypes.c_uint
#Private exported function from libdpx_i.h
#int DPxGetVidSwtpAddr(void);
_DPxGetVidSwtpAddrCall = DPxDll['DPxGetVidSwtpAddr']
_DPxGetVidSwtpAddrCall.restype = ctypes.c_int
def DPxGetVidSwtpAddr():
return _DPxGetVidSwtpAddrCall()
#Private exported function from libdpx_i.h
#void DPxSetVidSwtp(int address);
_DPxSetVidSwtpCall = DPxDll['DPxSetVidSwtp']
_DPxSetVidSwtpCall.argtypes = [ctypes.c_int]
_DPxSetVidSwtpCall.restype = None
def DPxSetVidSwtp(address):
_DPxSetVidSwtpCall(address)
#Private exported function from libdpx_i.h
#void DPxSetVidSwtp3D(int address);
_DPxSetVidSwtp3DCall = DPxDll['DPxSetVidSwtp3D']
_DPxSetVidSwtp3DCall.argtypes = [ctypes.c_int]
_DPxSetVidSwtp3DCall.restype = None
def DPxSetVidSwtp3D(address):
_DPxSetVidSwtp3DCall(address)
# void PPxDownloadTestPattern(TestStruct* testPattern, int loadAddr, int page)
[docs]def PPxLoadTestPattern(image, add, page):
"""Loads an image in the PROPixx since the PROPixx is different for software test patterns.
:Low-level C definition:
``void PPxDownloadTestPattern(TestStruct* testPattern, int loadAddr, int page)``
"""
class image_conv(ctypes.Structure):
_fields_ = [("array", (ctypes.c_ubyte * 3) * 1920 * 1080)]
_PPxDownloadTestPatternCall = DPxDll['PPxDownloadTestPattern']
_PPxDownloadTestPatternCall.argtypes = [ctypes.POINTER(image_conv), ctypes.c_int, ctypes.c_int ]
_PPxDownloadTestPatternCall.restype = None
image_c = image_conv()
#image_c.array = image
for i in range(0,3):
for x in range(0, 1920):
for y in range(0, 1080):
image_c.array[y][x][i] = int(image[y][x][i])
_PPxDownloadTestPatternCall(image_c, add, page)
#Private exported function from libdpx_i.h
#void DPxSetPPxHotSpotLut(int hotSpotCenterX, int hotSpotCenterY, UInt16* hotSpotLutData)
_DPxSetPPxHotSpotLutCall = DPxDll['DPxSetPPxHotSpotLut']
_DPxSetPPxHotSpotLutCall.argtypes = [ctypes.c_int, ctypes.c_int, ctypes.POINTER(ctypes.c_uint16)]
_DPxSetPPxHotSpotLutCall.restype = None
def DPxSetPPxHotSpotLut(x, y, psi):
item_count = len(psi)
packed_data = (ctypes.c_uint16 * item_count)(*psi)
_DPxSetPPxHotSpotLutCall(x,y, packed_data)
#Private exported function from libdpx_i.h
#void DPxEnablePPxHotSpotCorrection()
_DPxEnablePPxHotSpotCorrectionCall = DPxDll['DPxEnablePPxHotSpotCorrection']
_DPxEnablePPxHotSpotCorrectionCall.argtypes = None
_DPxEnablePPxHotSpotCorrectionCall.restype = None
def DPxEnablePPxHotSpotCorrection():
_DPxEnablePPxHotSpotCorrectionCall()
#Private exported function from libdpx_i.h
# void DPxDisablePPxHotSpotCorrection(void)
_DPxDisablePPxHotSpotCorrectionCall = DPxDll['DPxDisablePPxHotSpotCorrection']
_DPxDisablePPxHotSpotCorrectionCall.argtypes = None
_DPxDisablePPxHotSpotCorrectionCall.restype = None
def DPxDisablePPxHotSpotCorrection():
_DPxDisablePPxHotSpotCorrectionCall()
#Private exported function from libdpx_i.h
#void DPxSetPPxHotSpotCenter(int x, int y)
_DPxSetPPxHotSpotCenterCall = DPxDll['DPxSetPPxHotSpotCenter']
_DPxSetPPxHotSpotCenterCall.argtypes = [ctypes.c_int, ctypes.c_int]
_DPxSetPPxHotSpotCenterCall.restype = None
[docs]def DPxSetPPxHotSpotCenter(x,y):
""" Sets the hotspot correction location only.
Arguments:
x (int): The position in x from the center, + to the left.
y (int): The position in y from the center, + to the bottom.
"""
_DPxSetPPxHotSpotCenterCall(x,y)
#Private exported function from libdpx_i.h
#int DPxIsPPxHotSpotCorrection(void)
IsPPxHotSpotCorrection = DPxDll['DPxIsPPxHotSpotCorrection']
IsPPxHotSpotCorrection.argtypes = None
IsPPxHotSpotCorrection.restype = ctypes.c_int
[docs]def DPxIsPPxHotSpotCorrection():
"""
"""
return IsPPxHotSpotCorrection()
#void DPxGetPPxHotSpotCenter(int *x, int *y)
GetPPxHotSpotCenter = DPxDll['DPxGetPPxHotSpotCenter']
GetPPxHotSpotCenter.argtypes = [ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_int)]
GetPPxHotSpotCenter.restype = None
[docs]def DPxGetPPxHotSpotCenter():
"""
"""
p_x = ctypes.c_int(0)
p_y = ctypes.c_int(0)
GetPPxHotSpotCenter(ctypes.byref(p_x), ctypes.byref(p_y))
return (p_x.value, p_y.value)
getBacklightIntensity = DPxDll['DPxGetVidBacklightIntensity']
[docs]def DPxGetVidBacklightIntensity():
""" Returns the display current back light intensity.
Returns:
int: current backlight intensity in a scale between 0 and 255.
:Example:
>>> print my_device.getBacklightIntensity()
255
See also:
:class:`DPxSetBacklightIntensity`
:Low-level C definition:
``int DPxGetVidBacklightIntensity()``
"""
return getBacklightIntensity()
setBacklightIntensity = DPxDll['DPxSetVidBacklightIntensity']
setBacklightIntensity.argtypes = [ctypes.c_int]
setBacklightIntensity.restype = None
[docs]def DPxSetVidBacklightIntensity(intensity):
"""Sets the display current back light intensity.
Args:
intensity (int): Set to ``0`` for the lowest intensity level, ``255`` for the highest, or any other value in between.
:Example:
>>> my_device.setBacklightIntensity(42)
>>> my_device.updateRegisterCache()
>>> print my_device.getBacklightIntensity()
42
See also:
:class:`DPxGetBacklightIntensity`
:Low-level C definition:
``void DPxSetBacklightIntensity(int intensity)``
"""
setBacklightIntensity(intensity)
#Private exported function from libdpx_i.h
# Returns non-zero if there is a custom edid.
# int DPxIsCustomEdid(void)
DPxIsCustomEdid = DPxDll['DPxIsCustomEdid']
DPxIsCustomEdid.restype = ctypes.c_int
#Private exported function from libdpx_i.h
#int DPxHasRawUsb(void)
hasRawUsb = DPxDll['DPxHasRawUsb']
hasRawUsb.restype = ctypes.c_int
def DPxHasRawUsb():
# The low-level also sometimes returns an address. In that case, the value is
# Non-Zero, but the USB is not Raw. So when the return value is higher than
# 2^15, it could be an address. It should be safe safe to assume that the function
# will never reach that value when a raw usb is detected.
temp_value = hasRawUsb()
if temp_value > 32768:
temp_value = 0
return temp_value
#Private exported function from libdpx_i.h
#int DPxIsUsbTreeChanged(void)
isUsbTreeChanged = DPxDll['DPxIsUsbTreeChanged']
isUsbTreeChanged.restype = ctypes.c_int
def DPxIsUsbTreeChanged():
return isUsbTreeChanged()
#Private exported function from libdpx_i.h
#void DPxUsbScan(int doPrint)
usbScan = DPxDll['DPxUsbScan']
usbScan.restype = None#ctypes.c_int
def DPxUsbScan(print_info=0):
usbScan(print_info)
#Private exported function from libdpx_i.h
#void DPxReset(void)
reset = DPxDll['DPxReset']
reset.restype = None
def DPxReset():
reset()
#Private exported function from libdpx_i.h
#void DPxResetAll(void)
resetAll = DPxDll['DPxResetAll']
resetAll.restype = None
def DPxResetAll():
resetAll()
_DPxGetDevicesCount = DPxDll['DPxGetDevicesCount']
_DPxGetDevicesCount.restype = ctypes.c_int
[docs]def DPxGetDevicesCount ():
"""Return the size of one image in RAM.
Returns:
(int) Thethe size of image in byte
:Low-level C definition:
``int TPxSaveImageGap()``
"""
return _DPxGetDevicesCount()
#void DP3EnableTxVideoPassthru(int channel)
_DP3EnableTxVideoPassthru = DPxDll['DP3EnableTxVideoPassthru']
_DP3EnableTxVideoPassthru.restype = None
[docs]def DP3EnableTxVideoPassthru():
"""Enable the Tx Video Pass through mode on the Datapixx3.
:Low-level C definition:
``void DP3EnableTxVideoPassthru(int channel)``
"""
_DP3EnableTxVideoPassthru()
_DP3SetVidConsoleMode = DPxDll['DP3SetVidConsoleMode']
_DP3SetVidConsoleMode.argtypes = [ctypes.c_int]
_DP3SetVidConsoleMode.restype = None
[docs]def DP3SetVidConsoleDisplay(presetDisposition = 'FULL_STIMULI_HALF_TRACK'):
"""Select a preset video console disposition for the stimulis window and the tracker window. Only available for Datapixx3 Revision 8 and higher.
Args:
presetDisposition (str) : Determins the resolution and disposition of the windows. It can take on one of the following values
- **FULL_STIMULI_HALF_TRACK** (0): Tracker window will take half of its full resolution, Stimulis window will take full resolution and will be bound to the bottom right side of the screen.
- **FULL_STIMULI_NO_TRACK** (1): Tracker window will be turned off. Stimulis window will take full resolution and will be bound to the bottom right side of the screen.
- **FULL_STIMULI_FULL_TRACK** (2): Tracker window will take its full resolution. Stimulis window will take full resolution and will be bound to the bottom right side of the screen.
- **HALF_STIMULI_FULL_TRACK** (3): Tracker window will take its full resolution. Stimulis window will take half of its full resolution and will be bound to the bottom right side of the screen.
"""
_DP3SetVidConsoleMode(videoConsoleDisplayPresets[presetDisposition.upper()])
_DP3GetVidConsoleMode = DPxDll['DP3GetVidConsoleMode']
_DP3GetVidConsoleMode.argtypes = None
_DP3GetVidConsoleMode.restype = ctypes.c_int
def DP3GetVidConsoleMode():
return _DP3GetVidConsoleMode()
#double DP3GetPowerMonitor(int powNum)
_DP3GetPowerMonitor = DPxDll['DP3GetPowerMonitor']
_DP3GetPowerMonitor.restype = ctypes.c_double
[docs]def DP3GetPowerMonitor(powNum):
"""Get DATAPixx3 Power Monitor.
powNum :
- DP3_POW_VOLTAGE_0V95: 0
- DP3_POW_CURRENT_0V95: 1
- DP3_POW_POWER_0V95: 2
- DP3_POW_VOLTAGE_1V03: 3
- DP3_POW_CURRENT_1V03: 4
- DP3_POW_POWER_1V03: 5
- DP3_POW_VOLTAGE_1V8: 6
- DP3_POW_CURRENT_1V8: 7
- DP3_POW_POWER_1V8: 8
- DP3_POW_VOLTAGE_5V0: 9
- DP3_POW_CURRENT_5V0: 10
- DP3_POW_POWER_5V0: 11
Returns:
double: Voltage
:Low-level C definition:
``double DP3GetPowerMonitor(int powNum)``
"""
return _DP3GetPowerMonitor(ctypes.c_int(powNum))
#int DP3IsRxVideoLocked(int channel);
_DP3IsRxVideoLocked = DPxDll['DP3IsRxVideoLocked']
_DP3IsRxVideoLocked.restype = ctypes.c_int
[docs]def DP3IsRxVideoLocked(channel):
"""Check if RX Video is locked
channel : Rx Channel
Returns:
int: 1 if lock
:Low-level C definition:
``int DP3IsRxVideoLocked(int channel)``
"""
return _DP3IsRxVideoLocked(ctypes.c_int(channel))
#int DP3IsTxVideoLocked(int channel);
_DP3IsTxVideoLocked = DPxDll['DP3IsTxVideoLocked']
_DP3IsTxVideoLocked.restype = ctypes.c_int
[docs]def DP3IsTxVideoLocked(channel):
"""Check if RX Video is locked
channel : Rx Channel
Returns:
int: 1 if lock
:Low-level C definition:
``int DP3IsTxVideoLocked(int channel)``
"""
return _DP3IsTxVideoLocked(ctypes.c_int(channel))
#int DP3IsRxVideoBuffer(int channel);
_DP3IsRxVideoBuffer = DPxDll['DP3IsRxVideoBuffer']
_DP3IsRxVideoBuffer.restype = ctypes.c_int
[docs]def DP3IsRxVideoBuffer(channel):
""""Check if RX Video is buffered
channel : Rx Channel
Returns:
1 if buffered
:Low-level C definition:
``int DP3IsRxVideoBuffer(int channel)``
"""
return _DP3IsRxVideoBuffer(ctypes.c_int(channel))
#int DP3IsTxVideoPassthru(int channel);
_DP3IsTxVideoPassthru = DPxDll['DP3IsTxVideoPassthru']
_DP3IsTxVideoPassthru.restype = ctypes.c_int
[docs]def DP3IsTxVideoPassthru(channel):
""""Check if TX Video is passthru
channel : Rx Channel
Returns:
1 if passthru
:Low-level C definition:
``int DP3IsTxVideoPassthru(int channel)``
"""
return _DP3IsTxVideoPassthru(ctypes.c_int(channel))
#double DP3GetTemperature(int tempNum);
_DP3GetTemperature = DPxDll['DP3GetTemperature']
_DP3GetTemperature.restype = ctypes.c_double
[docs]def DP3GetTemperature(tempNum):
"""Get DATAPixx3 temperature Monitor
tempNum : Temperature type to monitor
- DP3_TEMP_FPGA:0
- DP3_TEMP_DP:1
- DP3_TEMP_FF:2
- DP3_TEMP_USB:3
- DP3_TEMP_ADC:4
- DP3_TEMP_POW_0V95:5
- DP3_TEMP_POW_1V03:6
- DP3_TEMP_POW_1V8:7
- DP3_TEMP_POW_5V0:8
Returns:
double: temperature
:Low-level C definition:
``double DP3GetTemperature(int tempNum)``
"""
return _DP3GetTemperature(ctypes.c_int(tempNum))
"""
This section provides the list of all predefined constants.
"""
#void DP3EnableTPxAnalogOut(int eye)
_DP3EnableTPxAnalogOut = DPxDll['DP3EnableTPxAnalogOut']
_DP3EnableTPxAnalogOut.restype = None
[docs]def DP3EnableTPxAnalogOut(eye):
"""Enables Analog Out
eye: Eye to disable (LEFT_EYE : 0, RIGHT_EYE : 1)
:Low-level C definition:
``void DP3EnableTPxAnalogOut(int eye)``
"""
_DP3EnableTPxAnalogOut(ctypes.c_int(eye))
#void DP3DisableTPxAnalogOut(void)
_DP3DisableTPxAnalogOut = DPxDll['DP3DisableTPxAnalogOut']
_DP3DisableTPxAnalogOut.restype = None
[docs]def DP3DisableTPxAnalogOut():
"""Disable Analog Out
:Low-level C definition:
``void DP3DisableTPxAnalogOut(void)``
"""
_DP3DisableTPxAnalogOut()
#unsigned DPxGetDPCoreReg(int channel, int addOffset, int addr)
_DPxGetDPCoreReg = DPxDll['DPxGetDPCoreReg']
_DPxGetDPCoreReg.restype = ctypes.c_uint
[docs]def DPxGetDPCoreReg(channel, addOffset, addr):
"""Read an 32-bit register from DP Core
:Low-level C definition:
``unsigned DPxGetDPCoreReg(int channel, int addOffset, int addr)``
"""
return _DPxGetDPCoreReg(ctypes.c_int(channel), ctypes.c_int(addOffset), ctypes.c_int(addr))
_DPxOpenIp = DPxDll['DPxOpenIp']
_DPxOpenIp.restype = ctypes.c_int
[docs]def DPxOpenIp(ip = "127.0.0.1"):
"""Does a DPxOpen on a particular server address Args:
ip (string): A valid IP address formatted according to the normal address classes.
Four dot seperated digits ranging from 0 to 255.
Returns:
int: Non-zero if the address fails, 0 if the address exists.
:Low-level C definition:
``int DPxOpenIp(char* inIpAddr)``
"""
p_ip = ctypes.create_string_buffer(ip.encode('utf-8'))
return _DPxOpenIp(p_ip)
_DPxSetServerAddress = DPxDll['DPxSetServerAddress']
_DPxSetServerAddress.restype = ctypes.c_int
[docs]def DPxSetServerAddress(ip = "127.0.0.1"):
"""Sets a server address in the low-level API
Args:
ip (string): A valid IP address formatted according to the normal address classes.
Four dot seperated digits ranging from 0 to 255.F
Returns:
int: Non-zero if the address fails, 0 if the address exists.
:Low-level C definition:
``int DPxSetServerAddress(char* inIpAddr)``
"""
p_ip = ctypes.create_string_buffer(ip.encode('utf-8'))
return _DPxSetServerAddress(p_ip)
_DPxGetCustomDevName = DPxDll['DPxGetCustomDevName']
_DPxGetCustomDevName.restype = ctypes.c_char_p
[docs]def DPxGetCustomDevName():
"""Get user-specified device name, ignoring whether or not it has been assigned to dpxSysDevsel
Returns:
Custom Device Name
:Low-level C definition:
``const char* DPxGetCustomDevName()``
"""
return _DPxGetCustomDevName().decode('utf-8')
_DPxSetCustomDevName = DPxDll['DPxSetCustomDevName']
[docs]def DPxSetCustomDevName(devName):
"""Set user-specified device name, ignoring whether or not it has been assigned to dpxSysDevsel
:Low-level C definition:
``void DPxSetCustomDevName(unsigned char* devName)``
"""
p_devName = ctypes.create_string_buffer(devName.encode('utf-8'))
return _DPxSetCustomDevName(p_devName)
_DPxClearCustomDevName = DPxDll['DPxClearCustomDevName']
[docs]def DPxClearCustomDevName():
"""Clear user-specified device name, ignoring whether or not it has been assigned to dpxSysDevsel
:Low-level C definition:
``void DPxClearCustomDevName()``
"""
return _DPxSetCustomDevName()
#unsigned int DPxGetNbMaxDevices();
_DPxGetNbMaxDevices = DPxDll['DPxGetNbMaxDevices']
_DPxGetNbMaxDevices.restype = ctypes.c_uint
[docs]def DPxGetNbMaxDevices():
"""Get the number maximum of devices supported
:low-level C definition:
``unsigned int DPxGetNbMaxDevices()``
"""
return _DPxGetNbMaxDevices()
#void DPxGetAllDeviceTable(stDeviceTableForPython *deviceTableForPython)
def DPxGetAllDeviceTable():
class deviceTable(ctypes.Structure):
_fields_ = [("dpxRawUsb", ctypes.c_int),
("dpxGoodFpga", ctypes.c_int),
("dpxIsDatapixx", ctypes.c_int),
("dpxIsDatapixx2", ctypes.c_int),
("dpxIsDatapixx3", ctypes.c_int),
("dpxIsViewpixx", ctypes.c_int),
("dpxViewpixxType", ctypes.c_int),
("dpxIsPropixxCtrl", ctypes.c_int),
("dpxIsPropixx", ctypes.c_int),
("dpxIsTrackpixx", ctypes.c_int),
("dpxIsPropixx3", ctypes.c_int),
("dpxIsIOHub", ctypes.c_int),
("dpxIsBridgedDevice", ctypes.c_int),
("dpxBridgePort", ctypes.c_int),
("dpxDeviceName", ctypes.c_char*64),
("dpxSerialNum", ctypes.c_char*64)]
_DPxGetAllDeviceTableCall = DPxDll['DPxGetAllDeviceTable']
_DPxGetAllDeviceTableCall.argtypes = [ctypes.POINTER(deviceTable * DPxGetNbMaxDevices())]
_DPxGetAllDeviceTableCall.restype = None
allDeviceTableFromServer = deviceTable * DPxGetNbMaxDevices()
ptrdeviceTableFromServer = allDeviceTableFromServer()
_DPxGetAllDeviceTableCall(ctypes.byref(ptrdeviceTableFromServer))
return ptrdeviceTableFromServer
# void TPxDetectTrackerType(TrackerType *trackerType)
_TPxDetectTrackerTypeCall = DPxDll['TPxDetectTrackerType']
[docs]def DetectTrackerType():
"""Return the tracker type
Return :
(int) tracker type (TPX3 : 0, TPXMINI : 1)
"""
trackerType = ctypes.c_int()
_TPxDetectTrackerTypeCall(ctypes.byref(trackerType))
return (trackerType.value)
import re
import codecs
ESCAPE_SEQUENCE_RE = re.compile(r'''
( \\U........ # 8-digit hex escapes
| \\u.... # 4-digit hex escapes
| \\x.. # 2-digit hex escapes
| \\[0-7]{1,3} # Octal escapes
| \\N\{[^}]+\} # Unicode characters by name
| \\[\\'"abfnrtv] # Single-character escapes
)''', re.UNICODE | re.VERBOSE)
def decode_escapes(s):
def decode_match(match):
return codecs.decode(match.group(0), 'unicode-escape')
return ESCAPE_SEQUENCE_RE.sub(decode_match, s)
# void TPxInitialize(int gazePointFilterMode, char *licenseFilePath)
_TPxInitializeCall = DPxDll['TPxInitialize']
_TPxInitializeCall.restype = None
_TPxInitializeCall.argtypes = [ctypes.c_int, ctypes.c_char_p]
[docs]def TPxInitialize(gazePointFilterMode, licenseFilePath = ""):
""" Initialize the tracker dependently of tractor type
Args:
gazePointFilterMode (enum): s
- QL_DEVICE_GAZE_POINT_FILTER_NONE
- QL_DEVICE_GAZE_POINT_FILTER_MEDIAN_FRAMES
- QL_DEVICE_GAZE_POINT_FILTER_MEDIAN_TIME
- QL_DEVICE_GAZE_POINT_FILTER_HEURISTIC_FRAMES
- QL_DEVICE_GAZE_POINT_FILTER_HEURISTIC_TIME
- QL_DEVICE_GAZE_POINT_FILTER_WEIGHTED_PREVIOUS_FRAME
- QL_DEVICE_GAZE_POINT_FILTER_MEAN_FRAMES
- QL_DEVICE_GAZE_POINT_FILTER_MEAN_TIME
:Low-level C definition:
``void TPxInitialize(int gazePointFilterMode, char *licenseFilePath)``
"""
return _TPxInitializeCall(gazePointFilterMode, ctypes.c_char_p(licenseFilePath.encode('utf-8')))
# void TPxUninitialize()
_TPxUninitializeCall = DPxDll['TPxUninitialize']
_TPxUninitializeCall.restype = None
[docs]def TPxUninitialize():
""" Uninitialize the tracker dependently of tractor type.
:Low-level C definition:
``void TPxUninitialize()``
"""
return _TPxUninitializeCall()
# void TPxInitializeCalibration(float *targets, int *targetsCount)
_TPxInitializeCalibrationCall = DPxDll['TPxInitializeCalibration']
_TPxInitializeCalibrationCall.restype = None
_TPxInitializeCalibrationCall.argtypes = [ctypes.POINTER(ctypes.POINTER(ctypes.c_float)), ctypes.POINTER(ctypes.c_int)]
[docs]def TPxInitializeCalibration():
"""Initialize the buit-in calibration process on the tracker.
Args:
targets (float): The x and y position of the targets. This is in percentage of the horizontal area to be calibrated (0.-100.).
:Low-level C definition:
``void TpxInitializeCalibration(float *targets, int *targetsCount)``
"""
targetsCount = ctypes.c_int(0)
ptr = ctypes.POINTER(ctypes.c_float)() #ctypes.cast (packedData, ctypes.POINTER(ctypes.c_float))
_TPxInitializeCalibrationCall(ctypes.byref(ptr),ctypes.byref(targetsCount))
target = []
for targetIndex in range(targetsCount.value):
print(targetIndex)
print(ptr[targetIndex*2])
print(ptr[targetIndex*2+1])
target.append((round(ptr[targetIndex*2]/100*1920), 1080 - round(ptr[targetIndex*2+1]/100*1080)))
return target, targetsCount.value
# void TpxCalibrateTarget(int targetIndex);
_TPxCalibrateTargetCall = DPxDll['TPxCalibrateTarget']
_TPxCalibrateTargetCall.restype = ctypes.c_int
[docs]def TPxCalibrateTarget(targetIndex):
"""Calibrate the specified target index on the tracker.
Args:
targetIndex (int): The index of the target to calibrate.
:Low-level C definition:
``void TpxCalibrateTarget(float *targets)``
"""
return _TPxCalibrateTargetCall(targetIndex)
# void TpxFinalizeCalibration();
_TPxFinalizeCalibrationCall = DPxDll['TPxFinalizeCalibration']
_TPxFinalizeCalibrationCall.restype = ctypes.c_uint
[docs]def TPxFinalizeCalibration():
"""Finalize the buit-in calibration process on the tracker.
:Low-level C definition:
``void TpxFinalizeCalibration()``
"""
return _TPxFinalizeCalibrationCall()
_TPxIsRemoteCalibratedCall = DPxDll['TPxIsRemoteCalibrated']
_TPxIsRemoteCalibratedCall.restype = ctypes.c_int
[docs]def TPxIsRemoteCalibrated():
"""Verifies if the tracker is remote calibrated.
:Low-level C definition:
``void TPxIsRemoteCalibrated()``
"""
cal_status = _TPxIsRemoteCalibratedCall()
if(cal_status == 0):
return False
else:
return True
# void TPxSetBuff(unsigned buffAddr, unsigned buffSize);
_TPxSetBuffCall = DPxDll['TPxSetBuff']
_TPxSetBuffCall.restype = None
[docs]def TPxSetBuff(buffer_addres, buffer_size):
"""Shortcut to set up the the base address and buffer size for schedule recording of TRACKPixx data.
:Low-level C definition:
``void TPxSetBuff(unsigned buffAddr, unsigned buffSize)``
"""
return _TPxSetBuffCall(buffer_addres, buffer_size)
# void TPxEnableFreeRun();
_TPxEnableFreeRunCall = DPxDll['TPxEnableFreeRun']
_TPxEnableFreeRunCall.restype = None
[docs]def TPxEnableFreeRun():
"""Enable the schedule to automatically record all data
:Low-level C definition:
``void TPxEnableFreeRun()``
"""
return _TPxEnableFreeRunCall()
# void TPxDisableFreeRun();
_TPxDisableFreeRunCall = DPxDll['TPxDisableFreeRun']
_TPxDisableFreeRunCall.restype = None
[docs]def TPxDisableFreeRun():
"""Disable the schedule to automatically record all data
:Low-level C definition:
``void TPxDisableFreeRun()``
"""
return _TPxDisableFreeRunCall()
# void TPxEnableMedianFilter()
_TPxEnableMedianFilterCall = DPxDll['TPxEnableMedianFilter']
_TPxEnableMedianFilterCall.restype = None
# void TPxDisableMedianFilter()
_TPxDisableMedianFilterCall = DPxDll['TPxDisableMedianFilter']
_TPxDisableMedianFilterCall.restype = None
# int TPxIsMedianFilterEnabled()
_TPxIsMedianFilterEnabledCall = DPxDll['TPxIsMedianFilterEnabled']
_TPxIsMedianFilterEnabledCall.restype = ctypes.c_int
# void TPxEnableHDR()
_TPxEnableHDRCall = DPxDll['TPxEnableHDR']
_TPxEnableHDRCall.restype = None
[docs]def TPxEnableHDR():
"""Enable the High Dynamic Range mode
:Low-level C definition:
``void TPxEnableHDR()``
"""
return _TPxEnableHDRCall()
# void TPxDisableHDR()
_TPxDisableHDRCall = DPxDll['TPxDisableHDR']
_TPxDisableHDRCall.restype = None
[docs]def TPxDisableHDR():
"""Disable the High Dynamic Range mode
:Low-level C definition:
``void TPxDisableHDR()``
"""
return _TPxDisableHDRCall()
# int IsHDREnabled()
_TPxIsHDREnabledCall = DPxDll['TPxIsHDREnabled']
_TPxIsHDREnabledCall.restype = ctypes.c_int
[docs]def TPxIsHDREnabledCall():
"""Returns the state of the HDR Filter
:Low-level C definition:
``int TPxIsHDREnabled()``
"""
return _TPxIsHDREnabledCall()
# To be change: add filetype compatibility, because it will help the user save to its own file.
# unsigned TPxSaveToCsv(unsigned address);
_TPxSaveToCsvCall = DPxDll['TPxSaveToCsv']
_TPxSaveToCsvCall.restype = ctypes.c_uint32
[docs]def TPxSaveToCSV(last_read_address, fileName):
"""Save from last_read_address up to TPxGetReadAddr(), into the default file for today
:Low-level C definition:
`unsigned TPxSaveToCsv(unsigned address)``
"""
if isinstance(fileName,str):
fileName = fileName.encode('utf-8')
return _TPxSaveToCsvCall(last_read_address, fileName)
# void TPxGetEyePositionDuringCalib(float screen_x, float screen_y, int eyeToVerify);
_TPxGetEyePositionDuringCalibCall = DPxDll['TPxGetEyePositionDuringCalib']
_TPxGetEyePositionDuringCalibCall.restype = None
_TPxGetEyePositionDuringCalibCall.argtypes = [ctypes.c_double, ctypes.c_double, ctypes.c_int]
[docs]def TPxGetEyePositionDuringCalib(x_screen, y_screen, eye_to_verify = 3):
""" Tells the camera to calibrate the current eye position.
This function is to be called during calibration, when there is a focus point displayed on the stimulus display.
Args:
x_screen (float): x-coordinate of the stimulus
y_screen (float): y-coordinate of the stimulus
eye_to_verify (int): enable data verification for each eye (bit 0 -> left eye, bit 1 -> rigth eye, active high)
Note:
It is possible to call this soon after stimulus is displayed (~500 ms after) since the tracker will wait for a fixation itself.
:Low-level C definition:
``void TPxGetEyePositionDuringCalib(float screen_x, float screen_y, int eyeToVerify)``
"""
return _TPxGetEyePositionDuringCalibCall( x_screen, y_screen, eye_to_verify )
# void TPxGetEyePositionDuringCalib_returnRaw(float screen_x, float screen_y, double* rawPosition, int eyeToVerify);
_TPxGetEyePositionDuringCalibCall_returnsRaw = DPxDll['TPxGetEyePositionDuringCalib_returnsRaw']
_TPxGetEyePositionDuringCalibCall_returnsRaw.restype = None
_TPxGetEyePositionDuringCalibCall_returnsRaw.argtypes = [ctypes.c_double, ctypes.c_double, (ctypes.c_double * 4), ctypes.c_int]
[docs]def TPxGetEyePositionDuringCalib_returnsRaw(x_screen, y_screen, eye_to_verify = 3):
""" Tells the camera to calibrate the current eye position and returns the raw (uncalibrated) vectors.
This function is to be called during calibration, when there is a focus point displayed on the stimulus display.
Args:
x_screen (float): x-coordinate of the stimulus
y_screen (float): y-coordinate of the stimulus
eye_to_verify (int): enable data verification for each eye (bit 0 -> left eye, bit 1 -> rigth eye, active high)
Note:
It is possible to call this soon after stimulus is displayed (~500 ms after) since the tracker will wait for a fixation itself.
Returns:
A list of raw eye vectors [xRightEye, yRightEye, xLeftEye, yLeftEye]
:Low-level C definition:
``void TPxGetEyePositionDuringCalib_returnsRaw(float screen_x, float screen_y, double* rawPosition, int eyeToVerify)``
"""
rawPosition = (ctypes.c_double*4)(* [0.0]*4)
_TPxGetEyePositionDuringCalibCall_returnsRaw( x_screen, y_screen, rawPosition, eye_to_verify )
return rawPosition[:]
# void TPxBestPolyGetEyePosition(double* eyeReturn, double* rawData)
_TPxBestPolyGetEyePositionCall = DPxDll['TPxBestPolyGetEyePosition']
_TPxBestPolyGetEyePositionCall.restype = ctypes.c_double
[docs]def TPxBestPolyGetEyePosition(packed_data, raw_data):
""" Returns the current gaze position by finding the best polynomial.
This returns the current calibrated gaze position on the screen using the calibration parameters found for the latest calibration.
Args:
packed_data (float): A list of position, such that first element is screen_x_left_eye, screen_y_left_eye, screen_x_right_eye, screen_y_right_eye
raw_data (float): A list of raw position, such that first element is x_left_eye, y_left_eye, x_right_eye, y_right_eye
Returns:
Return the timestamp from the tracker associated with the position
Example:
``>>import ctypes
>>packed_data = [0.0]*4
>>raw_data = [0.0]*4
>>timeStamp = TPxBestPolyGetEyePosition( (ctypes.c_double*4)(*packed_data), (ctypes.c_double*4)(*raw_data) )
>>packed_data = packed_data[:]``
:Low-level C definition:
``double TPxBestPolyGetEyePosition(double* eyeReturn, double* rawData)``
"""
posTimestamp = ctypes.c_double(0)
posTimestamp = _TPxBestPolyGetEyePositionCall(packed_data, raw_data)
return posTimestamp
[docs]def TPxGetEyePosition():
"""
Returns the current calibrated eye position, raw vectors, and timestamp.
Duplicates MATLAB function Datapixx('GetEyePosition').
Returns:
list: [xScreenLeft, yScreenLeft, xScreenRight, yScreenRight,
xLeftRaw, yLeftRaw, xRightRaw, yRightRaw,
timeStamp]
where
"Screen" elements are calibrated eye positions in Cartesian screen pixel coordinates,
"Raw" elements are uncalibrated corneal-to-pupil-center vectors in radians,
and
"timeStamp" is the DATAPixx time of the samples in seconds
:Low-level C definition:
``double TPxBestPolyGetEyePosition(double* eyeReturn, double* rawData)``
"""
packed_data = (ctypes.c_double*4)(* [0.0]*4)
raw_data = (ctypes.c_double*4)(* [0.0]*4)
posTimestamp = TPxBestPolyGetEyePosition(packed_data, raw_data)
return packed_data[:]+raw_data[:]+[posTimestamp]
_TPxGetPupilSize = DPxDll['TPxGetPupilSize']
_TPxGetPupilSize.restype = ctypes.c_int
_TPxGetPupilSize.argtypes = [(ctypes.c_double * 4)]
[docs]def TPxGetPupilSize():
"""Get pupil size as the semi- major/minor axes of an ellipse fitted to the left/right pupil.
Replicates MATLAB function Datapixx('GetPupilSize');
Returns:
tuple: (leftMajor, leftMinor, rightMajor, rightMinor)
:Low-level C definition:
``void TPxGetPupilSize(double* pupilSize)``
"""
pupil_size = (ctypes.c_double * 4)(* [.0]*4)
_TPxGetPupilSize(pupil_size)
return tuple(pupil_size[:])
_TPxGetPupilCoordinatesInPixels = DPxDll['TPxGetRawPupilCoordinates']
_TPxGetPupilCoordinatesInPixels.restype = ctypes.c_int
_TPxGetPupilCoordinatesInPixels.argtypes = [(ctypes.c_double * 4)]
[docs]def TPxGetPupilCoordinatesInPixels():
"""Get the (x,y) screen coordinates for left/right pupil centers.
Replicates MATLAB function Datapixx('GetPupilCoordinatesInPixels');
Returns:
list: [leftX, leftY, rightX, rightY]
:Low-level C definition:
``void TPxGetPupilSize(double* pupilSize)``
"""
pupilCoord = (ctypes.c_double * 4)(* [.0]*4)
_TPxGetPupilCoordinatesInPixels(pupilCoord)
return pupilCoord[:]
_TPxGetRawCRCoordinates = DPxDll['TPxGetRawCRCoordinates']
_TPxGetRawCRCoordinates.restype = ctypes.c_int
_TPxGetRawCRCoordinates.argtypes = [(ctypes.c_double * 4)]
[docs]def TPxGetCRCoordinatesInPixels():
"""Get the (x,y) screen coordinates for left/right corneal reflection centers.
Replicates MATLAB function Datapixx('GetCRCoordinatesInPixels');
Returns:
list: [leftX, leftY, rightX, rightY]
:Low-level C definition:
``void TPxGetRawCRCoordinates(double* pupilSize)``
"""
CRCoord = (ctypes.c_double * 4)(* [.0]*4)
_TPxGetRawCRCoordinates(CRCoord)
return CRCoord[:]
_TPxGetCalibCoeffs = DPxDll['TPxGetCalibCoeffs']
_TPxGetCalibCoeffs.restype = None
_TPxGetCalibCoeffs.argtypes = [(ctypes.c_double * 36)]
[docs]def TPxGetCalibCoeffs():
"""Get the calibrated coefficients for the polynomial that transforms raw eye vectors
into screen coordinates for the left/right eyes. The polynomial is applied to the
x and y component of the left and right eyes separately.
Replicates MATLAB function Datapixx('GetCalibrationCoeff');
Returns:
list:
elements 0: 8 are for the x component of the right eye
elements 9:18 are for the y component of the right eye
elements 19:26 are for the x component of the left eye
elements 27:35 are for the y component of the left eye
:Low-level C definition:
``void TPxGetCalibCoeffs(double* pupilSize)``
"""
coeffs = (ctypes.c_double * 36)(* [.0]*36)
_TPxGetCalibCoeffs(coeffs)
return coeffs[:]
#void TpxGetEyePositionFromBuiltInCalibration(double* eyeReturn)
_TPxGetEyePositionFromBuiltInCalibrationCall = DPxDll['TPxGetEyePositionFromBuiltInCalibration']
_TPxGetEyePositionFromBuiltInCalibrationCall.restype = None
_TPxGetEyePositionFromBuiltInCalibrationCall.argtypes = [(ctypes.c_double *4), (ctypes.c_double *2), (ctypes.c_double)]
[docs]def TPxGetEyePositionFromBuiltInCalibration():
"""Get Eye position specifically from the built-in calibration for TPx mini
Returns:
Tuple with
eyePosition a list of [xLeftEye, yLeftEye, xRightEye, yRightEye]
pupil_size a list of [leftDiameter, rightDiameter]
tracking_distance is the current distance (cm) between TPx and eye
:Low-level C definition:
``void TpxGetEyePositionFromBuiltInCalibration(double* eyeReturn)``
"""
eyePosition = (ctypes.c_double * 4)(* [0.0]*4)
pupil_size = (ctypes.c_double * 2)(* [0.0]*2)
tracking_distance = ctypes.c_double(0)
_TPxGetEyePositionFromBuiltInCalibrationCall(eyePosition, pupil_size, tracking_distance)
return (eyePosition[:], pupil_size[:], tracking_distance.value)
# void TPxFinishCalibration();
_TPxBestPolyFinishCalibrationCall = DPxDll['TPxBestPolyFinishCalibration']
_TPxBestPolyFinishCalibrationCall.restype = None
[docs]def TPxBestPolyFinishCalibration():
""" Finishes the calibration on the Device.
This function is to be called when you are done displaying stimuli for calibration. It will calculate the calibrations parameter
on the device and set the state to calibrated (which can be verified through ``isDeviceCalibrated``.
:Low-level C definition:
``void TPxFinishCalibration()``
"""
return _TPxBestPolyFinishCalibrationCall()
# int TPxIsDeviceCalibrated();
_TPxIsDeviceCalibratedCall = DPxDll['TPxIsDeviceCalibrated']
_TPxIsDeviceCalibratedCall.restype = ctypes.c_int
[docs]def TPxIsDeviceCalibrated():
""" Returns the calibrated state of the tracker.
Returns:
int: True (1) when tracked has been successfully calibrated, False (0) otherwise.
:Low-level C definition:
``int TPxIsDeviceCalibrated()``
"""
calStatus = _TPxIsDeviceCalibratedCall()
if(calStatus == 0):
return False
else:
return True
return calStatus
#void TPxSaveCalibration();
_TPxSaveCalibrationCall = DPxDll['TPxSaveCalibration']
_TPxSaveCalibrationCall.restype = None
[docs]def TPxSaveCalibration():
"""Save last executed calibration to tracker
:Low-level C definition:
``void TPxSaveCalibration()``
"""
print("TPxSaveCalibration")
_TPxSaveCalibrationCall()
#void TPxLoadCalibration();
_TPxLoadCalibrationCall = DPxDll['TPxLoadCalibration']
_TPxLoadCalibrationCall.restype = None
[docs]def TPxLoadCalibration():
"""Load calibration saved to tracker
:Low-level C definition:
``void TPxLoadCalibration()``
"""
print("loadCalibration")
_TPxLoadCalibrationCall()
#void TPxClearDeviceCalibration(void)
_TPxClearDeviceCalibrationCall = DPxDll['TPxClearDeviceCalibration']
_TPxClearDeviceCalibrationCall.restype = None
[docs]def TPxClearDeviceCalibration():
"""Clear calibration from tracker, making device not calibrated
:Low-level C definition:
``void TPxClearDeviceCalibration()``
"""
_TPxClearDeviceCalibrationCall()
# coefficients are not available from Python yet. After tracker C code architecture review, we will consider making this function avaialable
# GetCoefficientFromTracker = DPxDll['DPxGetCoefficientsFromTracker']
# GetCoefficientFromTracker.restype = None
# def DPxGetCoefficientsFromTracker():
# """Load calibration saved to tracker
#
# Args:
# ptrCoeffXA (double*): pointer to the 2-d array containing x axis coefficients for both eyes
# ptrCoeffYA (double*): pointer to the 2-d array containing y axis coefficients for both eyes
# ptrCoeffXB (double*): pointer to the 2-d array containing x axis coefficients for both eyes on the 2nd camera
# ptrCoeffYB (double*): pointer to the 2-d array containing y axis coefficients for both eyes on the 2nd camera
# numOfCoeffs (uint): number of coefficients per polynomial
#
#
# :Low-level C definition:
# ``void DPxSetCoefficientsInTracker(double* ptrCoeffXA, double* ptrCoeffYA, double* ptrCoeffXB, double* ptrCoeffYB, unsigned int numOfCoeffs)``
# """
# print "loadCalibration"
# loadCalibration()
# coefficients are not available from Python yet. After tracker C code architecture review, we will consider making this function avaialable
# SetCoefficientToTracker = DPxDll['DPxSetCoefficientsInTracker']
# SetCoefficientToTracker.restype = None
# def DPxSetCoefficientsInTracker():
# """Save last executed calibration to tracker
#
# Args:
# ptrCoeffXA (double*): pointer to the 2-d array containing x axis coefficients for both eyes
# ptrCoeffYA (double*): pointer to the 2-d array containing y axis coefficients for both eyes
# ptrCoeffXB (double*): pointer to the 2-d array containing x axis coefficients for both eyes on the 2nd camera
# ptrCoeffYB (double*): pointer to the 2-d array containing y axis coefficients for both eyes on the 2nd camera
# numOfCoeffs (uint): number of coefficients per polynomial
#
#
# :Low-level C definition:
# ``void DPxGetCoefficientsFromTracker(double* ptrCoeffXA, double* ptrCoeffYA, double* ptrCoeffXB, double* ptrCoeffYB, unsigned int numOfCoeffs)``
# """
# print "saveCalibration"
# saveCalibration()
_TPxShowOverlayCall = DPxDll['TPxShowOverlay']
_TPxShowOverlayCall.restype = None
[docs]def TPxShowOverlay():
"""Activate Datapixx3 Overlay to display the eye image and eye cursors on monitor
:Low-level C definition:
``void TPxShowOverlay()``
"""
print("Show Overlay")
_TPxShowOverlayCall()
#void TPxHideOverlay()
_TPxHideOverlayCall = DPxDll['TPxHideOverlay']
_TPxHideOverlayCall.restype = None
[docs]def TPxHideOverlay():
"""Deactivate Datapixx3 Overlay to hide the eyes image and eye cursors
:Low-level C definition:
``void TPxHideOverlay()``
"""
_TPxHideOverlayCall()
#void TPxSetSleepPictureRequest()
_TPxSetSleepPictureRequestCall = DPxDll['TPxSetSleepPictureRequest']
_TPxSetSleepPictureRequestCall.restype = None
[docs]def TPxSetSleepPictureRequest():
"""Put tracker to sleep by deactivating the picture request thus turning off the IR
:Low-level C definition:
``void TPxSetSleepPictureRequest()``
"""
return _TPxSetSleepPictureRequestCall()
#void TPxSetAwakePictureRequest()
_TPxSetAwakePictureRequestCall = DPxDll['TPxSetAwakePictureRequest']
_TPxSetAwakePictureRequestCall.restype = None
[docs]def TPxSetAwakePictureRequest():
"""Awake tracker by activating the picture request thus turning on the IR
:Low-level C definition:
``void TPxSetAwakePictureRequest()``
"""
_TPxSetAwakePictureRequestCall()
#int TPxIsAwakePictureRequest()
_TPxIsAwakePictureRequestCall = DPxDll['TPxIsAwakePictureRequest']
_TPxIsAwakePictureRequestCall.restype = ctypes.c_int
[docs]def TPxIsAwakePictureRequest():
"""Return True if tracker is awake
:Low-level C definition:
``void TPxSetAwakePictureRequest()``
"""
return _TPxIsAwakePictureRequestCall()
# void TPxSetupTPxSchedule(unsigned int buffBaseAddr, unsigned int numBuffFrames)
_TPxSetupTPxScheduleCall = DPxDll['TPxSetupTPxSchedule']
_TPxSetupTPxScheduleCall.restype = None
[docs]def TPxSetupTPxSchedule(buffBaseAddr = 0, numBuffFrames = 7200000):
"""Setup a schedule
Args:
buffBaseAddr (int): Any positive value equal to or greater than zero.
numBuffFrames (int): Specify the the frame count to get.
:Low-level C definition:
`` void TPxSetupTPxSchedule(unsigned int buffBaseAddr, unsigned int numBuffFrames)``
"""
_TPxSetupTPxScheduleCall(ctypes.c_uint(buffBaseAddr), ctypes.c_uint(numBuffFrames))
#unsigned TPxGetBuffWriteAddr(void)
_TPxGetBuffWriteAddrCall = DPxDll['TPxGetBuffWriteAddr']
_TPxGetBuffWriteAddrCall.restype = ctypes.c_uint
[docs]def TPxGetBuffWriteAddr():
"""Get RAM address to which next DATAPixx3 datum will be written
Returns:
int: Address of the next DATAPixx3 datum (int32)
:Low-level C definition:
`unsigned TPxGetBuffWriteAddr(void)``
"""
return _TPxGetBuffWriteAddrCall()
#unsigned TPxGetBuffSize()
_TPxGetBuffSizeCall = DPxDll['TPxGetBuffSize']
_TPxGetBuffSizeCall.restype = ctypes.c_uint
[docs]def TPxGetBuffSize():
""" Get DATAPixx3 RAM TPx buffer size in bytes
Returns:
int: Buffer size in bytes. (int32)
:Low-level C definition:
``unsigned TPxGetBuffSize()``
"""
return _TPxGetBuffSizeCall()
#unsigned TPxGetBuffBaseAddr()
_TPxGetBuffBaseAddrCall = DPxDll['TPxGetBuffBaseAddr']
_TPxGetBuffBaseAddrCall.restype = ctypes.c_uint
[docs]def TPxGetBuffBaseAddr():
"""Get DATAPixx3 RAM buffer start address
Returns:
int: Address of RAM buffer (int32)
:Low-level C definition:
``unsigned TPxGetBuffBaseAddr()``
"""
return _TPxGetBuffBaseAddrCall()
#int TPxGetTrackerScheduleFrameLength()
_TPxGetTrackerScheduleFrameLengthCall = DPxDll['TPxGetTrackerScheduleFrameLength']
_TPxGetTrackerScheduleFrameLengthCall.restype = ctypes.c_uint
_TPxGetTrackerScheduleFrameLengthCall.argtypes = [ctypes.c_uint]
[docs]def TPxGetTrackerScheduleFrameLength(firmwareRev):
""" Get the tracker schedule frame length for the actual device.
:low-level C definition:
``int TPxGetTrackerScheduleFrameLength()``
"""
return _TPxGetTrackerScheduleFrameLengthCall(firmwareRev)
#void TPxReadTPxData(uint addr, double* packed_data, uint numberOfFrames)
_TPxReadTPxDataCall = DPxDll['TPxReadTPxData']
_TPxReadTPxDataCall = DPxDll['TPxReadTPxData']
_TPxReadTPxDataCall.restype = None
[docs]def TPxReadTPxData(addr, readFrames = -1):
"""Retreive data acquired by the scheduler.
Args:
addr (unsigned int): Set to a number less than the total amount of memory available.
readFrames (unsigned int): -1 for all acquired data, positive for specific amount.
Returns:
List: a list of four elements
[0] = Acquired data
[1] = Current read address
[2] = Underflow flag, set to 1 when underflow
[3] = Overflow flag, set to 1 when overflow.
[4] = Read frame count (which should correspond to result[0].size())
:Low-level C definition:
``void TPxReadTPxData(uint addr, double* packed_data, uint numberOfFrames)``
"""
overflow = 0
underflow = 0
uiFirmwareRev = DPxGetFirmwareRev()
frameSize = TPxGetTrackerScheduleFrameLength(uiFirmwareRev)
writeAddr = TPxGetBuffWriteAddr();
if (addr > writeAddr) :
overflow = 1
numBuffFrames = (writeAddr + TPxGetBuffSize() - addr) // frameSize
else :
numBuffFrames = (writeAddr - addr) // frameSize
if (readFrames == -1) :
readFrames = numBuffFrames
elif (numBuffFrames < readFrames) :
underflow = 1
readFrames = numBuffFrames
numBuffFloats = readFrames * 22 # 22 being the number of elements per frame
float_list = [0.0] * numBuffFloats
packed_data = (ctypes.c_double * numBuffFloats)(*float_list)
_TPxReadTPxDataCall(ctypes.c_uint(addr), packed_data, ctypes.c_uint(readFrames))
retVal = [0.0] * numBuffFloats
for i in range(0, numBuffFloats):
retVal[i] = packed_data[i]
numBuffBytes = readFrames * frameSize
'''After that, we need to fix the new readAddr
4 cases:
1: No under/over: read = read + numBuffBytes
2: Overflow only: read = read + numBuffBytes (We might still be overflowing after, but its okay!)
3: Underflow only: read = write
4: Overflow AND underflow: read = baseAddr
'''
if overflow > 0 :
if underflow > 0 :
addr = TPxGetBuffBaseAddr()
else :
addr += numBuffBytes;
elif underflow > 0 :
addr = writeAddr;
else : #case 1
addr += numBuffBytes;
return (retVal, addr, underflow, overflow, readFrames)
#void TPxConvertCoordSysToCartesian(double * inPtrX, double * inPtrY, int inSize, double scaleX, double offsetX, double scaleY, double offsetY, double * outPtrX, double * outPtrY)
_TPxConvertCoordSysToCartesianCall = DPxDll['TPxConvertCoordSysToCartesian']
_TPxConvertCoordSysToCartesianCall.restype = None
[docs]def TPxConvertCoordSysToCartesian(inList, scaleX = 1, offsetX = -960, scaleY = 1, offsetY = -540):
"""Convert custom coordinate to system coordinate
Args:
inList (List): List of coordinates to convert.
scaleX (int) : Scaling factor of the horizontal axis. Should be 1 most of the time
scaleY (int) : Scaling factor of the vertical axis. Should be 1 if the origin is at bottom
of the screen and -1 if the origin is at the top
offsetX (int) : x axis offset of the custom system origin from the center of the screen
offsetY (int) : y axis offset of the custom system origin from the center of the screen
using the Cartesian system with origin at center of the screen
:Low-level C definition:
`void TPxConvertCoordSysToCartesian(double * inPtrX, double * inPtrY, int inSize, double scaleX, double offsetX, double scaleY, double offsetY, double * outPtrX, double * outPtrY)``
"""
listSize = len(inList)
float_list = [0.0] * listSize
tempListX = [0.0] * listSize
tempListY = [0.0] * listSize
for i in range(0, listSize):
tempListX[i] = inList[i][0]
tempListY[i] = inList[i][1]
srcPtrX = (ctypes.c_double * listSize)(*tempListX)
srcPtrY = (ctypes.c_double * listSize)(*tempListY)
resPtrX = (ctypes.c_double * listSize)(*float_list)
resPtrY = (ctypes.c_double * listSize)(*float_list)
_TPxConvertCoordSysToCartesianCall(srcPtrX, srcPtrY, ctypes.c_int(listSize), ctypes.c_double(scaleX), ctypes.c_double(offsetX), ctypes.c_double(scaleY), ctypes.c_double(offsetY), resPtrX, resPtrY)
resList = [[0.0, 0.0]] * listSize
for i in range(0, listSize):
resList[i] = [resPtrX[i], resPtrY[i]]
return resList
#void TPxConvertCoordSysToCustom(double * inPtrX, double * inPtrY, int inSize, double scaleX, double offsetX, double scaleY, double offsetY, double * outPtrX, double * outPtrY)
_TPxConvertCoordSysToCustomCall = DPxDll['TPxConvertCoordSysToCustom']
_TPxConvertCoordSysToCustomCall.restype = None
[docs]def TPxConvertCoordSysToCustom(inList, scaleX = 1, offsetX = -960, scaleY = 1, offsetY = -540):
"""Convert system coordinate to custom coordinate
Args:
inList (List): List of coordinates to convert.
scaleX (int) : Scaling factor of the horizontal axis. Should be 1 most of the time.
scaleY (int) : Scaling factor of the vertical axis. Should be 1 if the origin is at bottom
of the screen and -1 if the origin is at the top.
offsetX (int) : x axis offset of the custom system origin from the center of the screen.
offsetY (int) : y axis offset of the custom system origin from the center of the screen.
using the Cartesian system with origin at center of the screen
:Low-level C definition:
``void TPxConvertCoordSysToCustom(double * inPtrX, double * inPtrY, int inSize, double scaleX, double offsetX, double scaleY, double offsetY, double * outPtrX, double * outPtrY)``
"""
listSize = len(inList)
float_list = [0.0] * listSize
tempListX = [0.0] * listSize
tempListY = [0.0] * listSize
for i in range(0, listSize):
tempListX[i] = inList[i][0]
tempListY[i] = inList[i][1]
srcPtrX = (ctypes.c_double * listSize)(*tempListX)
srcPtrY = (ctypes.c_double * listSize)(*tempListY)
resPtrX = (ctypes.c_double * listSize)(*float_list)
resPtrY = (ctypes.c_double * listSize)(*float_list)
_TPxConvertCoordSysToCustomCall(srcPtrX, srcPtrY, ctypes.c_int(listSize), ctypes.c_double(scaleX), ctypes.c_double(offsetX), ctypes.c_double(scaleY), ctypes.c_double(offsetY), resPtrX, resPtrY)
resList = [[0.0, 0.0]] * listSize
for i in range(0, listSize):
resList[i] = [resPtrX[i], resPtrY[i]]
return resList
[docs]def TPxGetEyeImage():
"""
Returns a static image from the TRACKPixx3 camera feed. Duplicates MATLAB function Datapixx('GetEyeImage').
Returns:
numpy.ndarray of size (512,1280) and of type uint8
"""
DPxSelectDevice('DATAPixx3')
(addr,n,m) = TPxGetImagePtr() # (addr,512,1280)
im = DPxReadRam(TPX_IMG_ADDR,n*m//2) # DPxRAM encodes 16 bit elements, the first and second set of 8 bits encodes a different pixel. so n pixels is encoded by n/2 elements returned by ReadRAM
DPxSelectDevice('Auto')
# convert 16 bit pixel pairs into single 8bit pixels, reshape to n by m matrix, cast to bytes, return
return np.dstack(( im&0xFF, im&0xFF00>>8 )).squeeze().flatten().reshape(n,m).astype('uint8')
#int TPxSaveImages();
_TPxSaveImagesCall = DPxDll['TPxSaveImages']
_TPxSaveImagesCall.restype = ctypes.c_int
[docs]def TPxSaveImages ():
""" Write 16 Images at base address
Returns:
int: The address of the first frame.
:Low-level C definition:
``int TPxSaveImages()``
"""
return _TPxSaveImagesCall()
#int TPxSaveImageBaseAddr();
_TPxSaveImageBaseAddrCall = DPxDll['TPxSaveImageBaseAddr']
_TPxSaveImageBaseAddrCall.restype = ctypes.c_int
[docs]def TPxSaveImageBaseAddr ():
"""Save the images to RAM
Returns:
int: The adress of the first frame.
:Low-level C definition:
``int TPxSaveImages()``
"""
return _TPxSaveImageBaseAddrCall()
#int TPxSaveImageGap();
_TPxSaveImageGapCall = DPxDll['TPxSaveImageGap']
_TPxSaveImageGapCall.restype = ctypes.c_int
[docs]def TPxSaveImageGap ():
"""Return the size of one image in RAM.
Returns:
int: the size of image in bytes
:Low-level C definition:
``int TPxSaveImageGap()``
"""
return _TPxSaveImageGapCall()
#void TPxDisableSearchLimits(void)
_TPxDisableSearchLimitsCall = DPxDll['TPxDisableSearchLimits']
_TPxDisableSearchLimitsCall.restype = None
[docs]def TPxDisableSearchLimits():
"""Disable search limits
:Low-level C definition:
``void TPxDisableSearchLimits(void)``
"""
_TPxDisableSearchLimitsCall()
#void TPxEnableSearchLimits(void)
_TPxEnableSearchLimitsCall = DPxDll['TPxEnableSearchLimits']
_TPxEnableSearchLimitsCall.restype = None
[docs]def TPxEnableSearchLimits():
"""Enable search limit
:Low-level C definition:
``void TPxEnableSearchLimits(void)``
"""
_TPxEnableSearchLimitsCall()
#void TPxSetSearchLimits(unsigned short left_eye[4], unsigned short right_eye[4])
_TPxSetSearchLimitsCall = DPxDll['TPxSetSearchLimits']
_TPxSetSearchLimitsCall.restype = None
#_TPxSetSearchLimitsCall.argtypes = [ctypes.c_ushort]
[docs]def TPxSetSearchLimits(left_eye, right_eye):
"""Set search limits
:Low-level C definition:
``void TPxSetSearchLimits(void)``
"""
c_left_eye = (ctypes.c_ushort * 4) (*map(int,left_eye))
c_right_eye = (ctypes.c_ushort * 4) (*map(int,right_eye))
_TPxSetSearchLimitsCall(c_left_eye, c_right_eye)
#--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#void TPxGetSearchLimits(unsigned short left_eye[4], unsigned short right_eye[4])
_TPxGetSearchLimitsCall = DPxDll['TPxGetSearchLimits']
_TPxGetSearchLimitsCall.restype = None
_TPxGetSearchLimitsCall.argtypes = [(ctypes.c_ushort*4), (ctypes.c_ushort*4)]
[docs]def TPxGetSearchLimits():
"""Gets the search limits
:Low-level C definition:
``void TPxGetSearchLimits(void)``
"""
left_eye = (ctypes.c_ushort * 4)(* [0]*4)
right_eye = (ctypes.c_ushort * 4)(* [0]*4)
_TPxGetSearchLimitsCall(left_eye, right_eye)
return (left_eye[:], right_eye[:])
_TPxClearSearchLimits = DPxDll['TPxClearSearchLimits']
_TPxClearSearchLimits.restype = ctypes.c_int
_TPxClearSearchLimits.argtypes = None
[docs]def TPxClearSearchLimits():
"""Clear the TPx search limits
:Low-level C definition:
``void TPxClearSearchLimits(void)``
"""
return _TPxClearSearchLimits()
#void TPxGetPupilsCenter(uint32_t *left_x, uint32_t *left_y, uint32_t *right_x, uint32_t *right_y)
_TPxGetPupilsCenterCall = DPxDll['TPxGetPupilsCenter']
_TPxGetPupilsCenterCall.restype = None
[docs]def TPxGetPupilsCenter():
"""Return the pupiles center
:Low-level C definition:
``void TPxGetPupilsCenter(uint32_t *left_x, uint32_t *left_y, uint32_t *right_x, uint32_t *right_y)``
"""
left_x = ctypes.c_int32()
left_y = ctypes.c_int32()
right_x = ctypes.c_int32()
right_y = ctypes.c_int32()
_TPxGetPupilsCenterCall(ctypes.byref(left_x), ctypes.byref(left_y), ctypes.byref(right_x), ctypes.byref(right_y))
return left_x.value, left_y.value, right_x.value, right_y.value
_TPxSetIrisExpectedSizeCall = DPxDll['TPxSetIrisExpectedSize']
_TPxSetIrisExpectedSizeCall.restype = None
_TPxSetIrisExpectedSizeCall.argtypes = [ctypes.c_int]
[docs]def TPxSetIrisExpectedSize(size):
""" Set the Iris expected size to the DP3 and the TPx in pixel as required
:Low-level C definition:
``void TPxSetIrisExpectedSize(int irisExcpectedSize)``
"""
_TPxSetIrisExpectedSizeCall(size)
_TPxGetIrisExpectedSizeCall = DPxDll['TPxGetIrisExpectedSize']
_TPxGetIrisExpectedSizeCall.restype = ctypes.c_int
[docs]def TPxGetIrisExpectedSize():
""" Get the Iris expected size in pixel from the DP3
:Low-level C definition:
``int TPxGetIrisExpectedSize()``
"""
return _TPxGetIrisExpectedSizeCall()
_TPxSetLEDIntensityCall = DPxDll['TPxSetLEDIntensity']
_TPxSetLEDIntensityCall.restype = None
_TPxSetLEDIntensityCall.argtypes = [ctypes.c_uint]
[docs]def TPxSetLEDIntensity(intensity):
""" Set the infrared LED array intensity
:Low-level C definition:
``void TPxSetLEDIntensity(unsigned int intensity)``
"""
_TPxSetLEDIntensityCall(intensity)
_TPxGetLEDIntensityCall = DPxDll['TPxGetLEDIntensity']
_TPxGetLEDIntensityCall.restype = ctypes.c_uint
[docs]def TPxGetLEDIntensity():
""" Get the infrared LED array intensity value
:Low-level C definition:
``unsigned int TPxGetLEDIntensity()``
"""
return _TPxGetLEDIntensityCall()
#double TPXGetTime()
_TPxGetTimeCall = DPxDll['TPxGetTime']
_TPxGetTimeCall.restype = ctypes.c_double
[docs]def TPxGetTime():
"""Return the timestamp related to the tracker
:Low-level C definition:
``double TPXGetTime()``
"""
timestamp = ctypes.c_double(0)
timestamp = _TPxGetTimeCall()
return timestamp
#double TPxGetHorizontalFOV();
_TPxGetHorizontalFOV = DPxDll['TPxGetHorizontalFOV']
_TPxGetHorizontalFOV.restype = ctypes.c_double
[docs]def TPxGetHorizontalFOV():
"""Returns the horizontal field of view according to distance and lens saved to system.
:low-level C definition:
``double TPxGetHorizontalFOV()``
"""
fov_h = ctypes.c_double(0)
fov_h = _TPxGetHorizontalFOV()
return fov_h
#double TPxGetVerticalFOV();
_TPxGetVerticalFOV = DPxDll['TPxGetVerticalFOV']
_TPxGetVerticalFOV.restype = ctypes.c_double
[docs]def TPxGetVerticalFOV():
"""Returns the vertical field of view according to distance and lens saved to system.
:low-level C definition:
``double TPxGetVerticalFOV()``
"""
fov_v = ctypes.c_double(0)
fov_v = _TPxGetVerticalFOV()
return fov_v
#double TPxGetPixelSize();
_TPxGetPixelSize = DPxDll['TPxGetPixelSize']
_TPxGetPixelSize.restype = ctypes.c_double
[docs]def TPxGetPixelSize():
"""Returns the size represented by 1 pixel according to distance and lens saved to the system.
:low-level C definition:
``double TPxGetPixelSize()``
"""
pxSize = ctypes.c_double(0)
pxSize = _TPxGetPixelSize()
return pxSize
#double TPxGetPixelDensity();
_TPxGetPixelDensity = DPxDll['TPxGetPixelDensity']
_TPxGetPixelDensity.restype = ctypes.c_double
[docs]def TPxGetPixelDensity():
"""Returns the number of pixels it takes to represent an object of 1 mm according to distance and lens saved to the system.
:low-level C definition:
``double TPxGetPixelDensity()``
"""
pxDensity = ctypes.c_double(0)
pxDensity = _TPxGetPixelDensity()
return pxDensity
#void TPxSetDistance(unsigned int distance);
_TPxSetDistance = DPxDll['TPxSetDistance']
_TPxSetDistance.argtypes = [ctypes.c_uint]
_TPxSetDistance.restype = None
[docs]def TPxSetDistance(distance):
"""Set the tracking distance of the setup in centimeter.
Distance should be taken perpendicularly from the plan parralel to the lens, passing by the subject's eyes up to about 1 cm behind the tip of the lens.
Args:
distance (unsigned int): distance, in cm, between the camera and a parallel plan passing by the eyes of the subject.
:low-level C definition:
``void TPxSetDistance(unsigned int distance)``
"""
_TPxSetDistance(distance)
#unsigned int TPxGetDistance();
_TPxGetDistance = DPxDll['TPxGetDistance']
_TPxGetDistance.restype = ctypes.c_uint
[docs]def TPxGetDistance():
"""Get the tracking distance saved to the system.
:low-level C definition:
``unsigned int TPxGetDistance()``
"""
return _TPxGetDistance()
#void TPxSetLens(unsigned int lens);
_TPxSetLens = DPxDll['TPxSetLens']
_TPxSetLens.argtypes = [ctypes.c_uint]
_TPxSetLens.restype = None
[docs]def TPxSetLens(lens):
"""Set the lens type used in the setup.
Args:
lens : lens type used in the setup
Accepted values are:
- 0 (25 mm)
- 1 (50 mm)
- 2 (75 mm)
:low-level C definition:
``void TPxSetLens(unsigned int lens)``
"""
_TPxSetLens(lens)
#unsigned int TPxGetLens();
_TPxGetLens = DPxDll['TPxGetLens']
_TPxGetLens.restype = ctypes.c_uint
[docs]def TPxGetLens():
"""Get the lens type saved to the system.
:low-level C definition:
``unsigned int TPxGetLens()``
"""
return _TPxGetLens()
_TPxSetFixationSamples = DPxDll['TPxSetFixationSamples']
_TPxSetFixationSamples.argtypes = [ctypes.c_uint]
_TPxSetFixationSamples.restype = None
def TPxSetFixationSamples(sample):
return _TPxSetFixationSamples(sample)
_TPxSetFixationSpeed = DPxDll['TPxSetFixationSpeed']
_TPxSetFixationSpeed.argtypes = [ctypes.c_float]
_TPxSetFixationSpeed.restype = None
def TPxSetFixationSpeed(speed):
return _TPxSetFixationSpeed(speed)
_TPxSetSaccadeSamples = DPxDll['TPxSetSaccadeSamples']
_TPxSetSaccadeSamples.argtypes = [ctypes.c_uint]
_TPxSetSaccadeSamples.restype = None
def TPxSetSaccadeSamples(sample):
return _TPxSetSaccadeSamples(sample)
_TPxSetSaccadeSpeed = DPxDll['TPxSetSaccadeSpeed']
_TPxSetSaccadeSpeed.argtypes = [ctypes.c_float]
_TPxSetSaccadeSpeed.restype = None
def TPxSetSaccadeSpeed(speed):
return _TPxSetSaccadeSpeed(speed)
_TPxTrackingMode = DPxDll['TPxTrackingMode']
_TPxTrackingMode.argtypes = [ctypes.c_int, ctypes.c_ubyte]
_TPxTrackingMode.restype = None
def TPxTrackingMode(setter, mode):
return _TPxTrackingMode(setter, mode)
_TPxSpecies = DPxDll['TPxSpecies']
_TPxSpecies.argtypes = [ctypes.c_int, ctypes.c_ubyte]
_TPxSpecies.restype = None
def TPxSpecies(setter,mode):
return _TPxSpecies(setter, mode)
_TPxGetDataMini = DPxDll['TPxGetDataMini']
_TPxGetDataMini.restype = ctypes.c_double
[docs]def TPxMiniGetData():
""" Gets the following information:\n
timestamp, x_left, y_left, pp_size_left, x_right, y_right, pp_size_right, distance\n
This function can only be called once you have done a built-in calibration (remote)
Returns:
list: List containing timestamp, x_left, y_left, pp_size_left, x_right, y_right, pp_size_right, distance
:Low-level C definition:
``double TPxGetDataMini(double*)``
"""
intList = [0.0]*8
miniData = (ctypes.c_double * 8)(*intList)
_TPxGetDataMini(miniData)
return [i for i in miniData]
_TPxPpSizeCalibrationGetEyeData = DPxDll['TPxPpSizeCalibrationGetEyeData']
_TPxPpSizeCalibrationGetEyeData.restype = None
[docs]def TPxPpSizeCalibrationGetEyeData():
""" Starts gathering data for the pupil size calibration
:Low-level C definition:
``void TPxPpSizeCalibrationGetEyeData()``
"""
_TPxPpSizeCalibrationGetEyeData()
_TPxPpSizeCalibrationDoneGatheringData = DPxDll['TPxPpSizeCalibrationDoneGatheringData']
_TPxPpSizeCalibrationDoneGatheringData.restype = None
[docs]def TPxPpSizeCalibrationDoneGatheringData():
""" Stops gathering data for the pupil size calibration
:low-level C definition:
``void TPxPpSizeCalibrationDoneGatheringData()``
"""
_TPxPpSizeCalibrationDoneGatheringData()
_TPxPpSizeCalibrationLinearRegression = DPxDll['TPxPpSizeCalibrationLinearRegression']
_TPxPpSizeCalibrationLinearRegression.restype = None
[docs]def TPxPpSizeCalibrationLinearRegression():
""" Analyze the data gathered and extract linear regression slope that will serve as a
normalization factor for the pupil size calibration
:low-level C definition:
``void TPxPpSizeCalibrationLinearRegression()``
"""
_TPxPpSizeCalibrationLinearRegression()
_TPxPpSizeCalibrationApply = DPxDll['TPxPpSizeCalibrationApply']
_TPxPpSizeCalibrationApply.restype = ctypes.c_double
_TPxPpSizeCalibrationApply.argtypes = [ctypes.c_double, ctypes.c_double, ctypes.c_double, ctypes.c_double]
[docs]def TPxPpSizeCalibrationApply(slope, pp_size_norm, pp_size, raw):
""" Apply pupil size calibration to raw data from the camera.
Note that the pupil size calibration is applied directly in the FPGA. This function is used only as reference.
Formula : rawNorm = slope * (ppSizeNorm - ppSize) + raw
:low-level C definition:
``double TPxPpSizeCalibrationApply(double slope, double ppSizeNorm, double ppSize, double raw)``
"""
return _TPxPpSizeCalibrationApply(slope, pp_size_norm, pp_size, raw)
_TPxIsPpSizeCalibrated = DPxDll['TPxIsPpSizeCalibrated']
_TPxIsPpSizeCalibrated.restype = ctypes.c_int
[docs]def TPxIsPpSizeCalibrated():
""" Return pupil size calibration state.
:low-level C definition:
``int TPxIsPpSizeCalibrated()``
"""
calStatus = _TPxIsPpSizeCalibrated()
if(calStatus == 0):
return False
else:
return True
_TPxPpSizeCalibrationClear = DPxDll['TPxPpSizeCalibrationClear']
_TPxPpSizeCalibrationClear.restype = None
[docs]def TPxPpSizeCalibrationClear():
""" Clear the pupil size calibartion.
:low-level C definition
``void TPxPpSizeCalibrationClear()``
"""
_TPxPpSizeCalibrationClear()
_TPxPpSizeCalibrationSet = DPxDll['TPxPpSizeCalibrationSet']
_TPxPpSizeCalibrationSet.restype = None
[docs]def TPxPpSizeCalibrationSet():
""" Set the pupil size calibration factor found in global variables in the FPGA thus activating pupil size calibration.
:low-level C definition:
``void TPxPpSizeCalibrationSet()``
"""
_TPxPpSizeCalibrationSet()
_TPxPpSizeCalibrationGet = DPxDll['TPxPpSizeCalibrationGet']
_TPxPpSizeCalibrationGet.restype = None
_TPxPpSizeCalibrationGet.argtypes = [ctypes.POINTER(ctypes.c_double)]
[docs]def TPxPpSizeCalibrationGet():
""" Return the pupil calibration factor in an array.
:low-level C definition:
``void TPxPpSizeCalibrationGet(double * ppSizeSlope)``
"""
cal_factor = (ctypes.c_double * 4)
_TPxPpSizeCalibrationGet(ctypes.byref(cal_factor))
return cal_factor
_TPxIsLogTimetags = DPxDll['TPxIsLogTimetags']
_TPxIsLogTimetags.restype = ctypes.c_int
_TPxIsLogTimetags.argtypes = None
_TPxIsFreeRun = DPxDll['TPxIsFreeRun']
_TPxIsFreeRun.restype = ctypes.c_int
_TPxIsFreeRun.argtypes = None
[docs]def TPxIsFreeRun():
""" Query the free-run status of the TPx.
:Low-level C definition:
``int TPxIsFreeRun(void)``
"""
return _TPxIsFreeRun()
_TPxGetTrackerStatus = DPxDll['TPxGetTrackerStatus']
_TPxGetTrackerStatus.restype = ctypes.c_int
_TPxGetTrackerStatus.argtypes = None
[docs]def TPxGetTrackerStatus():
""" Return the DATAPixx3 status flag from registry (DP3REG_TRK_STATUS_FLAG @ 0x59A).
From registry DP3REG_TRK_STATUS_FLAG 0x59A
bit 0 - Blink left
bit 1 - Blink right
bit 2 - Saccade left
bit 3 - Fixation left
bit 4 - Saccade right
bit 5 - Fixation right
bit 6 to 15 - padding
:Low-level C definition:
``int TPxGetTrackerStatus(void)``
"""
return _TPxGetTrackerStatus()
[docs]def TPxIsSubjectMakingSaccade():
"""
Returns two Boolean flags, one for each eye, to indicate whether the subject is currently saccading.
Replicates the behabivor of Datapixx('IsSubjectMakingSaccade')
Returns:
tuple: (leftSaccadeFlag, rightSaccadeFlag) where each element is type(bool)
and indicates whether the left and right eye are currently saccading.
"""
regStatus = TPxGetTrackerStatus()
return bool(regStatus & 2**2), bool(regStatus & 2**4)
[docs]def TPxIsSubjectFixating():
"""
Returns two Boolean flags, one for each eye, to indicate whether the subject is currently fixating.
Replicates the behabivor of Datapixx('IsSubjectFixating')
Returns:
tuple: (leftFixationFlag, rightFixationFlag) where each element is type(bool)
and indicates whether the left and right eye are currently fixating.
"""
regStatus = TPxGetTrackerStatus()
return bool(regStatus & 2**3), bool(regStatus & 2**5)
_TPxSetSaccadeThresholds = DPxDll['TPxSetSaccadeThresholds']
_TPxSetSaccadeThresholds.restype = ctypes.c_int
_TPxSetSaccadeThresholds.argtypes = [ctypes.c_float, ctypes.c_uint]
[docs]def TPxSetSaccadeThresholds(minSpeed=10000.0, minNumberOfConsecutiveSamples=10):
"""
Used to define the thresholds for classifying saccade events.
Replicates the behabivor of Datapixx('SetSaccadeThresholds' [, mainSpeed=10000] [, minNumberOfConsecutiveSamples=10])
Arguments:
minSpeed (float): the eye velocity threshold above which to classify saccades. Uses units of pixels per second
minNumberOfConsecutiveSamples (int): the minimum number of consecutive samples required to classify a saccade event.
"""
return _TPxSetSaccadeThresholds(ctypes.c_float(minSpeed),ctypes.c_uint(minNumberOfConsecutiveSamples))
_TPxSetFixationThresholds = DPxDll['TPxSetFixationThresholds']
_TPxSetFixationThresholds.restype = ctypes.c_int
_TPxSetFixationThresholds.argtypes = [ctypes.c_float, ctypes.c_uint]
[docs]def TPxSetFixationThresholds(maxSpeed=2500.0, minNumberOfConsecutiveSamples=25):
"""
Used to define the thresholds for classifying fixation events.
Replicates the behabivor of Datapixx('SetFixationThresholds' [, maxSpeed=2500] [, minNumberOfConsecutiveSamples=25])
Arguments:
maxSpeed (float): the eye velocity threshold below which to classify fixations. Uses units of pixels per second
minNumberOfConsecutiveSamples (int): the minimum number of consecutive samples required to classify a fixation event.
"""
return _TPxSetFixationThresholds(ctypes.c_float(maxSpeed),ctypes.c_uint(minNumberOfConsecutiveSamples))
[docs]def TPxStartSchedule():
""" Enable TRACKPixx scheduling
"""
TPxEnableFreeRun()
[docs]def TPxStopSchedule():
""" Disable TRACKPixx scheduling
"""
TPxDisableFreeRun()
[docs]def TPxSetupSchedule(bufferbaseAddress=int(12e6), numBuffFrames=int(36e5)):
"""
Set up the base address and buffer size for TRACKPxix recording. Replicates the
behavior of Datapixx('SetupTPxSchedule') in MATLAB. This function must be
proceeded by a call to TPxStartSchedule().
Args:
bufferbaseAddress (int): base address for writing TRACKPixx samples into DATAPixx RAM
default = int(12e6)
numBuffFrames (int): number of frames in DATAPixx RAM allocated for writing TRACKPixx samples
default = int(36e5), which is ~30 minutes of 2KHz recording
Returns:
Dictionary with the following key/entry pairs to indicate TRACKPixx status information:
'isRecording' : (bool) is the acquisition currently running?
'isLogTimetag' : (bool) are we acquiring timetags in addition to eye tracking data?
'bufferBaseAddress' : (int) the acquisition data buffer base address within the Datapixx
'bufferSize' : (int) the number of allocated bytes in the acquisition data buffer
'currentWriteAddr' : (int) the buffer address which will be written by the next acquired TPx sample
'currentReadAddr' : (int) the buffer address which will be read by the next streaming call to TPxReadData
'numBufferFrames' : (int) the total number of samples which fit in the acquisition data buffer
'currentWriteFrame' : (int) the buffer frame which will be written by the next acquired TPx sample
'currentReadFrame' : (int) the buffer frame which will be read by the next call to TPxReadData
'newBufferFrames' : (int) the number of new buffer frames since last call to TPxReadData (i.e., currentWriteFrame - currentReadFrame)
'numStreamUnderflows' : (int) the number of TRACKPixx streaming underflows which have occurred since TPxSetSchedule
'numStreamOverflows' : (int) the number of TRACPixx streaming overflows which have occurred since TPxSetSchedule
Raises:
1) 'bufferbaseAddress' is not an integer or is less than 0 or is not even
2) 'numBuffFrames' is not an integer or is less than 1
3) 'numBuffFrames' exceeds what is available in DATAPixx RAM
"""
# bufferBaseAddress input argument
if not isinstance(bufferbaseAddress,int) or bufferbaseAddress < 0 or bufferbaseAddress & 1:
raise Exception("'bufferBaseAddress' must be an even integer greater than 0")
# bufferSize input argument
if not isinstance(numBuffFrames,int) or numBuffFrames <= 0:
raise Exception("'numberOfEyeData' must be an integer greater than 0")
# determine the frame size
uiFirmwareRev = DPxGetFirmwareRev()
uiFrameSize = TPxGetTrackerScheduleFrameLength(uiFirmwareRev)
# check requested buffer size against size of DPx ram
buffSize = numBuffFrames * uiFrameSize # 32 or 64 bytes datum on the TPx!
if (bufferbaseAddress + buffSize) > DPxGetRamSize():
raise Exception("Specified buffer size exceeds Datapixx RAM.")
TPxSetBuff(bufferbaseAddress, buffSize)
return {'isRecording': 0,
'isLogTimetag': 0,
'bufferBaseAddress' : bufferbaseAddress,
'bufferSize' : buffSize,
'currentWriteAddr' : 0,
'currentReadAddr' : bufferbaseAddress,
'numBufferFrames' : numBuffFrames,
'currentWriteFrame' : 0,
'currentReadFrame' : 0,
'newBufferFrames' : 0,
'numStreamUnderflows' : 0,
'numStreamOverflows' : 0}
[docs]def TPxGetStatus(TPxDict):
"""
Updates a dictionary with entries indicating TRACKPixx status information. This
dictionary is returned by TPxSetupSchedule(). Replicates the behavior of
Datapixx('GetTPxStatus') in MATLAB.
Args:
TPxDict (dict): Returned by TPxSetupSchedule(). Contains the following key/entry pairs:
'isRecording' : (bool) is the acquisition currently running?
'isLogTimetag' : (bool) are we acquiring timetags in addition to eye tracking data?
'bufferBaseAddress' : (int) the acquisition data buffer base address within the Datapixx
'bufferSize' : (int) the number of allocated bytes in the acquisition data buffer
'currentWriteAddr' : (int) the buffer address which will be written by the next acquired TPx sample
'currentReadAddr' : (int) the buffer address which will be read by the next streaming call to TPxReadData
'numBufferFrames' : (int) the total number of samples which fit in the acquisition data buffer
'currentWriteFrame' : (int) the buffer frame which will be written by the next acquired TPx sample
'currentReadFrame' : (int) the buffer frame which will be read by the next call to TPxReadData
'newBufferFrames' : (int) the number of new buffer frames since last call to TPxReadData (i.e., currentWriteFrame - currentReadFrame)
'numStreamUnderflows' : (int) the number of TRACKPixx streaming underflows which have occurred since TPxSetSchedule
'numStreamOverflows' : (int) the number of TRACPixx streaming overflows which have occurred since TPxSetSchedule
"""
# Update dictionary schedule info
TPxDict['isRecording"'] = TPxIsFreeRun()
TPxDict['isLogTimetag'] = TPxIsLogTimetags()
# Get buffer info
baseAddr = TPxGetBuffBaseAddr()
buffSize = TPxGetBuffSize()
uiFirmwareRev = DPxGetFirmwareRev()
uiFrameSize = TPxGetTrackerScheduleFrameLength(uiFirmwareRev)
currentWriteAddr = TPxGetBuffWriteAddr()
currentReadAddr = TPxDict['currentReadAddr']
# Check for warp around cases here
# Dont check for overflow, just say we have until the end of the buffer of data
if currentReadAddr > currentWriteAddr:
newBufferFrames = ((buffSize + baseAddr) - (currentReadAddr)) // uiFrameSize # Assume we have the left over to read
else:
newBufferFrames = (currentWriteAddr - currentReadAddr) // uiFrameSize
currentWriteFrame = (currentWriteAddr - baseAddr) // uiFrameSize
currentReadFrame = (currentReadAddr - baseAddr) // uiFrameSize
# Update dictionary read/write info
TPxDict['currentWriteAddr'] = currentWriteAddr
TPxDict['currentWriteFrame'] = currentWriteFrame
TPxDict['currentReadFrame'] = currentReadFrame
TPxDict['newBufferFrames'] = newBufferFrames
# 'bufferBaseAddress', 'bufferSize', and 'numBufferFrames' are initialized
# in TPxSetupSchedule() and don't need updating
#
# 'currentReadAddr', 'numStreamUnderflows', and 'numStreamOverflows'
# are updated in TPxReadData()
[docs]def TPxReadData(TPxDict, numFrames = None):
"""
Return new TRACKPixx samples from a Datapixx buffer while a TRACKPixx
schedule is running. Replicates the behavior of Datapixx('ReadTPxData') in MATLAB.
Args:
TPxDict (dict): Returned by TPxSetupSchedule(). Contains the following key/entry pairs:
'isRecording' : (bool) is the acquisition currently running?
'isLogTimetag' : (bool) are we acquiring timetags in addition to eye tracking data?
'bufferBaseAddress' : (int) the acquisition data buffer base address within the Datapixx
'bufferSize' : (int) the number of allocated bytes in the acquisition data buffer
'currentWriteAddr' : (int) the buffer address which will be written by the next acquired TPx sample
'currentReadAddr' : (int) the buffer address which will be read by the next streaming call to TPxReadData
'numBufferFrames' : (int) the total number of samples which fit in the acquisition data buffer
'currentWriteFrame' : (int) the buffer frame which will be written by the next acquired TPx sample
'currentReadFrame' : (int) the buffer frame which will be read by the next call to TPxReadData
'newBufferFrames' : (int) the number of new buffer frames since last call to TPxReadData (i.e., currentWriteFrame - currentReadFrame)
'numStreamUnderflows' : (int) the number of TRACKPixx streaming underflows which have occurred since TPxSetSchedule
'numStreamOverflows' : (int) the number of TRACPixx streaming overflows which have occurred since TPxSetSchedule
numFrames (int): Number of new frames to read from DATAPixx RAM. Must be greater than 0.
If omitted, this defaults to reading the entire buffer.
Returns:
bufferData (ndarray): an N x 20 numpy.ndarray where each row is a TRACKPixx sample
and each column corresponds to a particular TRACKPixx metric
enumerated below:
Col# Name Type Description
1 timetag float Time stamp of DATAPixx time in seconds
2 leftScrPosX float Cartesian screen coordinate for x component of left eye in pixels
3 leftScrPosY float Cartesian screen coordinate for y component of left eye in pixels
4 leftPPSize float Diameter of left eye pupil in pixels
5 rightScrPosX float Cartesian screen coordinate for x component of right eye in pixels
6 rightScrPosY float Cartesian screen coordinate for y component of right eye in pixels
7 rightPPSize float Diameter of right eye pupil in pixels
8 DigitalInput int Digital input state in base10
9 leftBlink bool Is left eye blinking?
10 rightBlink bool Is right eye blinking?
11 DigitalOutput int Digital output state in base10
12 leftFixation bool Is left eye fixated?
13 rightFixation bool Is right eye fixated?
14 leftSaccade bool Is left eye saccading?
15 rightSaccade bool Is right eye saccading?
16 messageC int Integer event code sent to DPx (not yet implemented)
17 leftRawX float Pupil-to-corneal reflection vector x component for left eye
18 leftRawY float Pupil-to-corneal reflection vector y component for left eye
19 rightRawX float Pupil-to-corneal reflection vector x component for right eye
20 rightRawY float Pupil-to-corneal reflection vector y component for right eye
"""
# check numFrames input argument
if numFrames is None:
numFrames = -1
elif not isinstance(numFrames,int) or numFrames < 1:
raise Exception("'numFrames' must be an integer > 0")
# the DPx RAM read operations are already defined in pypixxlib._libdpx.TPxReadTPxData()
TPxData, addr, underflow, overflow, _ = TPxReadTPxData(TPxDict['currentReadAddr'], numFrames)
TPxDict['currentReadAddr'] = addr
TPxDict['numStreamUnderflows'] += underflow
TPxDict['numStreamOverflows'] += overflow
return np.array(TPxData,dtype=object).reshape(numFrames,22)[:,0:20]
_TPxMiniGetThreadStatus = DPxDll['TPxMiniGetThreadStatus']
_TPxMiniGetThreadStatus.restype = None
_TPxMiniGetThreadStatus.argtypes = [ctypes.POINTER(ctypes.c_uint8), ctypes.POINTER(ctypes.c_uint32), ctypes.POINTER(ctypes.c_uint32)]
def TPxMiniGetThreadStatus():
outCount = (ctypes.c_uint32 * 1)()
readIndex = (ctypes.c_uint32 * 1)()
threadStatus = (ctypes.c_uint8 * 1)()
_TPxMiniGetThreadStatus(threadStatus, outCount, readIndex)
return threadStatus[0], outCount[0], readIndex[0]
_TPxMiniGetDataServer = DPxDll['TPxMiniGetData']
_TPxMiniGetDataServer.restype = None
_TPxMiniGetDataServer.argtypes = [ctypes.POINTER(ctypes.c_double), ctypes.c_ushort]
[docs]def TPxMiniGetDataServer(numElem):
"""
"""
# the server can process a maximum of 1000 data at once
frameCount = 0
if (numElem == 0):
# process all
status, frameCount, readIndex = TPxMiniGetThreadStatus()
frameCount = (frameCount - readIndex)
else:
frameCount = numElem
readLen = frameCount
if frameCount > 1000:
readLen = 1000
retVal = []
i = 0
while (i < frameCount):
partialEyeData = (ctypes.c_double *( readLen * 8))(*[0]*readLen)
_TPxMiniGetDataServer(partialEyeData, readLen)
i += readLen
for j in range(0, readLen):
tempList = [partialEyeData[8*j+k] for k in range(8)]
retVal.append(tempList)
if ((i + readLen) > frameCount):
readLen = frameCount - i
return retVal
_TPxMiniServerSetUpDataRecording = DPxDll['TPxMiniServerSetUpDataRecording']
_TPxMiniServerSetUpDataRecording.restype = None
_TPxMiniServerSetUpDataRecording.argtypes = [ctypes.c_ushort]
[docs]def TPxMiniServerSetUpDataRecording(numElem):
"""
"""
_TPxMiniServerSetUpDataRecording(numElem)
_TPxMiniRecordData = DPxDll['TPxMiniRecordData']
_TPxMiniRecordData.restype = None
_TPxMiniRecordData.argtypes = None
[docs]def TPxMiniRecordData():
"""
"""
_TPxMiniRecordData()
_TPxMiniStopRecording = DPxDll['TPxMiniStopRecording']
_TPxMiniStopRecording.restype = None
_TPxMiniStopRecording.argtypes = None
[docs]def TPxMiniStopRecording():
""" Return the pupil calibration factor in an array.
:low-level C definition:
``void TPxMiniStopRecording()``
"""
_TPxMiniStopRecording()
_TPxMiniGetEyePosition = DPxDll['TPxMiniGetEyePosition']
_TPxMiniGetEyePosition.restype = None
_TPxMiniGetEyePosition.argtypes = [ctypes.POINTER(ctypes.c_double)]
[docs]def TPxMiniGetEyePosition():
""" Return the last eye position in an array.
:low-level C definition:
``void TPxMiniGetEyePosition(double * lastEyePosition)``
"""
length = 8
int_list = [0]*length
item_count = len(int_list)
packed_data = (ctypes.c_double * item_count)(*int_list)
_TPxMiniGetEyePosition(packed_data)
eyePosition = [packed_data[i] for i in range(0, 8)]
return eyePosition
_TPxMiniSetDownScaleFactor = DPxDll['TPxMiniSetDownScaleFactor']
_TPxMiniSetDownScaleFactor.restype = None
_TPxMiniSetDownScaleFactor.argtypes = [ctypes.c_int]
[docs]def TPxMiniSetDownScaleFactor(scaleFactor = 0):
""" Set the TPxMini downscale factor to a user-specified value.
:low-level C definition:
``void TPxMiniSetDownScaleFactor(int newValue)``
"""
_TPxMiniSetDownScaleFactor(scaleFactor)
_TPxMiniSetScreenProportionCall = DPxDll['TPxMiniSetScreenProportion']
_TPxMiniSetScreenProportionCall.restype = None
_TPxMiniSetScreenProportionCall.argtypes = [ctypes.c_int]
[docs]def TPxMiniSetScreenProportion(screenProportion = 80):
""" Set the TPxMini screen proportion to calibrate.
:low-level C definition:
``void TPxMiniSetScreenProportion(int newValue)``
"""
_TPxMiniSetScreenProportionCall(screenProportion)
_TPxSetTrackerWindowBrightnessCall = DPxDll['TPxSetTrackerWindowBrightness']
_TPxSetTrackerWindowBrightnessCall.restype = None
_TPxSetTrackerWindowBrightnessCall.argtypes = [ctypes.c_int]
[docs]def TPxSetTrackerWindowBrightness(brightness = 200):
""" Set the tracker window brightness.
:low-level C definition:
``void TPxSetTrackerWindowBrightness(int brightness)``
"""
_TPxSetTrackerWindowBrightnessCall(brightness)
_TPxMiniTeardown = DPxDll['TPxMiniTeardown']
_TPxMiniTeardown.restype = ctypes.c_int
_TPxMiniTeardown.argtypes = None
[docs]def TPxMiniTeardown():
""" Teardown the TPx/mini.
:low-level C definition:
``void TPxMiniTeardown(void)``
"""
return _TPxMiniTeardown()
[docs]def TPxCloseTPxMini():
"""
Close the TPx/mini.
Replicates the behavior of Datapixx('CloseTPxMini')
"""
TPxMiniTeardown()
TPxUninitialize()
[docs]def TPxOpenTPxMini(proportion=80):
"""
Replicates the behabivor of Datapixx('OpenTPxMini')
Arguments:
proportion (int): the percentage of the screen to calibrate.
Raises:
1) proportion is outside the interval (40,100) or is not an integer
2) user attempting to use TPx/mini on non-windows machine
3) invalid or missing TPx/mini license file
"""
if not isinstance(proportion,int) or proportion > 100 or proportion < 40:
raise Exception("proportion must be a single integer between 40 and 100")
if sys_platform == 'Windows':
licenseFilePath = 'C:/ProgramData/VPixx Technologies/Licenses/'
else:
raise Exception("TRACKPixx/mini not supportted on %s"%sys_platform)
TPxInitialize(0, licenseFilePath)
TPxMiniSetScreenProportion(proportion)
if DPxGetError() == err['DPX_ERR_TRK_QL_DEVICE_IS_NOT_REGISTERED']:
raise Exception("ERROR ERROR ERROR \n License not installed. Please open PyPixx to install the license. \n ERROR ERROR ERROR")
_TPxInitPWM = DPxDll['TPxInitPWM']
_TPxInitPWM.restype = None
[docs]def TPxInitPWM():
"""Close currently selected VPixx device.
:Low-level C definition:
``void DPxClose()``
"""
_TPxInitPWM()
_TPxSetRobotEyesPositionInPixels = DPxDll['TPxSetRobotEyesPositionInPixels']
_TPxSetRobotEyesPositionInPixels.restype = None
_TPxSetRobotEyesPositionInPixels.argtypes = [ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int]
[docs]def TPxSetRobotEyesPositionInPixels(xL, yL, xR, yR):
"""Close currently selected VPixx device.
:Low-level C definition:
``void DPxClose()``
"""
_TPxSetRobotEyesPositionInPixels( int(xL), int(yL), int(xR), int(yR))
[docs]def DisableTPxAnalogOut():
"""Sets up the Analog out to its default behavior (schedules) instead of TRACKPixx3 data.
"""
TPxSetAllDACOutput(0)
[docs]def EnableTPxAnalogOut(modeDAC0 = 0, modeDAC1 = 0, modeDAC2 = 0, modeDAC3 = 0):
"""Enables Analog Out for TRACKPixx3 data on the DATAPixx3
mode follows this chart:
- 0: Default schedule controlled analog.
- 1: Left eye screen X.
- 2: Right eye screen X.
- 3: Left eye screen Y.
- 4: Right eye screen Y.
- 5: Left eye pupil diameter.
- 6: Right eye pupil diameter.
- 7: Average eye screen X.
- 8: Average eye screen Y.
- 9: Average eye pupil diameter.
- 10: Blink detection flag.
- 11: Left eye raw X.
- 12: Right eye raw X.
- 13: Left eye raw Y.
- 14: Right eye raw Y.
- 15: Left eye saccade & fixation flag.
- 16: Right eye saccade & fixation flag.
:Low-level C definition:
``void TPxSetAllDACOutput(int combinedMode)``
"""
if (modeDAC0 > 16 or modeDAC1 > 16 or modeDAC2 > 16 or modeDAC3 > 16 or\
modeDAC0 < 0 or modeDAC1 < 0 or modeDAC2 < 0 or modeDAC3 < 0):
print("modes must be between 0 and 16")
mode = modeDAC0 + modeDAC1 << 8 + modeDAC2 << 16 + modeDAC2 << 24
TPxSetAllDACOutput(mode)
# void TPxSetAllDACOutput()
_TPxSetAllDACOutput = DPxDll['TPxSetAllDACOutput']
_TPxSetAllDACOutput.restype = None
_TPxSetAllDACOutput.argtypes = [ctypes.c_int]
[docs]def TPxSetAllDACOutput(allChannelValue):
"""Set the DAC value
:Low-level C definition:
`` TPxSetAllDACOutput``
"""
_TPxSetAllDACOutput(int(allChannelValue))
_TPxGetAllDACOutput = DPxDll['TPxGetAllDACOutput']
_TPxGetAllDACOutput.argtypes = [ctypes.c_uint]
[docs]def TPxGetAllDACOutput():
"""Get the analog state.
:low-level C definition:
``unsigned int TPxSetAllDACOutput()``
"""
return _TPxGetAllDACOutput()
_DP3IsTxVideo3DSupported = DPxDll['DP3IsTxVideo3DSupported']
_DP3IsTxVideo3DSupported.argtypes = [ctypes.c_int]
_DP3IsTxVideo3DSupported.restype = None
def DP3IsTxVideo3DSupported(channel):
return _DP3IsTxVideo3DSupported(int(channel))
# TSCOPE NEW FUNCTIONS
_DPxEnablePPxTScopeQuad = DPxDll['DPxEnablePPxTScopeQuad']
_DPxEnablePPxTScopeQuad.argtypes = None
_DPxEnablePPxTScopeQuad.restype = None
[docs]def DPxEnablePPxTScopeQuad():
"""
Only one quadrant of an uploaded image is presented at a time
"""
return _DPxEnablePPxTScopeQuad()
_DPxDisablePPxTScopeQuad = DPxDll['DPxDisablePPxTScopeQuad']
_DPxDisablePPxTScopeQuad.argtypes = None
_DPxDisablePPxTScopeQuad.restype = None
[docs]def DPxDisablePPxTScopeQuad():
"""
The entire uploaded image is presented
"""
return _DPxDisablePPxTScopeQuad()
_DPxEnablePPxGcdShift = DPxDll['DPxEnablePPxGcdShift']
_DPxEnablePPxGcdShift.argtypes = None
_DPxEnablePPxGcdShift.restype = None
[docs]def DPxEnablePPxGcdShift():
"""
PROPixx Gaze-Contingent Display is shifted horizontally and vertically
"""
return _DPxEnablePPxGcdShift()
_DPxDisablePPxGcdShift = DPxDll['DPxDisablePPxGcdShift']
_DPxDisablePPxGcdShift.argtypes = None
_DPxDisablePPxGcdShift.restype = None
[docs]def DPxDisablePPxGcdShift():
"""
PROPixx display is not shifted
"""
return _DPxDisablePPxGcdShift()
_DPxEnablePPxGcdShiftSubframe = DPxDll['DPxEnablePPxGcdShiftSubframe']
_DPxEnablePPxGcdShiftSubframe.argtypes = None
_DPxEnablePPxGcdShiftSubframe.restype = None
[docs]def DPxEnablePPxGcdShiftSubframe():
"""
PROPixx Gaze-Contingent Display can modify image shift on every DLP sub-frame
"""
return _DPxEnablePPxGcdShiftSubframe()
_DPxDisablePPxGcdShiftSubframe = DPxDll['DPxDisablePPxGcdShift']
_DPxDisablePPxGcdShiftSubframe.argtypes = None
_DPxDisablePPxGcdShiftSubframe.restype = None
[docs]def DPxDisablePPxGcdShiftSubframe():
"""
PROPixx Gaze-Contingent Display only modifies shift once per video frame
"""
return _DPxDisablePPxGcdShiftSubframe()
_DPxEnablePPxGcdShiftHardware = DPxDll['DPxEnablePPxGcdShiftHardware']
_DPxEnablePPxGcdShiftHardware.argtypes = None
_DPxEnablePPxGcdShiftHardware.restype = None
[docs]def DPxEnablePPxGcdShiftHardware():
"""
PROPixx Gaze-Contingent Display shift is controlled by hardware
"""
return _DPxEnablePPxGcdShiftHardware()
_DPxDisablePPxGcdShiftHardware = DPxDll['DPxDisablePPxGcdShiftHardware']
_DPxDisablePPxGcdShiftHardware.argtypes = None
_DPxDisablePPxGcdShiftHardware.restype = None
[docs]def DPxDisablePPxGcdShiftHardware():
"""
PROPixx Gaze-Contingent Display shift is controlled by software registers
"""
return _DPxDisablePPxGcdShiftHardware()
_DPxEnableGcdShiftHardwareBridge = DPxDll['DPxEnableGcdShiftHardwareBridge']
_DPxEnableGcdShiftHardwareBridge.argtypes = None
_DPxEnableGcdShiftHardwareBridge.restype = None
[docs]def DPxEnableGcdShiftHardwareBridge():
"""
PROPixx Controller bridges hardware inputs to PROPixx for Gaze-Contingent Display shifting
"""
return _DPxEnableGcdShiftHardwareBridge()
_DPxDisableGcdShiftHardwareBridge = DPxDll['DPxDisableGcdShiftHardwareBridge']
_DPxDisableGcdShiftHardwareBridge.argtypes = None
_DPxDisableGcdShiftHardwareBridge.restype = None
[docs]def DPxDisableGcdShiftHardwareBridge():
"""
PROPixx Controller does not send hardware data to PROPixx for Gaze-Contingent Display shifting
"""
return _DPxDisableGcdShiftHardwareBridge()
_DPxSetGcdShiftHardwareMode = DPxDll['DPxSetGcdShiftHardwareMode']
_DPxSetGcdShiftHardwareMode.argtypes = [ctypes.c_int]
_DPxSetGcdShiftHardwareMode.restype = None
[docs]def DPxSetGcdShiftHardwareMode(mode = 0):
"""
Sets the PROPixx TScope Mode.
Arguments:
mode (int): the percentage of the screen to calibrate.
- **0**: X and Y are foced to 0.
- **1**: X and Y are signed 16-bit numbers from ADC0 and ADC1.
- **2**: X and Y are signed 12-bit numbers from DIN11:00 and DIN23:12..
Raises:
Error if the mode is not a support value
"""
if (mode > 2 or mode < 0):
raise("Mode argument should between 0 and 2")
if (mode == 0):
libdpxMode = api_constants['DPXREG_CTRL_GCD_SHIFT_HW_MODE_NULL']
elif (mode == 1):
libdpxMode = api_constants['DPXREG_CTRL_GCD_SHIFT_HW_MODE_ADC']
else:
libdpxMode = api_constants['DPXREG_CTRL_GCD_SHIFT_HW_MODE_DIN']
_DPxSetGcdShiftHardwareMode(libdpxMode)
_DPxSetGcdShiftHardwareTransform = DPxDll['DPxSetGcdShiftHardwareTransform']
_DPxSetGcdShiftHardwareTransform.argtypes = [ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int]
_DPxSetGcdShiftHardwareTransform.restype = None
_DPxGetPPxTScopeSchedCount = DPxDll['DPxGetPPxTScopeSchedCount']
_DPxGetPPxTScopeSchedCount.argtypes = None
_DPxGetPPxTScopeSchedCount.restype = ctypes.c_int
[docs]def DPxGetPPxTScopeSchedCount():
"""
Get T-Scope schedule update count
"""
return _DPxGetPPxTScopeSchedCount()
_DPxIsPPxTScopePrepAck = DPxDll['DPxIsPPxTScopePrepAck']
_DPxIsPPxTScopePrepAck.argtypes = None
_DPxIsPPxTScopePrepAck.restype = ctypes.c_int
[docs]def DPxIsPPxTScopePrepAck():
"""
Returns non-zero when cover page has been presented, and T-Scope schedule can be started
"""
return _DPxIsPPxTScopePrepAck()
_DPxSetPPxTScopeMode = DPxDll['DPxSetPPxTScopeMode']
_DPxSetPPxTScopeMode.argtypes = [ctypes.c_int]
_DPxSetPPxTScopeMode.restype = None
[docs]def DPxSetPPxTScopeMode(mode = 0):
"""
Sets the PROPixx TScope Mode.
Arguments:
mode (int): the percentage of the screen to calibrate.
- **0**: Binary Images stored in PROPixx DRAM.
- **1**: Single video image stored in the base page.
- **2**: Sequence of video image, depending on the uploaded program.
Raises:
Error if the mode is not a support value
"""
if (mode > 2 or mode < 0):
raise("Mode argument should between 0 and 2")
if (mode == 0):
libdpxMode = api_constants['PPXREG_TSCOPE_CTRL_MODE_BIN_LIST']
elif (mode == 1):
libdpxMode = api_constants['PPXREG_TSCOPE_CTRL_MODE_VID_SINGLE']
else:
libdpxMode = api_constants['PPXREG_TSCOPE_CTRL_MODE_VID_PROG']
_DPxSetPPxTScopeMode(libdpxMode)
_DPxSetPPxTScopeProgAddr = DPxDll['DPxSetPPxTScopeProgAddr']
_DPxSetPPxTScopeProgAddr.argtypes = [ctypes.c_int]
_DPxSetPPxTScopeProgAddr.restype = None
[docs]def DPxSetPPxTScopeProgAddr(addr = 0):
"""
Sets the program that the third Tscope mode uses to present video.
Arguments:
addr (int): The address of the program (between 0 and 1024)
Raises:
Error if the address is not between 0 and 1024
"""
if (addr > 1024 or addr < 0):
raise("Address argument must be betweten 0 and 1024")
_DPxSetPPxTScopeProgAddr(addr)
_DPxEnablePPxTScope = DPxDll['DPxEnablePPxTScope']
_DPxEnablePPxTScope.argtypes = None
_DPxEnablePPxTScope.restype = None
[docs]def DPxEnablePPxTScope():
"""
Enable the PROPixx T-Scope subsystem. This will terminate normal display of incoming video. Contains an implicit call to RegWrRd.
"""
_DPxEnablePPxTScope()
_DPxDisablePPxTScope = DPxDll['DPxDisablePPxTScope']
_DPxDisablePPxTScope.argtypes = None
_DPxDisablePPxTScope.restype = None
[docs]def DPxDisablePPxTScope():
"""
Enable the PROPixx T-Scope subsystem. This will return the PROPixx to normal display of incoming video. Contains an implicit call to RegWrRd.
"""
_DPxDisablePPxTScope()
_DPxEnablePPxTScopePrepReq = DPxDll['DPxEnablePPxTScopePrepReq']
_DPxEnablePPxTScopePrepReq.argtypes = None
_DPxEnablePPxTScopePrepReq.restype = None
[docs]def DPxEnablePPxTScopePrepReq():
"""
Wait for the current video frame to terminate, then load and show cover page of TScope movie. Note that TScope requires a transition from
DPxDisablePPxTScopePrepReq to DPxEnablePPxTScopePrepReq.
"""
_DPxEnablePPxTScopePrepReq()
_DPxDisablePPxTScopePrepReq = DPxDll['DPxDisablePPxTScopePrepReq']
_DPxDisablePPxTScopePrepReq.argtypes = None
_DPxDisablePPxTScopePrepReq.restype = None
[docs]def DPxDisablePPxTScopePrepReq():
"""
Wait for the current video frame to terminate, then load and show cover page of TScope movie. Note that TScope requires a transition from
DPxDisablePPxTScopePrepReq to DPxEnablePPxTScopePrepReq.
"""
_DPxDisablePPxTScopePrepReq()
_DPxSetPPxTScopeProgOffsetPage = DPxDll['DPxSetPPxTScopeProgOffsetPage']
_DPxSetPPxTScopeProgOffsetPage.argtypes = (ctypes.c_uint16,)
_DPxSetPPxTScopeProgOffsetPage.restype = None
[docs]def DPxSetPPxTScopeProgOffsetPage(offset):
"""
Sets the offset for the PROPixx TScope Mode, the value is a 16-bit unsigned integer"
Raises:
Error when the offset is not in the right ranged.
"""
if (offset > 65536 or offset < 0):
raise("Offset argument must be between 0 and 65535")
_DPxSetPPxTScopeProgOffsetPage(offset)
_DPxSetPPxTScopeProg = DPxDll['DPxSetPPxTScopeProg']
_DPxSetPPxTScopeProg.argtypes = [ctypes.POINTER(ctypes.c_uint16), ctypes.c_int]
_DPxSetPPxTScopeProg.restype = None
[docs]def DPxSetPPxTScopeProg(program):
"""
Sends a microcode program to the PROPixx TScope system. The program is a list of two dimensions.
Args:
program (list): The list should be a 2D list, with the first collumn ([0][i]) contains the frame index which should be presented. The second collumn ([1][i]) is the number of times the frame should be presented.
If the number of times a frame should be presented is set to zero, the program will continue showing this frame until stopped.
Ex for the unpacked program:
program2 = np.zeros((1024,2), np.uint16)
for i in range(1023):
frame = i % 32
value = math.floor(frame/4) * 256 + (frame % 4)
program2[i][0] = int(value)
program2[i][1] = int(60)
program2[1023][0] = 0
"""
unpacked_program = []
for i in range(len(program)):
unpacked_program.append(program[i][0])
unpacked_program.append(program[i][1])
# Then we need to convert it to a proper Uint16 array
item_count = len(unpacked_program)
packed_data = (ctypes.c_uint16 * item_count)(*unpacked_program)
_DPxSetPPxTScopeProg(packed_data, i)
_DPxEnablePPxSwtpLoad = DPxDll['DPxEnablePPxSwtpLoad']
_DPxEnablePPxSwtpLoad.argtypes = None
_DPxEnablePPxSwtpLoad.restype = None
[docs]def DPxEnablePPxSwtpLoad():
"""
Load the current video input directly into the DRAM to be played back later using the TScope modes.
"""
_DPxEnablePPxSwtpLoad()
_DPxDisablePPxSwtpLoad = DPxDll['DPxDisablePPxSwtpLoad']
_DPxDisablePPxSwtpLoad.argtypes = None
_DPxDisablePPxSwtpLoad.restype = None
[docs]def DPxDisablePPxSwtpLoad():
"""
Stops the loading of the current video input directly into the DRAM to be played back later using the TScope modes.
"""
_DPxDisablePPxSwtpLoad()
_DPxSetPPxSwtpLoadPage = DPxDll['DPxSetPPxSwtpLoadPage']
_DPxSetPPxSwtpLoadPage.argtypes = None
_DPxSetPPxSwtpLoadPage.restype = None
[docs]def DPxSetPPxSwtpLoadPage(page):
"""
Sets the page to load a test pattern directly into the RAM.
Args:
page (int): Page value, between 0 and 127
Raises:
Error if page value is not in the right range
"""
if (page < 0 or page > 128):
raise("Page argument must be between 0 and 128")
_DPxSetPPxSwtpLoadPage(page)
_DPxStartPPxTScopeSched = DPxDll['DPxStartPPxTScopeSched']
_DPxStartPPxTScopeSched.argtypes = None
_DPxStartPPxTScopeSched.restype = None
[docs]def DPxStartPPxTScopeSched():
"""
Starts running a PROPixx TScope schedule. The schedule will start on the next register update. The cover page will first be shown until the offset set by the
schedule has passed. Every call to DPxStartPPxTScopeSched muust be preceeded by a call to DPxSetPPxTScopeSched
"""
_DPxStartPPxTScopeSched();
_DPxStopPPxTScopeSched = DPxDll['DPxStopPPxTScopeSched']
_DPxStopPPxTScopeSched.argtypes = None
_DPxStopPPxTScopeSched.restype = None
[docs]def DPxStopPPxTScopeSched():
"""
Stops running a PROPixx TScope schedule. The schedule will stop on the next register update. If the maxScheduleFrames is not set to zero, the schedule will end once zero is reached.
"""
_DPxStopPPxTScopeSched();
_DPxWritePPxTScopePages = DPxDll['DPxWritePPxTScopePages']
_DPxWritePPxTScopePages.argtypes = [ctypes.c_uint, ctypes.c_uint, ctypes.c_void_p]
_DPxWritePPxTScopePages.restype = None
[docs]def DPxWritePPxTScopePages(index, data):
"""
Download 1 ore more TScope images to the PROPixx Ram. TScope images are 1920 * 1080 bits = 2 703 600 bits = 259 200 bytes.
The data of the TScope images should be stored little-endian, so bit 0 of byte 0 controls the top left pixel.
Maximum number of pages depends on the size of RAM. Most PROPixx will have 2016 MB for TScope at most.
TScope pages are stored by 256kB bounderies, therefore a maxumum of 8064 pages are availible.
Args:
index (int): Indicates the location (range 1-8064), where the write should start
data (numpy array of uint8): 2D List of data to write, each bit represents 1 pixel. This should be a 240x1080*nPages array, where each data (8 bits) is 8 horizontal pixels.
The data should have a length multiple of 259 200 bytes.
For example:
import numpy as np
pageData = np.zeros((1920//8, 1080), np.uint8)
for i in range(200):
pageData[i] = [255] * 1080
This put the top 200 rows of pixels to be white.
Raises:
Error if the index is not between 1 and 8064
Error if the size of data is not a multiple of 259200 or is smaller.
"""
if (index < 1 or index > 8064):
raise("Index value must be between 1 and 8063")
pageDataSize = data.size
if (pageDataSize % 259200):
raise("data size must be a multiple of 259 200")
nbPage = pageDataSize // 259200
if (nbPage < 1):
raise("No pages to be written.")
#Index - 1 because this starts at 1 but C starts at 0. (same as matlab)
data = data.astype(np.uint8)
data_p = data.ctypes.data_as(ctypes.c_void_p)
_DPxWritePPxTScopePages(index-1, nbPage, data_p)
_DPxSetPPxTScopeSched = DPxDll['DPxSetPPxTScopeSched']
_DPxSetPPxTScopeSched.argtypes = [ctypes.c_uint, ctypes.c_uint, ctypes.c_int, ctypes.c_uint]
_DPxSetPPxTScopeSched.restype = None
_DPxSetPPxTScopeBuffBasePage = DPxDll['DPxSetPPxTScopeBuffBasePage']
_DPxSetPPxTScopeBuffBasePage.argtypes = [ctypes.c_uint]
_DPxSetPPxTScopeBuffBasePage.restype = None
_DPxSetPPxTScopeBuffNPages = DPxDll['DPxSetPPxTScopeBuffNPages']
_DPxSetPPxTScopeBuffNPages.argtypes = [ctypes.c_uint]
_DPxSetPPxTScopeBuffNPages.restype = None
[docs]def SetPropixxTScopeSchedule(onset, rate, maxScheduleFrame, startPage = 1, nPages = None):
"""
Configure a schedule for T-Scope image sequence playback on PROPixx.
Args:
onset (float): Time in seconds before the schedule should start. Between 0 and 4.29 seconds
rate (list): List with 1 or 2 elements. the first element is an integer indicating the sampling rate. the second element is either
an integer indicating the sampling rate units, or not present. When this is just an int, it is considered to be pages/second.
int description
1 sampling rate specified in pages/second.
2 sampling rate specified in pages/video frame being recieved on DVI.
3 sampling rate specified in seconds/page (frame period)
Maximum speed is 10 kHz.
maxScheduleFrame (int): If the duration of the schedule is known, pass the number of frames. The schedule will terminate automatically when the countdown reaches 0. If duration is unknown, pass 0.
startPage (int): Where the schedule should start. This represents the cover page. First page shown when DPxEnablePPxTScopePrepReq is called.
nPages (int): Specify how many pages in the PROPixx RAM should be used in this sequence. If the schedule requests more pages than nPages, then it will wrap back to the cover page.
For many applications, the complete stimulus is represented by a single pass through a fixed block of pages. In these cases, nPages could be left at its default value of maxScheduleFrames.
Note that every call to StartPropixxTScopeSchedule must be preceeded by a call to SetPropixxTScopeSchedule (ie: multiple calls to StartPropixxTScopeSchedule each require their own call to SetPropixxTScopeSchedule).
Schedule timing is implemented in hardware with microsecond precision.
"""
if (onset < 0 or onset > 4.28):
raise ("Onset argument must be between 0 and 4.28 seconds")
schedOnset = math.floor(onset * 1.0e9 + 0.5)
if isinstance(rate,int): # integer passed
unit = 1
schedRate = rate
elif isinstance(rate,list) and len(rate)==2: # 2 element list passed
schedRate = rate[0]
# check integrity integrity of element 2
unit = rate[1]
if (unit < 1 or unit > 3):
raise("Unit must be 1,2 or 3")
else: # neither a single integer or a 2 element list passed
raise Exception
# Convert to the proper values for C-API
#RateCheck
if (unit == 1): #Hz
schedRateHz = schedRate;
unitC = DPXREG_SCHED_CTRL_RATE_HZ
elif (unit == 2): #Rate per video frame
schedRateHz = schedRate * DPxGetVidVFreq();
unitC = DPXREG_SCHED_CTRL_RATE_XVID
elif (unit == 3): #Seconds/samples
schedRateHz = 1 / schedRate;
unitC = DPXREG_SCHED_CTRL_RATE_NANO
if (schedRateHz > 10000):
raise("Maximum rate is 10 kHz")
if (schedRate < 0):
raise("Rate must be positive")
if (maxScheduleFrame < 0):
raise("Maximum of schedule frame must be a positive number")
if (startPage > 8063 or startPage < 1):
raise("StartPage must be between 1 and 8063")
startPage = startPage - 1
if (maxScheduleFrame == 0 and nPages == None):
raise("When maxScheduleFrame is 0, nPages needs to be defined")
if (nPages == None):
nPages = maxScheduleFrame
_DPxSetPPxTScopeSched(schedOnset, ctypes.c_uint32(schedRate), unitC, maxScheduleFrame);
_DPxSetPPxTScopeBuffBasePage(startPage);
_DPxSetPPxTScopeBuffNPages(nPages);
eye = {'LEFT_EYE': 0, 'RIGHT_EYE': 1, 'BOTH': 2 }
tempNum = { 'DP3_TEMP_FPGA':0,
'DP3_TEMP_DP':1,
'DP3_TEMP_FF':2,
'DP3_TEMP_USB':3,
'DP3_TEMP_ADC':4,
'DP3_TEMP_POW_0V95':5,
'DP3_TEMP_POW_1V03':6,
'DP3_TEMP_POW_1V8':7,
'DP3_TEMP_POW_5V0':8}
powNum = {'DP3_POW_VOLTAGE_0V95': 0,
'DP3_POW_CURRENT_0V95': 1,
'DP3_POW_POWER_0V95': 2,
'DP3_POW_VOLTAGE_1V03': 3,
'DP3_POW_CURRENT_1V03': 4,
'DP3_POW_POWER_1V03': 5,
'DP3_POW_VOLTAGE_1V8': 6,
'DP3_POW_CURRENT_1V8': 7,
'DP3_POW_POWER_1V8': 8,
'DP3_POW_VOLTAGE_5V0': 9,
'DP3_POW_CURRENT_5V0': 10,
'DP3_POW_POWER_5V0': 11 }
api_constants = {'AUTO': -1,
'CRYSTALEYES':0x10,
'C48': 3,
'C36D': 7,
'C24': 0,
'DEPTH Q':0x40,
'DISABLED':0x70,
'DIFF': 1,
'DPX_REG_SPACE': 480,
'DPX_REG_SPACE_DP3': 2048,
'GND' : 0,
'HZ': 0,
'LEFT': 0x100,
'LINE' : 2,
'LR': 0,
'L48': 1,
'L48D': 5,
'M16': 2,
'M16O': 2,
'MIC': 1,
'MONO': 0,
'M16D': 6,
'NANO': 32,
'NVIDIA': 0x20,
'VOLFONI': 0x50,
'RAW': -2,
'REF0': 2,
'REF1': 3,
'RB24': 8,
'RIGHT': 0x200,
'STEREO1': 0x300,
'STEREO2': 0x400,
'UNCONFIGURED': 0,
'DATAPIXX': 10,
'DATAPIXX2': 20,
'DATAPIXX3': 30,
'VIEWPIXX': 40,
'VIEWPIXX3D': 40,
'VIEWPIXXEEG': 40,
'VIEWPIXXXL': 40,
'PROPIXXCTRL': 50,
'PROPIXX': 60,
'TRACKPIXX': 70,
'TRACKPIXX3': 70,
'IOHUB' : 80,
'PROPIXX3': 110,
'VIDEO': 16,
'DPX_DEVSEL_LAST_DEVICE': 89,
'VIEWPIXX_TYPE': 1,
'VIEWPIXX_TYPE_3D': 2,
'VIEWPIXX_TYPE_EEG': 3,
'VIEWPIXX_TYPE_XL': 4,
'DPX_DEVSEL_MULTI': 10,
'PPXREG_TSCOPE_CTRL_MODE_BIN_LIST' : 0,
'PPXREG_TSCOPE_CTRL_MODE_VID_SINGLE' : 2,
'PPXREG_TSCOPE_CTRL_MODE_VID_PROG' : 4,
'DPXREG_CTRL_GCD_SHIFT_HW_MODE_NULL' : 0x0000,
'DPXREG_CTRL_GCD_SHIFT_HW_MODE_ADC' : 0x0010,
'DPXREG_CTRL_GCD_SHIFT_HW_MODE_DIN' : 0x0020,
}
adc_channel_reference = {0 : 'GND',
1 : 'DIFF',
2 : 'REF0',
3 : 'REF1'
}
rate_constants = {0x00: 'HZ',
0x10: 'VIDEO',
0x20: 'NANO'
}
mic_mode_constants = {0x00: 'mono',
0x10: 'left',
0x20: 'right',
0x30: 'stereo'
}
audio_mode_constants = {0x000: 'mono',
0x100: 'left',
0x200: 'right',
0x300: 'stereo1',
0x400: 'stereo2'
}
video_mode_constants = {1: 'L48',
2: 'M16',
3: 'C48',
4: 'HWTP',
5: 'L48D',
6: 'M16D',
7: 'C36D',
0: 'C24',
8: 'RB24'
}
propixx_sequencer_constants = {0x00: 'RGB 120Hz',
0x10: 'RB3D',
0x20: 'RGB Quad 480Hz',
0x30: 'RGB 240Hz',
0x40: 'RGB 180Hz',
0x50: 'GREY Quad 1440Hz',
0x60: 'RGB 120Hz Calib. High Bit Depth',
0x90: 'GREY 3x 360Hz',
0xA0: 'GREY 720Hz',
0xB0: 'RGB2',
0xF0: 'Custom Sequencer'
}
propixx_sequencer_constants2 = {0x00: 'RGB',
0x10: 'RB3D',
0x20: 'QUAD4X',
0x30: 'RGB240',
0x40: 'RGB180',
0x50: 'QUAD12X',
0x60: 'RGBHBD',
0x90: 'GREY3X',
0xA0: 'GREY720',
0xB0: 'RGB2',
0xF0: 'Custom Sequencer'
}
propixx_led_current_constant = {'PPX_LED_CUR_RED_L': 0,
'PPX_LED_CUR_RED_H': 1,
'PPX_LED_CUR_GRN_L': 2,
'PPX_LED_CUR_GRN_H': 3,
'PPX_LED_CUR_BLU_L': 4,
'PPX_LED_CUR_BLU_H': 5,
'PPX_LED_CUR_ALT_L': 6,
'PPX_LED_CUR_ALT_H': 7
}
vesa_mode_constants = {0x00: 'LR',
0x10: 'CRYSTALEYES',
0x20: 'NVIDIA',
0x40: 'PPX_DEPTHQ',
0x50: 'VOLFONI',
0x70: 'DISABLED'
}
part_number_constants = {
0x0000: 'NoPart',
0x1000: 'DATAPixx LITE',
0x1001: 'DATAPixx FULL',
0x2000: 'VIEWPixx LITE',
0x2001: 'VIEWPixx FULL',
0x2004: 'VIEWPixx3D LITE',
0x2005: 'VIEWPixx3D FULL',
0x2006: 'VIEWPixxEEG',
0x2010: 'VIEWPixxXL LITE',
0x2011: 'VIEWPixxXL FULL',
0x5068: 'PROPixx Ctrl LITE',
0x5069: 'PROPixx Ctrl FULL',
0x5050: 'PROPixx',
0x1002: 'DATAPixx2 LITE',
0x1003: 'DATAPixx2 FULL',
0x1004: 'DATAPixx3 LITE',
0x1005: 'DATAPixx3 FULL',
0x3410: 'TRACKPixx',
0x494F: 'IOHub'
}
test_pattern_constants = {'MASK': 0xF000,
'C24': 0,
'DVI': 0x0000,
'LVDS': 0x1000,
'SWTP': 0x4000,
'SWTP 3D': 0x5000,
'RGB SQUARES': 0x8000,
'GRAY': 0x9000,
'BAR': 0xA000,
'BAR2': 0xB000,
'DOTS': 0xC000,
'DOTS1': 0xC000 + 0x4E1,
'DOTS2': 0xC000 + 0x4D1,
'DOTS PPX': 0xC000 + 0xAF0,
'RAMP': 0xD000,
'RGB': 0xE000,
'PROJ': 0xF000
}
videoConsoleDisplayPresets = {'FULL_STIMULI_HALF_TRACK': 0,
'FULL_STIMULI_NO_TRACK': 1,
'FULL_STIMULI_FULL_TRACK': 2,
'HALF_STIMULI_FULL_TRACK': 3
}
lensTypes = {'25mm': 0,
'50mm': 1,
'75mm': 2
}
DPXREG_ADC_CHANREF_GND = 0 # Referenced to ground
DPXREG_ADC_CHANREF_DIFF = 1 # Referenced to adjacent analog input
DPXREG_ADC_CHANREF_REF0 = 2 # Referenced to REF0 analog input
DPXREG_ADC_CHANREF_REF1 = 3 # Referenced to REF1 analog input
DPXREG_AUD_CTRL_LRMODE_MONO = 0x0000 # Each AUD schedule datum goes to left and right channels
DPXREG_AUD_CTRL_LRMODE_LEFT = 0x0100 # Each AUD schedule datum goes to left channel only
DPXREG_AUD_CTRL_LRMODE_RIGHT = 0x0200 # Each AUD schedule datum goes to right channel only
DPXREG_AUD_CTRL_LRMODE_STEREO_1 = 0x0300 # Pairs of AUD data are copied to left/right channels
DPXREG_AUD_CTRL_LRMODE_STEREO_2 = 0x0400 # AUD data goes to left channel, AUX data goes to right
PPX_POWER_5V = 0x0000
PPX_POWER_2P5V = 0x0001
PPX_POWER_1P8V = 0x0002
PPX_POWER_1P5V = 0x0003
PPX_POWER_1P1V = 0x0004
PPX_POWER_1V = 0x0005
PPX_POWER_12V = 0x0006
PPX_TEMP_LED_RED = 0x0000
PPX_TEMP_LED_GRN = 0x0001
PPX_TEMP_LED_BLU = 0x0002
PPX_TEMP_LED_ALT = 0x0003
PPX_TEMP_DMD = 0x0004
PPX_TEMP_POWER_BOARD = 0x0005
PPX_TEMP_LED_POWER_BOAD = 0x0006
PPX_TEMP_RX_DVI = 0x0007
PPX_TEMP_FPGA = 0x0008
PPX_TEMP_FPGA2 = 0x0009
PPX_LED_DAC_RED_L = 0x0000
PPX_LED_DAC_RED_H = 0x0001
PPX_LED_DAC_GRN_L = 0x0002
PPX_LED_DAC_GRN_H = 0x0003
PPX_LED_DAC_BLU_L = 0x0004
PPX_LED_DAC_BLU_H = 0x0005
PPX_FAN_TACH_1 = 0x0000
PPX_FAN_TACH_2 = 0x0001
PPX_FAN_TACH_3 = 0x0002
PPX_FAN_TACH_4 = 0x0003
PPX_FAN_TACH_5 = 0x0004
PPX_FAN_TACH_6 = 0x0005
DPXREG_VID_SRC_MASK = 0xF000
DPXREG_VID_SRC_DVI = 0x0000
DPXREG_VID_SRC_LVDS = 0x1000
DPXREG_VID_SRC_SWTP = 0x4000
DPXREG_VID_SRC_SWTP_3D = 0x5000
DPXREG_VID_SRC_HWTP_RGB_SQUARES = 0x8000
DPXREG_VID_SRC_HWTP_GRAY = 0x9000
DPXREG_VID_SRC_HWTP_DRIFTING_BAR = 0xA000
DPXREG_VID_SRC_HWTP_DRIFTING_BAR2 = 0xB000
DPXREG_VID_SRC_HWTP_DRIFTING_DOTS = 0xC000
DPXREG_VID_SRC_HWTP_DRIFTING_RAMP = 0xD000
DPXREG_VID_SRC_HWTP_RGB = 0xE000
DPXREG_VID_SRC_HWTP_PROJ = 0xF000
DPXREG_SCHED_CTRL_LOG_TOUCHPIXX = 2097152 # 0x00200000
DPXREG_SCHED_CTRL_LOG_EVENTS = 1048576 # 0x00100000
DPXREG_SCHED_CTRL_LOG_TIMETAG = 65536 # 0x00010000
DPXREG_SCHED_CTRL_COUNTDOWN = 256 # 0x00000100
DPXREG_SCHED_CTRL_RATE_MASK = 48 # 0x00000030
DPXREG_SCHED_CTRL_RATE_XVID = 16 # 0x00000010
DPXREG_SCHED_CTRL_RATE_NANO = 32 # 0x00000020
DPXREG_SCHED_CTRL_RUNNING = 1 # 0x00000001
DPXREG_VID_LCD_TIMING = 0x1A6
DPXREG_VID_BL_INTENSITY = 0x1A8
DPXREG_VID_VPERIOD_L = 0x180
DPXREG_VID_VPERIOD_H = 0x182
DPXREG_VID_HTOTAL = 0x184
DPXREG_VID_VTOTAL = 0x186
DPXREG_VID_HACTIVE = 0x188
DPXREG_VID_VACTIVE = 0x18A
DPXREG_VID_CLK_CTRL = 0x18C
DPXREG_VID_STATUS = 0x18E
DPXREG_VID_CTRL2 = 0x1A0
DPXREG_VID_CTRL = 0x19E
DPXREG_VID_CTRL_NATIVE100HZ = 0x4000
DPXREG_VID_CTRL2_EEG_BRIGHT_MODE = 0x0040
DPXREG_VID_CTRL2_NO_EXTPOL = 0x0020
DPXREG_VID_CTRL2_NO_VLOCK_LAMP = 0x0010
DPXREG_VID_CTRL2_NO_VLOCK = 0x0008
DPXREG_VID_CTRL2_NO_VCALIB = 0x0004
DPXREG_VID_CTRL2_NO_VDITH = 0x0002
DPXREG_VID_CTRL2_NO_HDITH = 0x0001
DPXREG_VID_CTRL2_PIXELDRIVE = 0x8000
DPXREG_VID_CTRL2_PIXELDRIVE_ACCUM = 0x4000
DPXREG_VID_CTRL2_PIXELDRIVE_ACCUM2 = 0x2000
DPXREG_VID_CTRL2_LCD_3D60HZ = 0x0800
DPXREG_VID_CTRL2_TX_DVI_1080P = 0x0100
DPXREG_VID_BL_SCAN_CTRL = 0x1AE
DPXREG_VID_STATUS_DVI_AUTO_3D_MODE = 0x1000
DPXREG_VID_STATUS_DVI_DIRECT_ACTIVE = 0x0800
DPXREG_VID_STATUS_DVI_STRETCH_DE = 0x0400
DPXREG_VID_STATUS_DVI_LOCKABLE = 0x0200
DPXREG_VID_STATUS_LCD_HIFREQ = 0x0100
DPXREG_VID_STATUS_SLEEP = 0x0008
DPXREG_VID_STATUS_TURBO = 0x0004
DPXREG_VID_STATUS_DVI_ACTIVE_DUAL = 0x0002
DPXREG_VID_STATUS_DVI_ACTIVE = 0x0001
DPXREG_VID_BL_POWER_FAULT = 0x80
DPXREG_VID_BL_POWER_CTRL = 0x1AC
DPXREG_STATS0 = 0x1C0
DPXREG_STATS1 = 0x1C2
DPXREG_STATS2 = 0x1C4
DPXREG_STATS3 = 0x1C6
DPXREG_STATS4 = 0x1C8
DPXREG_STATS5 = 0x1CA
DPXREG_STATS6 = 0x1CC
DPXREG_STATS7 = 0x1CE
DPXREG_DDR_CSR = 0x1DC
PPXREG_SLEEP = 0x0A
PPXREG_SLEEP_AWAKE_STATUS = 0x4
PPX_TEMP_LED_POWER_BOARD = 6
PPXREG_TEMP_STATUS = 0x2E
PPXREG_SLEEP_LAMP_LED_ON_STATUS = 0x20
PPXREG_SLEEP_LAMP_LED_OFF = 0x10
PPXREG_SLEEP_LAMP_LED_ON = 0x8
PPXREG_SLEEP_GOTO_SLEEP = 0x2
PPXREG_SLEEP_GOTO_AWAKE = 0x1
PPXREG_TEMP_LED_GRN_RED = 0x20
PPXREG_TEMP_LED_ALT_BLU = 0x22
PPXREG_TEMP_DMD_POW = 0x24
PPXREG_TEMP_RX_DVI_LED_POW_BD = 0x26
PPXREG_TEMP_DDC4100_FPGA = 0x28
PPXREG_TEMP_VOLTAGE_MONITOR = 0x2A
PPXREG_TEMP_UNUSED = 0x2C
PPXREG_POWER_FIRST = 0x30
PPXREG_POWER_5V = 0x30
PPXREG_POWER_2P5V = 0x32
PPXREG_POWER_1P8V = 0x34
PPXREG_POWER_1P5V = 0x36
PPXREG_POWER_1P1V = 0x38
PPXREG_POWER_1P0V = 0x3A
PPXREG_POWER_12V = 0x3C
PPXREG_FAN_CONFIG = 0x40
PPXREG_FAN_CONFIG_PWM = 0x00FF
PPXREG_FAN_CONFIG_IDLE_PWM = 0xFF00
PPXREG_FAN_TACH_1_2 = 0x42
PPXREG_FAN_TACH_3_4 = 0x44
PPXREG_FAN_TACH_5_6 = 0x46
PPXREG_FAN_CONFIG2 = 0x48
PPXREG_FAN_CONFIG2_FAN_QUIET_MODE = 0x0001
PPXREG_TSCOPE_BUFF_BASEPAGE = 0x120
PPXREG_TSCOPE_BUFF_NPAGES = 0x122
PPXREG_TSCOPE_CSR = 0x12E
PPXREG_TSCOPE_CSR_PREP_ACK = 0x0020
PPXREG_TSCOPE_CSR_PREP_REQ = 0x0010
PPXREG_TSCOPE_CSR_EN = 0x0001
PPXREG_TSCOPE_SCHED_ONSET_L = 0x130 # Delay between schedule start and first TACH update tick, in nanoseconds
PPXREG_TSCOPE_SCHED_ONSET_H = 0x132
PPXREG_TSCOPE_SCHED_RATE_L = 0x134 # Tick rate in ticks/second or ticks/frame, or tick period in nanoseconds
PPXREG_TSCOPE_SCHED_RATE_H = 0x136
PPXREG_TSCOPE_SCHED_COUNT_L = 0x138 # Tick counter
PPXREG_TSCOPE_SCHED_COUNT_H = 0x13A
PPXREG_TSCOPE_SCHED_CTRL_L = 0x13C # Bits are defined in DPXREG_DAC_SCHED_CTRL register
PPXREG_TSCOPE_SCHED_CTRL_H = 0x13E
PPXREG_3D_CROSSTALK_RED_LR = 0x140
PPXREG_3D_CROSSTALK_RED_RL = 0x142
PPXREG_3D_CROSSTALK_GRN_LR = 0x144
PPXREG_3D_CROSSTALK_GRN_RL = 0x146
PPXREG_3D_CROSSTALK_BLU_LR = 0x148
PPXREG_3D_CROSSTALK_BLU_RL = 0x14A
PPXREG_0x14C = 0x14C
PPXREG_0x14E = 0x14E
PPXREG_HS_CTRL = 0x150
PPXREG_HS_CTRL_CORRECTION_EN = 0x0001
PPXREG_HS_CTRL_SPI_LUT_FOUND = 0x0002
PPXREG_HS_CTRL_SPI_CENTER_FOUND = 0x0004
PPXREG_HS_CENTER_X_COORD = 0x152
PPXREG_HS_CENTER_Y_COORD = 0x154
PPXREG_0x156 = 0x156
PPXREG_0x158 = 0x158
PPXREG_0x15A = 0x15A
PPXREG_0x15C = 0x15C
PPXREG_0x15E = 0x15E
PPXREG_VID_DDC_CFG = 0x160
PPXREG_VID_DDC_CFG_PATGEN = 0xFF00
PPXREG_VID_DDC_CFG_ARST = 0x0080
PPXREG_VID_DDC_CFG_PWR_FLOAT = 0x0040
PPXREG_VID_DDC_CFG_WDT_EN = 0x0020
PPXREG_VID_DDC_CFG_ROWADD_MODE = 0x0010
PPXREG_VID_DDC_CFG_NS_FLIP_EN = 0x0008
PPXREG_VID_DDC_CFG_COMP_DATA_EN = 0x0004
PPXREG_VID_DDC_CFG_CNT_HALT = 0x0002
PPXREG_VID_DDC_CFG_DDC_FLOAT = 0x0001
PPXREG_VID_MIRROR_TIME = 0x162
PPXREG_VID_MIRROR_TIME_SETTLING = 0xFF00
PPXREG_VID_MIRROR_TIME_RESET_ACTIVE = 0x00FF
PPXREG_3D_CROSSTALK_LR = 0x164
PPXREG_3D_CROSSTALK_RL = 0x166
PPXREG_3D_CROSSTALK = 0x168
PPXREG_VID_INTENSITY = 0x16A
PPXREG_VID_SEQ_PERIOD = 0x16C
PPXREG_VID_SEQ_CSR = 0x16E
PPXREG_VID_SEQ_CSR_STATUS = 0xFF00
PPXREG_VID_SEQ_CSR_PGRM_MASK = 0x00F0 # Only bit 4 is used for now
PPXREG_VID_SEQ_CSR_PGRM_CUSTOM = 0x00F0 # Custom USB uploaded
PPXREG_VID_SEQ_CSR_PGRM_RGB = 0x0000 # Default RGB 120Hz
PPXREG_VID_SEQ_CSR_PGRM_RB3D = 0x0010 # R/B channels drive grayscale 3D
PPXREG_VID_SEQ_CSR_PGRM_QUAD4X = 0x0020 # 4 display quadrants are projected at 4x refresh rate
PPXREG_VID_SEQ_CSR_PGRM_RGB240 = 0x0030 # RGB 240Hz
PPXREG_VID_SEQ_CSR_PGRM_RGB180 = 0x0040 # RGB 180Hz
PPXREG_VID_SEQ_CSR_PGRM_QUAD12X = 0x0050 # 4 display quadrants are projected at 12x refresh rate with grayscales
PPXREG_VID_SEQ_CSR_EN = 0x0001
PPXREG_LED_DAC_RED_L = 0x170
PPXREG_LED_DAC_RED_H = 0x172
PPXREG_LED_DAC_GRN_L = 0x174
PPXREG_LED_DAC_GRN_H = 0x176
PPXREG_LED_DAC_BLU_L = 0x178
PPXREG_LED_DAC_BLU_H = 0x17A
PPXREG_LED_DAC_ALT_L = 0x17C
PPXREG_LED_DAC_ALT_H = 0x17E
PPX_POWER_5V = 0
PPX_POWER_2P5V = 1
PPX_POWER_1P8V = 2
PPX_POWER_1P5V = 3
PPX_POWER_1P1V = 4
PPX_POWER_1V = 5
PPX_POWER_12V = 6
PPX_TEMP_LED_RED = 0
PPX_TEMP_LED_GRN = 1
PPX_TEMP_LED_BLU = 2
PPX_TEMP_LED_ALT = 3
PPX_TEMP_DMD = 4
PPX_TEMP_POWER_BOARD = 5
PPX_TEMP_LED_POWER_BOARD = 6
PPX_TEMP_RX_DVI = 7
PPX_TEMP_FPGA = 8
PPX_TEMP_FPGA2 = 9
PPX_LED_DAC_RED_L = 0
PPX_LED_DAC_RED_H = 1
PPX_LED_DAC_GRN_L = 2
PPX_LED_DAC_GRN_H = 3
PPX_LED_DAC_BLU_L = 4
PPX_LED_DAC_BLU_H = 5
PPX_LED_DAC_ALT_L = 6
PPX_LED_DAC_ALT_H = 7
PPX_FAN_TACH_1 = 0
PPX_FAN_TACH_2 = 1
PPX_FAN_TACH_3 = 2
PPX_FAN_TACH_4 = 3
PPX_FAN_TACH_5 = 4
PPX_FAN_TACH_6 = 5
PPX_SEQ_CMD_FLASH_START = 0x1000
PPX_SEQ_CMD_FLASH_WAIT = 0x2000
PPX_SEQ_CMD_FLASH_STOP = 0x3000
PPX_SEQ_CMD_DDC_LOAD = 0x4000
PPX_SEQ_CMD_DDC_CLEAR = 0x5000
PPX_SEQ_CMD_DDC_RESET = 0x6000
PPX_SEQ_CMD_TIMER_START = 0x7000
PPX_SEQ_CMD_TIMER_WAIT = 0x8000
PPX_SEQ_CMD_EOP = 0xF000
DPX_DAC_NCHANS = 4
DPX_ADC_NCHANS = 16
DPX_MIC_SRC_UNKNOWN = 0
DPX_MIC_SRC_MIC_IN = 1
DPX_MIC_SRC_LINE_IN = 2
DPX_VID = 0x04b4
DPX_PID = 0x4450
DPX_DID = 0x0000
VPX_PID = 0x5650
PPX_PID = 0x5050
PCX_PID = 0x5043
DP2_PID = 0x4432
TPX_PID = 0x5450
NBR_VPIXX_DEV = 4
DATAPIXX = 1
DATAPIXX2 = 5
VIEWPIXX = 2
PROPIXX_CTR = 3
PROPIXX = 4
SPI_ADDR_DPX_FPGA = 0x010000
SPI_ADDR_DPX_TEXT = 0x1F0000
SPI_ADDR_DPX_EDID = 0x3E0000
SPI_ADDR_DPX_ANALOG = 0x3F0000
SPI_ADDR_VPX_FPGA = 0x000000
SPI_ADDR_FULL_SS = 0x6D0000
SPI_ADDR_LITE_SS = 0x730000
SPI_ADDR_VPX_REGDEF = 0x790000
SPI_ADDR_PPX_LEDCAL = 0x7A0000
SPI_ADDR_VPX_LEDCUR = 0x7B0000
SPI_ADDR_VPX_VCALIB = 0x7C0000
SPI_ADDR_VPX_ANALOG = 0x7D0000
SPI_ADDR_PPX_HS_LUT = 0x7D0000
SPI_ADDR_PPX_HS_POS = 0x7D6000
SPI_ADDR_VPX_EDID = 0x7E0000
SPI_ADDR_VPX_TEXT = 0x7F0000
SPI_ADDR_PPX_DDD = 0x300000
SPI_ADDR_PPX_SS = 0x400000
SPI_ADDR_DP3_CALIB = 0x1FD0000
SPI_ADDR_PPX_LEDMAXD65 = (SPI_ADDR_PPX_LEDCAL + 0x0000)
SPI_ADDR_PPX_LEDMAXCUR = (SPI_ADDR_PPX_LEDCAL + 0xFF00)
SPI_ADDR_PPX_LEDMAXD65_GREY0 = (SPI_ADDR_PPX_LEDCAL + 0x0060)
SPI_ADDR_PPX_LEDMAXD65_GREY1 = (SPI_ADDR_PPX_LEDCAL + 0x0070)
SPI_ADDR_PPX_LEDCUSTOM_RGB0 = (SPI_ADDR_PPX_LEDCAL + 0x0080)
SPI_ADDR_PPX_LEDCUSTOM_RGB1 = (SPI_ADDR_PPX_LEDCAL + 0x0090)
SPI_ADDR_PPX_LEDMAXD65_CAL_HBD = (SPI_ADDR_PPX_LEDCAL + 0x0100)
# Relationship between LED current, and voltage DAC setting:
# V = I * 30 * R(0.001 Ohm)
# V = 2.5 * VDAC / 65536
# VDAC = I * 30 * 0.001 * 65536 / 2.5
# = I * 786.432
PPX_LEDCUR_TO_VDAC = 786.432
TPX_IMG_ADDR = 0x75EEC000
errors = [
('DPX_SUCCESS',0,'Function executed successfully'),
('DPX_FAIL',-1,'Generic failure code'),
('DPX_ERR_USB_NO_DATAPIXX',-1000,'No DATAPixx was found'),
('DPX_ERR_USB_RAW_EZUSB',-1001,'EZ-USB appears to have no firmware'),
('DPX_ERR_USB_RAW_FPGA',-1002,'FPGA appears to be unconfigured'),
('DPX_ERR_USB_OPEN',-1003,'An error occurred while opening a USB channel'),
('DPX_ERR_USB_OPEN_FPGA',-1004,'An FPGA detection error occurred while opening DATAPixx'),
('DPX_ERR_USB_SET_CONFIG',-1005,'Could not set the USB configuration'),
('DPX_ERR_USB_CLAIM_INTERFACE',-1006,'Could not claim the USB interface'),
('DPX_ERR_USB_ALT_INTERFACE',-1007,'Could not set the USB alternate interface'),
('DPX_ERR_USB_UNKNOWN_DPID',-1008,'Unrecognized DATAPixx ID register value'),
('DPX_ERR_USB_REG_BULK_WRITE',-1009,'USB error while writing register set'),
('DPX_ERR_USB_REG_BULK_READ',-1010,'USB error while reading register set'),
('DPX_ERR_USB_DEVSEL_INDEX',-1011,'Illegal device index'),
('DPX_ERR_USB_SYSDEVSEL_INDEX',-1012,'Illegal system device index'),
('DPX_ERR_SPI_START',-1100,'SPI communication startup error'),
('DPX_ERR_SPI_STOP',-1101,'SPI communication termination error'),
('DPX_ERR_SPI_READ',-1102,'SPI communication read error'),
('DPX_ERR_SPI_WRITE',-1103,'SPI communication write error'),
('DPX_ERR_SPI_ERASE',-1104,'SPI communication erase error'),
('DPX_ERR_SPI_WAIT_DONE',-1105,'SPI communication error while waiting for SPI write to complete'),
('DPX_ERR_SETREG16_ADDR_ODD',-1200,'DPxSetReg16 passed an odd address'),
('DPX_ERR_SETREG16_ADDR_RANGE',-1201,'DPxSetReg16 passed an address which was out of range'),
('DPX_ERR_SETREG16_DATA_RANGE',-1202,'DPxSetReg16 passed a datum which was out of range'),
('DPX_ERR_GETREG16_ADDR_ODD',-1203,'DPxGetReg16 passed an odd address'),
('DPX_ERR_GETREG16_ADDR_RANGE',-1204,'DPxGetReg16 passed an address which was out of range'),
('DPX_ERR_SETREG32_ADDR_ALIGN',-1205,'DPxSetReg32 passed an address which was not 32-bit aligned'),
('DPX_ERR_SETREG32_ADDR_RANGE',-1206,'DPxSetReg32 passed an address which was out of range'),
('DPX_ERR_GETREG32_ADDR_ALIGN',-1207,'DPxGetReg32 passed an address which was not 32-bit aligned'),
('DPX_ERR_GETREG32_ADDR_RANGE',-1208,'DPxGetReg32 passed an address which was out of range'),
('DPX_ERR_NANO_MARK_NULL_PTR',-1301,'A pointer argument was null'),
('DPX_ERR_NANO_TIME_NULL_PTR',-1300,'A pointer argument was null'),
('DPX_ERR_UNKNOWN_PART_NUMBER',-1302,'Unrecognized part number'),
('DPX_ERR_RAM_UNKNOWN_SIZE',-1400,'Unrecognized RAM configuration'),
('DPX_ERR_RAM_WRITEREAD_FAIL',-1401,'RAM read did not return same value written'),
('DPX_ERR_RAM_WRITE_ADDR_ODD',-1402,'RAM write buffer address must be even'),
('DPX_ERR_RAM_WRITE_LEN_ODD',-1403,'RAM write buffer length must be even'),
('DPX_ERR_RAM_WRITE_TOO_HIGH',-1404,'RAM write block exceeds end of DATAPixx memory'),
('DPX_ERR_RAM_WRITE_BUFFER_NULL',-1405,'RAM write source buffer pointer is null'),
('DPX_ERR_RAM_WRITE_USB_ERROR',-1406,'A USB error occurred while writing the RAM buffer'),
('DPX_ERR_RAM_READ_ADDR_ODD',-1407,'RAM read buffer address must be even'),
('DPX_ERR_RAM_READ_LEN_ODD',-1408,'RAM read buffer length must be even'),
('DPX_ERR_RAM_READ_TOO_HIGH',-1409,'RAM read block exceeds end of DATAPixx memory'),
('DPX_ERR_RAM_READ_BUFFER_NULL',-1410,'RAM read destination buffer pointer is null'),
('DPX_ERR_RAM_READ_USB_ERROR',-1411,'A USB error occurred while reading the RAM buffer'),
('DPX_ERR_DAC_SET_BAD_CHANNEL',-1500,'Valid channels are 0-3'),
('DPX_ERR_DAC_SET_BAD_VALUE',-1501,'Value falls outside DAC''s output range'),
('DPX_ERR_DAC_GET_BAD_CHANNEL',-1502,'Valid channels are 0-3'),
('DPX_ERR_DAC_RANGE_NULL_PTR',-1503,'A pointer argument was null'),
('DPX_ERR_DAC_RANGE_BAD_CHANNEL',-1504,'Valid channels are 0-3'),
('DPX_ERR_DAC_BUFF_BAD_CHANNEL',-1505,'Valid channels are 0-3'),
('DPX_ERR_DAC_BUFF_ODD_BASEADDR',-1506,'An odd buffer base was requested'),
('DPX_ERR_DAC_BUFF_BASEADDR_TOO_HIGH',-1507,'The requested buffer is larger than the DATAPixx RAM'),
('DPX_ERR_DAC_BUFF_ODD_READADDR',-1508,'An odd buffer read address was requested'),
('DPX_ERR_DAC_BUFF_READADDR_TOO_HIGH',-1509,'The requested read address exceeds the DATAPixx RAM'),
('DPX_ERR_DAC_BUFF_ODD_WRITEADDR',-1510,'An odd buffer write address was requested'),
('DPX_ERR_DAC_BUFF_WRITEADDR_TOO_HIGH',-1511,'The requested write address exceeds the DATAPixx RAM'),
('DPX_ERR_DAC_BUFF_ODD_SIZE',-1512,'An odd buffer size was requested'),
('DPX_ERR_DAC_BUFF_TOO_BIG',-1513,'The requested buffer is larger than the DATAPixx RAM'),
('DPX_ERR_DAC_SCHED_TOO_FAST',-1514,'The requested schedule rate is too fast'),
('DPX_ERR_DAC_SCHED_BAD_RATE_UNITS',-1515,'Unnrecognized schedule rate units parameter'),
('DPX_ERR_ADC_GET_BAD_CHANNEL',-1600,'Valid channels are 0-17'),
('DPX_ERR_ADC_RANGE_NULL_PTR',-1601,'A pointer argument was null'),
('DPX_ERR_ADC_RANGE_BAD_CHANNEL',-1602,'Valid channels are 0-17'),
('DPX_ERR_ADC_REF_BAD_CHANNEL',-1603,'Valid channels are 0-15'),
('DPX_ERR_ADC_BAD_CHAN_REF',-1604,'Unrecognized channel reference parameter'),
('DPX_ERR_ADC_BUFF_BAD_CHANNEL',-1605,'Valid channels are 0-15'),
('DPX_ERR_ADC_BUFF_ODD_BASEADDR',-1606,'An odd buffer base was requested'),
('DPX_ERR_ADC_BUFF_BASEADDR_TOO_HIGH',-1607,'The requested buffer is larger than the DATAPixx RAM'),
('DPX_ERR_ADC_BUFF_ODD_READADDR',-1608,'An odd buffer read address was requested'),
('DPX_ERR_ADC_BUFF_READADDR_TOO_HIGH',-1609,'The requested read address exceeds the DATAPixx RAM'),
('DPX_ERR_ADC_BUFF_ODD_WRITEADDR',-1610,'An odd buffer write address was requested'),
('DPX_ERR_ADC_BUFF_WRITEADDR_TOO_HIGH',-1611,'The requested write address exceeds the DATAPixx RAM'),
('DPX_ERR_ADC_BUFF_ODD_SIZE',-1612,'An odd buffer size was requested'),
('DPX_ERR_ADC_BUFF_TOO_BIG',-1613,'The requested buffer is larger than the DATAPixx RAM'),
('DPX_ERR_ADC_SCHED_TOO_FAST',-1614,'The requested schedule rate is too fast'),
('DPX_ERR_ADC_SCHED_BAD_RATE_UNITS',-1615,'Unnrecognized schedule rate units parameter'),
('DPX_ERR_DOUT_SET_BAD_MASK',-1700,'Valid masks set bits 23 downto 0'),
('DPX_ERR_DOUT_BUFF_ODD_BASEADDR',-1701,'An odd buffer base was requested'),
('DPX_ERR_DOUT_BUFF_BASEADDR_TOO_HIGH',-1702,'The requested buffer is larger than the DATAPixx RAM'),
('DPX_ERR_DOUT_BUFF_ODD_READADDR',-1703,'An odd buffer read address was requested'),
('DPX_ERR_DOUT_BUFF_READADDR_TOO_HIGH',-1704,'The requested read address exceeds the DATAPixx RAM'),
('DPX_ERR_DOUT_BUFF_ODD_WRITEADDR',-1705,'An odd buffer write address was requested'),
('DPX_ERR_DOUT_BUFF_WRITEADDR_TOO_HIGH',-1706,'The requested write address exceeds the DATAPixx RAM'),
('DPX_ERR_DOUT_BUFF_ODD_SIZE',-1707,'An odd buffer size was requested'),
('DPX_ERR_DOUT_BUFF_TOO_BIG',-1708,'The requested buffer is larger than the DATAPixx RAM'),
('DPX_ERR_DOUT_SCHED_TOO_FAST',-1709,'The requested schedule rate is too fast'),
('DPX_ERR_DOUT_SCHED_BAD_RATE_UNITS',-1710,'Unnrecognized schedule rate units parameter'),
('DPX_ERR_DIN_SET_BAD_MASK',-1800,'Valid masks set bits 23 downto 0'),
('DPX_ERR_DIN_BUFF_ODD_BASEADDR',-1801,'An odd buffer base was requested'),
('DPX_ERR_DIN_BUFF_BASEADDR_TOO_HIGH',-1802,'The requested buffer is larger than the DATAPixx RAM'),
('DPX_ERR_DIN_BUFF_ODD_READADDR',-1803,'An odd buffer read address was requested'),
('DPX_ERR_DIN_BUFF_READADDR_TOO_HIGH',-1804,'The requested read address exceeds the DATAPixx RAM'),
('DPX_ERR_DIN_BUFF_ODD_WRITEADDR',-1805,'An odd buffer write address was requested'),
('DPX_ERR_DIN_BUFF_WRITEADDR_TOO_HIGH',-1806,'The requested write address exceeds the DATAPixx RAM'),
('DPX_ERR_DIN_BUFF_ODD_SIZE',-1807,'An odd buffer size was requested'),
('DPX_ERR_DIN_BUFF_TOO_BIG',-1808,'The requested buffer is larger than the DATAPixx RAM'),
('DPX_ERR_DIN_SCHED_TOO_FAST',-1809,'The requested schedule rate is too fast'),
('DPX_ERR_DIN_SCHED_BAD_RATE_UNITS',-1810,'Unnrecognized schedule rate units parameter'),
('DPX_ERR_DIN_BAD_STRENGTH',-1811,'Strength is in the range 0-1'),
('DPX_ERR_AUD_SET_BAD_VALUE',-1900,'Value falls outside AUD''s output range'),
('DPX_ERR_AUD_SET_BAD_VOLUME',-1901,'Valid volumes are in the range 0-1'),
('DPX_ERR_AUD_SET_BAD_LRMODE',-1902,'See DPxSetAudLRMode() for valid values'),
('DPX_ERR_AUD_BUFF_ODD_BASEADDR',-1903,'An odd buffer base was requested'),
('DPX_ERR_AUD_BUFF_BASEADDR_TOO_HIGH',-1904,'The requested buffer is larger than the DATAPixx RAM'),
('DPX_ERR_AUD_BUFF_ODD_READADDR',-1905,'An odd buffer read address was requested'),
('DPX_ERR_AUD_BUFF_READADDR_TOO_HIGH',-1906,'The requested read address exceeds the DATAPixx RAM'),
('DPX_ERR_AUD_BUFF_ODD_WRITEADDR',-1907,'An odd buffer write address was requested'),
('DPX_ERR_AUD_BUFF_WRITEADDR_TOO_HIGH',-1908,'The requested write address exceeds the DATAPixx RAM'),
('DPX_ERR_AUD_BUFF_ODD_SIZE',-1909,'An odd buffer size was requested'),
('DPX_ERR_AUD_BUFF_TOO_BIG',-1910,'The requested buffer is larger than the DATAPixx RAM'),
('DPX_ERR_AUX_BUFF_ODD_BASEADDR',-1911,'An odd buffer base was requested'),
('DPX_ERR_AUX_BUFF_BASEADDR_TOO_HIGH',-1912,'The requested buffer is larger than the DATAPixx RAM'),
('DPX_ERR_AUX_BUFF_ODD_READADDR',-1913,'An odd buffer read address was requested'),
('DPX_ERR_AUX_BUFF_READADDR_TOO_HIGH',-1914,'The requested read address exceeds the DATAPixx RAM'),
('DPX_ERR_AUX_BUFF_ODD_WRITEADDR',-1915,'An odd buffer write address was requested'),
('DPX_ERR_AUX_BUFF_WRITEADDR_TOO_HIGH',-1916,'The requested write address exceeds the DATAPixx RAM'),
('DPX_ERR_AUX_BUFF_ODD_SIZE',-1917,'An odd buffer size was requested'),
('DPX_ERR_AUX_BUFF_TOO_BIG',-1918,'The requested buffer is larger than the DATAPixx RAM'),
('DPX_ERR_AUD_SCHED_TOO_FAST',-1919,'The requested schedule rate is too fast'),
('DPX_ERR_AUD_SCHED_TOO_SLOW',-1920,'The requested schedule rate is too slow'),
('DPX_ERR_AUD_SCHED_BAD_RATE_UNITS',-1921,'Unnrecognized schedule rate units parameter'),
('DPX_ERR_AUD_CODEC_POWERUP',-1922,'The CODEC didn''t set its internal powerup bits'),
('DPX_ERR_MIC_SET_GAIN_TOO_LOW',-2000,'See DPxSetMicSource() for valid values'),
('DPX_ERR_MIC_SET_GAIN_TOO_HIGH',-2001,'See DPxSetMicSource() for valid values'),
('DPX_ERR_MIC_SET_BAD_SOURCE',-2002,'See DPxSetMicSource() for valid values'),
('DPX_ERR_MIC_SET_BAD_LRMODE',-2003,'See DPxSetMicLRMode() for valid values'),
('DPX_ERR_MIC_BUFF_ODD_BASEADDR',-2004,'An odd buffer base was requested'),
('DPX_ERR_MIC_BUFF_BASEADDR_TOO_HIGH',-2005,'The requested buffer is larger than the DATAPixx RAM'),
('DPX_ERR_MIC_BUFF_ODD_READADDR',-2006,'An odd buffer read address was requested'),
('DPX_ERR_MIC_BUFF_READADDR_TOO_HIGH',-2007,'The requested read address exceeds the DATAPixx RAM'),
('DPX_ERR_MIC_BUFF_ODD_WRITEADDR',-2008,'An odd buffer write address was requested'),
('DPX_ERR_MIC_BUFF_WRITEADDR_TOO_HIGH',-2009,'The requested write address exceeds the DATAPixx RAM'),
('DPX_ERR_MIC_BUFF_ODD_SIZE',-2010,'An odd buffer size was requested'),
('DPX_ERR_MIC_BUFF_TOO_BIG',-2011,'The requested buffer is larger than the DATAPixx RAM'),
('DPX_ERR_MIC_SCHED_TOO_FAST',-2012,'The requested schedule rate is too fast'),
('DPX_ERR_MIC_SCHED_BAD_RATE_UNITS',-2013,'Unnrecognized schedule rate units parameter'),
('DPX_ERR_VID_SET_BAD_MODE',-2100,'See DPxSetVidMode() for valid values'),
('DPX_ERR_VID_CLUT_WRITE_USB_ERROR',-2101,'A USB error occurred while writing a video CLUT'),
('DPX_ERR_VID_VSYNC_USB_ERROR',-2102,'A USB error occurred while waiting for vertical sync'),
('DPX_ERR_VID_EDID_WRITE_USB_ERROR',-2103,'A USB error occurred while writing EDID data'),
('DPX_ERR_VID_LINE_READ_USB_ERROR',-2104,'A USB error occurred while reading the video line buffer'),
('DPX_ERR_VID_PSYNC_NPIXELS_ARG_ERROR',-2105,'Pixel sync nPixels argument must be in the range 1-8'),
('DPX_ERR_VID_PSYNC_TIMEOUT_ARG_ERROR',-2106,'Pixel sync timeout argument must be in the range 0-65535'),
('DPX_ERR_VID_PSYNC_LINE_ARG_ERROR',-2107,'Pixel sync raster line argument must be in the range 0-4095'),
('DPX_ERR_VID_ALPHA_WRITE_USB_ERROR',-2108,'A USB error occurred while writing video horizontal overlay alpha data'),
('DPX_ERR_VID_BASEADDR_ALIGN_ERROR',-2109,'The requested base address was not aligned on a 64kB boundary'),
('DPX_ERR_VID_BASEADDR_TOO_HIGH',-2110,'The requested base address exceeds the DATAPixx RAM'),
('DPX_ERR_VID_VSYNC_WITHOUT_VIDEO',-2111,'The API was told to block until VSYNC; but DATAPixx is not receiving any video'),
('DPX_ERR_VID_BL_INTENSITY_ARG_ERROR',-2112, 'Backlight intensity argument must be in the range 0-255'),
('DPX_ERR_PPX_BAD_VOLTAGE',-3000,''),
('DPX_ERR_PPX_BAD_TEMP',-3001,''),
('DPX_ERR_PPX_BAD_LED',-3002,''),
('DPX_ERR_PPX_BAD_FAN',-3003,''),
('DPX_ERR_PPX_BAD_LED_CURRENT',-3004,''),
('DPX_ERR_PPX_SEQ_WRITE_USB_ERROR',-3005,'A USB error occurred while writing a video sequence'),
('DPX_ERR_TRK_QL_ERROR_INVALID_DEVICE_ID' ,-3300, 'The input device ID is invalid.'),
('DPX_ERR_TRK_QL_ERROR_INVALID_SETTINGS_ID' ,-3301,'The input settings ID is invalid.'),
('DPX_ERR_TRK_QL_ERROR_INVALID_CALIBRATION_ID' ,-3302, 'The input calibration ID is invalid.'),
('DPX_ERR_TRK_QL_ERROR_INVALID_TARGET_ID' ,-3303, 'The input target ID is invalid.'),
('DPX_ERR_TRK_QL_ERROR_INVALID_PASSWORD' ,-3304, 'The password for the device is not valid.'),
('DPX_ERR_TRK_QL_ERROR_INVALID_PATH' ,-3305, 'The input path is invalid.'),
('DPX_ERR_TRK_QL_ERROR_INVALID_DURATION' ,-3306, 'The input duration is invalid.'),
('DPX_ERR_TRK_QL_ERROR_INVALID_POINTER' ,-3307, 'The input pointer is NULL.'),
('DPX_ERR_TRK_QL_ERROR_TIMEOUT_ELAPSED' ,-3308, 'The timeout time was reached.'),
('DPX_ERR_TRK_QL_ERROR_INTERNAL_ERROR' ,-3309, 'An internal error occurred. Contact EyeTech for further help.'),
('DPX_ERR_TRK_QL_ERROR_BUFFER_TOO_SMALL' ,-3310, 'The input buffer is is not large enough.'),
('DPX_ERR_TRK_QL_ERROR_CALIBRAION_NOT_INITIALIZED' ,-3311, 'The calibration container has not been initialized. See QLCalibration_Initialize()'),
('DPX_ERR_TRK_QL_ERROR_DEVICE_NOT_STARTED' ,-3312,'The device has not been started. See QLDevice_Start()'),
('DPX_ERR_TRK_QL_ERROR_NOT_SUPPORTED' ,-3313, 'The setting is not supported by the given device. See QLDevice_IsSettingSupported()'),
('DPX_ERR_TRK_QL_ERROR_NOT_FOUND' ,-3314, 'The setting is not in the settings container.'),
('DPX_ERR_TRK_QL_ERROR_UNAUTHORIZED_APPLICATION_RUNNING' ,-3315,'The API has detected that an unauthorized application is running on the computer. '),
('DPX_ERR_TRK_QL_ERROR_INVALID_DEVICE_GROUP_ID' ,-3316,'The input device group ID is invalid.'),
('DPX_ERR_TRK_QL_TARGET_NOT_CALIBRATED' ,-3317,'The target is not calibrated properly.'),
('DPX_ERR_TRK_QL_DEVICE_IS_NOT_REGISTERED' ,-3318, 'The device is not registered in the licence file.'),
('DPX_ERR_SERVER_IP_NOT_VALID' ,-5000, 'Error raised when in USB-Over-TCP mode and server Ip is not valid.'),
('DPX_ERR_SERVER_NOT_FOUND' ,-5001, 'Server not found. Probably because server is not started or has failed to start.'),]
err = dict([(error[0],error[1]) for error in errors])
err_return = dict([(error[1],error[0]) for error in errors])
detailed_error = dict([(error[0],error[2]) for error in errors])