Skip to content

Commit

Permalink
Merge pull request #33 from dhhagan/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
dhhagan authored Sep 2, 2016
2 parents 95f7151 + 7859b15 commit 375e062
Show file tree
Hide file tree
Showing 5 changed files with 4,135 additions and 44 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[![Build Status](https://travis-ci.org/dhhagan/py-opc.svg?branch=develop)](https://travis-ci.org/dhhagan/py-opc)
[![PyPI version](https://badge.fury.io/py/py-opc.svg)](https://badge.fury.io/py/py-opc)
[![Coverage Status](https://coveralls.io/repos/dhhagan/py-opc/badge.svg?branch=master&service=github)](https://coveralls.io/github/dhhagan/py-opc?branch=master)
[![Join the chat at https://gitter.im/dhhagan/py-opc](https://badges.gitter.im/dhhagan/py-opc.svg)](https://gitter.im/dhhagan/py-opc?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![DOI](https://zenodo.org/badge/doi/10.5281/zenodo.48803.svg)](http://dx.doi.org/10.5281/zenodo.48803)
Expand Down
72 changes: 31 additions & 41 deletions opc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pkg_resources import get_distribution
from .exceptions import FirmwareVersionError, SpiConnectionError
from .decorators import requires_firmware
from .lookup_table import OPC_LOOKUP

from time import sleep
import spidev
Expand Down Expand Up @@ -48,8 +49,8 @@ def __init__(self, spi_connection, **kwargs):
self.model = kwargs.get('model', 'N2')

# Check to make sure the connection is a valid SpiDev instance
if not isinstance(spi_connection, spidev.SpiDev):
raise SpiConnectionError("This is not an instance of SpiDev.")
assert isinstance(spi_connection, spidev.SpiDev), "The SPI connection must be a valid spidev.SpiDev instance"
assert self.cnxn.mode == 1, "SPI mode must be 1"

# Set the firmware version upon initialization
try:
Expand Down Expand Up @@ -152,21 +153,34 @@ def _calculate_period(self, vals):
else:
return self._calculate_float(vals)

def _calculate_bin_boundary(self, val):
"""Calculates the bin boundary value in micrometers, assuming a 12-bit ADC with 17.5 um Full-Scale.
def lookup_bin_boundary(self, adc_value):
"""Looks up the bin boundary value in microns based on the lookup table provided by Alphasense.
**NOTE**: This is incorrect!
:param adc_value: ADC Value (0 - 4095)
:param val: ADC Value
:type val: int
:type adc_value: int
:rtype: float
"""
fullscale = 17.5 # micrometers
adc = 12
if adc_value < 0:
adc_value = 0

if adc_value > 4095:
adc_value = 4095

return OPC_LOOKUP[adc_value]

def calculate_bin_boundary(self, bb):
"""Calculate the adc value that corresponds to a specific bin boundary diameter in microns.
:param bb: Bin Boundary in microns
return (val / (2**adc - 1)) * fullscale
:type bb: float
:rtype: int
"""

return min(enumerate(OPC_LOOKUP), key = lambda x: abs(x[1] - bb))[0]

def read_info_string(self):
"""Reads the information string for the OPC
Expand Down Expand Up @@ -321,14 +335,6 @@ def config(self):
if self.firmware['major'] > 15.:
data['TOF_SFR'] = config[234]

# Don't know what to do about all of the bytes yet!
if self.debug:
count = 0
print ("Debugging the Config Variables")
for each in config:
print ("\t{0}: {1}".format(count, each))
count += 1

return data

@requires_firmware(18.)
Expand Down Expand Up @@ -381,6 +387,9 @@ def write_config_variables(self, config_vars):
:type config_vars: dictionary
"""

warnings.warn("This method has not yet been implemented.")

return

@requires_firmware(18.)
Expand All @@ -394,6 +403,9 @@ def write_config_variables2(self, config_vars):
:type config_vars: dictionary
"""

warnings.warn("This method has not yet been implemented.")

return

def histogram(self):
Expand Down Expand Up @@ -500,14 +512,6 @@ def histogram(self):
data['Bin 11'] + data['Bin 12'] + data['Bin 13'] + data['Bin 14'] + \
data['Bin 15']

# If debug is True, print out the bytes!
if self.debug:
count = 0
print ("Histogram Data")
for each in resp:
print ("\t{0}: {1}".format(count, each))
count += 1

# Check that checksum and the least significant bits of the sum of histogram bins
# are equivilant
if (histogram_sum & 0x0000FFFF) != data['Checksum']:
Expand Down Expand Up @@ -989,18 +993,4 @@ def read_histogram(self):
data['Bin 11'] + data['Bin 12'] + data['Bin 13'] + data['Bin 14'] + \
data['Bin 15']

# If debug is True, print out the bytes!
if self.debug:
count = 0
print ("Debugging the Histogram")
for each in resp:
print ("\t{0}: {1}".format(count, each))
count += 1

# Check that checksum and the least significant bits of the sum of histogram bins
# are equivilant (Doesn't work right now for some reason -> checksum always == 0!)
#if (histogram_sum & 0x0000FFFF) != data['Checksum']:
# warnings.warn("Data transfer was incomplete.")
# return None

return data
Loading

0 comments on commit 375e062

Please sign in to comment.