Skip to content

Commit

Permalink
Merge pull request #72 from tavurth/master
Browse files Browse the repository at this point in the history
Added await function to alpha
  • Loading branch information
dhhagan authored Jun 27, 2018
2 parents e0b62c1 + 76bfd70 commit d89361d
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions opc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,12 @@ def __init__(self, spi_connection, firmware=None, max_cnxn_retries=5, retry_inte
except:
logger.info("No firmware version could be read.")

# Sleep for a bit to alleviate issues
sleep(1)
# We requested to wait until the device is connected
if kwargs.get('wait', False) is not False:
self.wait(**kwargs)

else: # Sleep for a bit to alleviate issues
sleep(1)

def _16bit_unsigned(self, LSB, MSB):
"""Returns the combined LSB and MSB
Expand Down Expand Up @@ -174,6 +178,31 @@ def _calculate_period(self, vals):
else:
return self._calculate_float(vals)

def wait(self, **kwargs):
"""Wait for the OPC to prepare itself for data transmission. On some devides this can take a few seconds
:rtype: self
:Example:
>> alpha = opc.OPCN2(spi, debug=True).wait(check=200)
>> alpha = opc.OPCN2(spi, debug=True, wait=True, check=200)
"""

if not callable(self.on):
raise UserWarning('Your device does not support the self.on function, try without wait')

if not callable(self.histogram):
raise UserWarning('Your device does not support the self.histogram function, try without wait')

self.on()
while True:
try:
if self.histogram() is None:
raise UserWarning('Could not load histogram, perhaps the device is not yet connected')

except UserWarning as e:
sleep(kwargs.get('check', 200) / 1000.)

return self

def lookup_bin_boundary(self, adc_value):
"""Looks up the bin boundary value in microns based on the lookup table provided by Alphasense.
Expand Down

0 comments on commit d89361d

Please sign in to comment.