jupyterpidaq.Boards.boards
This file handles loading adc board control software and sensor information. It uses the list of known boards. It will skip boards that produce an error either because the pypi package is not installed or an error occurs when trying to communicate with the board.
The ADC simulator will be installed if no boards are available.
1""" 2This file handles loading adc board control software and sensor information. 3It uses the list of known boards. It will skip boards that produce an error 4either because the pypi package is not installed or an error occurs when 5trying to communicate with the board. 6 7The ADC simulator will be installed if no boards are available. 8""" 9from importlib import import_module 10import logging 11 12logger = logging.getLogger(__name__) 13 14# TODO: Update this list of available board options as they are created. 15# Name format is `.package.boardname` where `boardname` is the name of the 16# python file defining the required board operations. 17 18knownboardpkgs = ('jupyterpidaq.Boards.PiGPIO.ADS1115', 19 'jupyterpidaq.Boards.PiGPIO.DAQC2', 20 'jupyterpidaq.Boards.vernier.labquest') 21knownsimulators = ('jupyterpidaq.Boards.Simulated.ADCsim', 22 'jupyterpidaq.Boards.Simulated.ADCsim_line') 23 24 25def load_boards(): 26 """ 27 Uses the list of known board packages to search for available boards. 28 The file <boardname>.py should at minimum 29 implement a `find_boards(): routine that overrides the function below and 30 define a class for the particular board that extends the `Board` class 31 defined below. 32 33 :return: list of adc board objects. 34 """ 35 # Load available board driver packages 36 boardpkgs = [] 37 for pkg in knownboardpkgs: 38 tmpmod = None 39 try: 40 tmpmod = import_module(pkg) 41 except (ImportError, RuntimeError) as e: 42 logger.debug(e) 43 tmpmod = None 44 if (tmpmod): 45 boardpkgs.append(tmpmod) 46 logging.log(logging.DEBUG,str(boardpkgs)) 47 48 # Check for available boards 49 boards = [] 50 if len(boardpkgs) >= 1: 51 # All board pkgs must implement `find_boards(). 52 for drv in boardpkgs: 53 avail = drv.find_boards() 54 for hdw in avail: 55 boards.append(hdw) 56 if len(boards) == 0: 57 # We found no boards 58 print('\nNo ADC boards found. Using simulated boards...',end='') 59 boards = _load_simulators() 60 return boards 61 62def find_boards(): 63 """ 64 A function overriding this must be implemented by all board packages. 65 See examples in working packages. This is highly board dependent. 66 67 :return: list of board objects 68 """ 69 raise NotImplementedError 70 71def _load_simulators(): 72 """ 73 Private function to add simulated ADC boards 74 :return: 75 boards list of adc board objects. 76 """ 77 simpkgs = [] 78 boards = [] 79 tmpmod = None 80 for sim in knownsimulators: 81 try: 82 tmpmod = import_module(sim) 83 except ImportError as e: 84 logger.debug(e) 85 tmpmod = None 86 if (tmpmod): 87 simpkgs.append(tmpmod) 88 logging.log(logging.DEBUG,str(simpkgs)) 89 if len(simpkgs) >= 1: 90 # All board pkgs must implement `find_boards(). 91 for drv in simpkgs: 92 avail = drv.find_boards() 93 logging.log(logging.DEBUG,str(avail)) 94 if avail: 95 boards.append(avail) 96 return boards 97 98 99class Board: 100 """ 101 Base class for all boards. Each board should be an extension of this class. 102 """ 103 def __init__(self): 104 """ 105 Should be overridden by each board and define at minimum: 106 self.name = 'board name/adc name/type' Short an useful to end user 107 self.vendor = 'Vendor/Manufacturer name` 108 self.channels = tuple of available channel IDs 109 self.gains = list of gains 110 self.Vdd = voltage provided by board to sensors 111 """ 112 self.name = None 113 self.vendor = None 114 self.channels = None 115 self.gains = [1] 116 self.Vdd = None 117 118 def getname(self): 119 """ 120 :return: string value of the board name, a short label of board type. 121 """ 122 return self.name 123 124 def getchannels(self): 125 """ 126 :return: tuple of ids for available channels 127 """ 128 return self.channels 129 130 def getgains(self): 131 """ 132 If not defined for a specific board the gain is fixed at 1. 133 :return: tuple of gains availabe for onboard preamp 134 """ 135 return self.gains 136 137 def getvendor(self): 138 """ 139 :return: string value of the vendor name 140 """ 141 return self.vendor 142 143 def getVdd(self): 144 """ 145 :return: numerical value of the Vdd, voltage provided to sensors 146 """ 147 return self.Vdd 148 149 def getsensors(self): 150 """ 151 This returns a list of objects that allow the software to translate 152 the measured voltage into a sensor reading in appropriate units. 153 Must be provided by the specific board implementation. See examples 154 in working board packages. 155 :return: A list of valid sensor objects to use with this board. This 156 should be a subset of all the sensors returned by the listSensors 157 function in sensors.py. 158 """ 159 raise NotImplementedError 160 161 def V_oversampchan(self, chan, gain, avg_sec, **kwargs): 162 """ 163 This function should return a tuple with average, minimum and maximum 164 for a channel averaged over the period of time avg_sec. How the 165 averaging is performed will depend on the board. 166 :param chan: id of the channel to be measured 167 :param gain: gain of the channel if adjustable 168 :param avg_sec: float period of time over which to average 169 :return: a tuple consisting of V_avg, V_min, V_max, time_stamp, avg_Vdd 170 The time_stamp is the time the data was collected, usually the 171 middle of the averaging period. avg_Vdd should be the measured 172 average Vdd taken simultaneously, immediately before, 173 or immediately after the voltage being measured. If the board or 174 power supply is very stable self.Vdd can be returned instead. 175 """ 176 raise NotImplementedError 177 178 def V_oversampchan_stats(self, chan, gain, avg_sec, **kwargs): 179 """ 180 This function should return a tuple of statistical information for a 181 channel averaged over the period of time avg_sec. 182 :param chan: id of the channel to be measured 183 :param gain: gain of the channel if adjustable 184 :param avg_sec: float period of time over which to average 185 :return: tuple consisting of V_avg, stdev, stdev_avg, time_stamp, 186 avg_Vdd where stdev_avg is the estimated standard deviation 187 of the average not the standard deviation of the values 188 sampled (stdev). avg_Vdd should be the measured 189 average Vdd taken simultaneously, immediately before, 190 or immediately after the voltage being measured. If the board or 191 power supply is very stable self.Vdd can be returned instead. 192 """ 193 raise NotImplementedError 194 195 def V_sampchan(self, chan, gain, **kwargs): 196 """ 197 This function returns a single measurement and the time it was 198 collected. 199 :param chan: id of the channel to be measured 200 :param gain: gain of the channel if adjustable 201 :return: a tuple consisting of V, time_stamp, ref_Vdd, where V = the 202 single voltage measurement and time_stamp the time it was 203 collected. ref_Vdd should be the measured 204 Vdd taken simultaneously, immediately before, 205 or immediately after the voltage being measured. If the board or 206 power supply is very stable self.Vdd can be returned instead. 207 """ 208 raise NotImplementedError
26def load_boards(): 27 """ 28 Uses the list of known board packages to search for available boards. 29 The file <boardname>.py should at minimum 30 implement a `find_boards(): routine that overrides the function below and 31 define a class for the particular board that extends the `Board` class 32 defined below. 33 34 :return: list of adc board objects. 35 """ 36 # Load available board driver packages 37 boardpkgs = [] 38 for pkg in knownboardpkgs: 39 tmpmod = None 40 try: 41 tmpmod = import_module(pkg) 42 except (ImportError, RuntimeError) as e: 43 logger.debug(e) 44 tmpmod = None 45 if (tmpmod): 46 boardpkgs.append(tmpmod) 47 logging.log(logging.DEBUG,str(boardpkgs)) 48 49 # Check for available boards 50 boards = [] 51 if len(boardpkgs) >= 1: 52 # All board pkgs must implement `find_boards(). 53 for drv in boardpkgs: 54 avail = drv.find_boards() 55 for hdw in avail: 56 boards.append(hdw) 57 if len(boards) == 0: 58 # We found no boards 59 print('\nNo ADC boards found. Using simulated boards...',end='') 60 boards = _load_simulators() 61 return boards
Uses the list of known board packages to search for available boards.
The file find_boards(): routine that overrides the function below and
define a class for the particular board that extends the
Board` class
defined below.
Returns
list of adc board objects.
63def find_boards(): 64 """ 65 A function overriding this must be implemented by all board packages. 66 See examples in working packages. This is highly board dependent. 67 68 :return: list of board objects 69 """ 70 raise NotImplementedError
A function overriding this must be implemented by all board packages. See examples in working packages. This is highly board dependent.
Returns
list of board objects
100class Board: 101 """ 102 Base class for all boards. Each board should be an extension of this class. 103 """ 104 def __init__(self): 105 """ 106 Should be overridden by each board and define at minimum: 107 self.name = 'board name/adc name/type' Short an useful to end user 108 self.vendor = 'Vendor/Manufacturer name` 109 self.channels = tuple of available channel IDs 110 self.gains = list of gains 111 self.Vdd = voltage provided by board to sensors 112 """ 113 self.name = None 114 self.vendor = None 115 self.channels = None 116 self.gains = [1] 117 self.Vdd = None 118 119 def getname(self): 120 """ 121 :return: string value of the board name, a short label of board type. 122 """ 123 return self.name 124 125 def getchannels(self): 126 """ 127 :return: tuple of ids for available channels 128 """ 129 return self.channels 130 131 def getgains(self): 132 """ 133 If not defined for a specific board the gain is fixed at 1. 134 :return: tuple of gains availabe for onboard preamp 135 """ 136 return self.gains 137 138 def getvendor(self): 139 """ 140 :return: string value of the vendor name 141 """ 142 return self.vendor 143 144 def getVdd(self): 145 """ 146 :return: numerical value of the Vdd, voltage provided to sensors 147 """ 148 return self.Vdd 149 150 def getsensors(self): 151 """ 152 This returns a list of objects that allow the software to translate 153 the measured voltage into a sensor reading in appropriate units. 154 Must be provided by the specific board implementation. See examples 155 in working board packages. 156 :return: A list of valid sensor objects to use with this board. This 157 should be a subset of all the sensors returned by the listSensors 158 function in sensors.py. 159 """ 160 raise NotImplementedError 161 162 def V_oversampchan(self, chan, gain, avg_sec, **kwargs): 163 """ 164 This function should return a tuple with average, minimum and maximum 165 for a channel averaged over the period of time avg_sec. How the 166 averaging is performed will depend on the board. 167 :param chan: id of the channel to be measured 168 :param gain: gain of the channel if adjustable 169 :param avg_sec: float period of time over which to average 170 :return: a tuple consisting of V_avg, V_min, V_max, time_stamp, avg_Vdd 171 The time_stamp is the time the data was collected, usually the 172 middle of the averaging period. avg_Vdd should be the measured 173 average Vdd taken simultaneously, immediately before, 174 or immediately after the voltage being measured. If the board or 175 power supply is very stable self.Vdd can be returned instead. 176 """ 177 raise NotImplementedError 178 179 def V_oversampchan_stats(self, chan, gain, avg_sec, **kwargs): 180 """ 181 This function should return a tuple of statistical information for a 182 channel averaged over the period of time avg_sec. 183 :param chan: id of the channel to be measured 184 :param gain: gain of the channel if adjustable 185 :param avg_sec: float period of time over which to average 186 :return: tuple consisting of V_avg, stdev, stdev_avg, time_stamp, 187 avg_Vdd where stdev_avg is the estimated standard deviation 188 of the average not the standard deviation of the values 189 sampled (stdev). avg_Vdd should be the measured 190 average Vdd taken simultaneously, immediately before, 191 or immediately after the voltage being measured. If the board or 192 power supply is very stable self.Vdd can be returned instead. 193 """ 194 raise NotImplementedError 195 196 def V_sampchan(self, chan, gain, **kwargs): 197 """ 198 This function returns a single measurement and the time it was 199 collected. 200 :param chan: id of the channel to be measured 201 :param gain: gain of the channel if adjustable 202 :return: a tuple consisting of V, time_stamp, ref_Vdd, where V = the 203 single voltage measurement and time_stamp the time it was 204 collected. ref_Vdd should be the measured 205 Vdd taken simultaneously, immediately before, 206 or immediately after the voltage being measured. If the board or 207 power supply is very stable self.Vdd can be returned instead. 208 """ 209 raise NotImplementedError
Base class for all boards. Each board should be an extension of this class.
104 def __init__(self): 105 """ 106 Should be overridden by each board and define at minimum: 107 self.name = 'board name/adc name/type' Short an useful to end user 108 self.vendor = 'Vendor/Manufacturer name` 109 self.channels = tuple of available channel IDs 110 self.gains = list of gains 111 self.Vdd = voltage provided by board to sensors 112 """ 113 self.name = None 114 self.vendor = None 115 self.channels = None 116 self.gains = [1] 117 self.Vdd = None
Should be overridden by each board and define at minimum: self.name = 'board name/adc name/type' Short an useful to end user self.vendor = 'Vendor/Manufacturer name` self.channels = tuple of available channel IDs self.gains = list of gains self.Vdd = voltage provided by board to sensors
119 def getname(self): 120 """ 121 :return: string value of the board name, a short label of board type. 122 """ 123 return self.name
Returns
string value of the board name, a short label of board type.
125 def getchannels(self): 126 """ 127 :return: tuple of ids for available channels 128 """ 129 return self.channels
Returns
tuple of ids for available channels
131 def getgains(self): 132 """ 133 If not defined for a specific board the gain is fixed at 1. 134 :return: tuple of gains availabe for onboard preamp 135 """ 136 return self.gains
If not defined for a specific board the gain is fixed at 1.
Returns
tuple of gains availabe for onboard preamp
138 def getvendor(self): 139 """ 140 :return: string value of the vendor name 141 """ 142 return self.vendor
Returns
string value of the vendor name
144 def getVdd(self): 145 """ 146 :return: numerical value of the Vdd, voltage provided to sensors 147 """ 148 return self.Vdd
Returns
numerical value of the Vdd, voltage provided to sensors
150 def getsensors(self): 151 """ 152 This returns a list of objects that allow the software to translate 153 the measured voltage into a sensor reading in appropriate units. 154 Must be provided by the specific board implementation. See examples 155 in working board packages. 156 :return: A list of valid sensor objects to use with this board. This 157 should be a subset of all the sensors returned by the listSensors 158 function in sensors.py. 159 """ 160 raise NotImplementedError
This returns a list of objects that allow the software to translate the measured voltage into a sensor reading in appropriate units. Must be provided by the specific board implementation. See examples in working board packages.
Returns
A list of valid sensor objects to use with this board. This should be a subset of all the sensors returned by the listSensors function in sensors.py.
162 def V_oversampchan(self, chan, gain, avg_sec, **kwargs): 163 """ 164 This function should return a tuple with average, minimum and maximum 165 for a channel averaged over the period of time avg_sec. How the 166 averaging is performed will depend on the board. 167 :param chan: id of the channel to be measured 168 :param gain: gain of the channel if adjustable 169 :param avg_sec: float period of time over which to average 170 :return: a tuple consisting of V_avg, V_min, V_max, time_stamp, avg_Vdd 171 The time_stamp is the time the data was collected, usually the 172 middle of the averaging period. avg_Vdd should be the measured 173 average Vdd taken simultaneously, immediately before, 174 or immediately after the voltage being measured. If the board or 175 power supply is very stable self.Vdd can be returned instead. 176 """ 177 raise NotImplementedError
This function should return a tuple with average, minimum and maximum for a channel averaged over the period of time avg_sec. How the averaging is performed will depend on the board.
Parameters
- chan: id of the channel to be measured
- gain: gain of the channel if adjustable
- avg_sec: float period of time over which to average
Returns
a tuple consisting of V_avg, V_min, V_max, time_stamp, avg_Vdd The time_stamp is the time the data was collected, usually the middle of the averaging period. avg_Vdd should be the measured average Vdd taken simultaneously, immediately before, or immediately after the voltage being measured. If the board or power supply is very stable self.Vdd can be returned instead.
179 def V_oversampchan_stats(self, chan, gain, avg_sec, **kwargs): 180 """ 181 This function should return a tuple of statistical information for a 182 channel averaged over the period of time avg_sec. 183 :param chan: id of the channel to be measured 184 :param gain: gain of the channel if adjustable 185 :param avg_sec: float period of time over which to average 186 :return: tuple consisting of V_avg, stdev, stdev_avg, time_stamp, 187 avg_Vdd where stdev_avg is the estimated standard deviation 188 of the average not the standard deviation of the values 189 sampled (stdev). avg_Vdd should be the measured 190 average Vdd taken simultaneously, immediately before, 191 or immediately after the voltage being measured. If the board or 192 power supply is very stable self.Vdd can be returned instead. 193 """ 194 raise NotImplementedError
This function should return a tuple of statistical information for a channel averaged over the period of time avg_sec.
Parameters
- chan: id of the channel to be measured
- gain: gain of the channel if adjustable
- avg_sec: float period of time over which to average
Returns
tuple consisting of V_avg, stdev, stdev_avg, time_stamp, avg_Vdd where stdev_avg is the estimated standard deviation of the average not the standard deviation of the values sampled (stdev). avg_Vdd should be the measured average Vdd taken simultaneously, immediately before, or immediately after the voltage being measured. If the board or power supply is very stable self.Vdd can be returned instead.
196 def V_sampchan(self, chan, gain, **kwargs): 197 """ 198 This function returns a single measurement and the time it was 199 collected. 200 :param chan: id of the channel to be measured 201 :param gain: gain of the channel if adjustable 202 :return: a tuple consisting of V, time_stamp, ref_Vdd, where V = the 203 single voltage measurement and time_stamp the time it was 204 collected. ref_Vdd should be the measured 205 Vdd taken simultaneously, immediately before, 206 or immediately after the voltage being measured. If the board or 207 power supply is very stable self.Vdd can be returned instead. 208 """ 209 raise NotImplementedError
This function returns a single measurement and the time it was collected.
Parameters
- chan: id of the channel to be measured
- gain: gain of the channel if adjustable
Returns
a tuple consisting of V, time_stamp, ref_Vdd, where V = the single voltage measurement and time_stamp the time it was collected. ref_Vdd should be the measured Vdd taken simultaneously, immediately before, or immediately after the voltage being measured. If the board or power supply is very stable self.Vdd can be returned instead.