Skip to content

Commit

Permalink
Merge pull request #301 from south-coast-science/develop
Browse files Browse the repository at this point in the history
pulling changes
  • Loading branch information
jadempage committed Oct 5, 2020
2 parents 62f71e4 + 8a2551b commit 158fb6e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/scs_dfe/particulate/opc.py
Expand Up @@ -77,11 +77,13 @@ def __init__(self, interface):

def power_on(self):
self.__interface.power_opc(True)
self.__interface.power_ndir(True) # TODO: OPCube work-around - remove!
time.sleep(self.boot_time())


def power_off(self):
self.__interface.power_opc(False)
self.__interface.power_ndir(False) # TODO: OPCube work-around - remove!


# ----------------------------------------------------------------------------------------------------------------
Expand Down
26 changes: 21 additions & 5 deletions src/scs_dfe/particulate/opc_n2/opc_n2.py
Expand Up @@ -40,8 +40,8 @@ class OPCN2(AlphasenseOPC):
__FAN_DOWN_TIME = 2

__CMD_POWER = 0x03
__CMD_POWER_ON = 0x00 # 0x03, 0x00
__CMD_POWER_OFF = 0x01 # 0x03, 0x01
__CMD_POWER_ON = 0x00
__CMD_POWER_OFF = 0x01

__CMD_CHECK_STATUS = 0xcf
__CMD_READ_HISTOGRAM = 0x30
Expand All @@ -50,7 +50,7 @@ class OPCN2(AlphasenseOPC):
__CMD_CHECK = 0xcf

__RESPONSE_BUSY = 0x31
__RESPONSE_READY = 0xf3
__RESPONSE_NOT_BUSY = (0x00, 0xff, 0xf3)

__SPI_CLOCK = 326000 # Minimum speed for OPCube
__SPI_MODE = 1
Expand Down Expand Up @@ -202,8 +202,24 @@ def __wait_while_busy(self, specified_timeout=None):


def __cmd_power(self, cmd):
self._spi.xfer([self.__CMD_POWER, cmd])
time.sleep(self.__DELAY_CMD)
try:
self._spi.open()

while True:
response = self._spi.xfer([self.__CMD_POWER])
time.sleep(self.__DELAY_CMD)

# print(["0x%02x" % char for char in response], file=sys.stderr)
# sys.stderr.flush()

if response[0] in self.__RESPONSE_NOT_BUSY:
break

self._spi.xfer([cmd])
time.sleep(self.__DELAY_TRANSFER)

finally:
self._spi.close()


def __cmd(self, cmd):
Expand Down
4 changes: 2 additions & 2 deletions src/scs_dfe/particulate/opc_n3/opc_n3.py
Expand Up @@ -65,7 +65,7 @@ class OPCN3(AlphasenseOPC):
__CMD_RESET = 0x06

__RESPONSE_BUSY = 0x31
__RESPONSE_READY = (0x00, 0xff, 0xf3)
__RESPONSE_NOT_BUSY = (0x00, 0xff, 0xf3)

__SPI_CLOCK = 326000 # Minimum speed for OPCube
__SPI_MODE = 1
Expand Down Expand Up @@ -353,7 +353,7 @@ def __cmd_power(self, cmd):
# print(["0x%02x" % char for char in response], file=sys.stderr)
# sys.stderr.flush()

if response[0] in self.__RESPONSE_READY:
if response[0] in self.__RESPONSE_NOT_BUSY:
break

self._spi.xfer([cmd])
Expand Down
2 changes: 1 addition & 1 deletion src/scs_dfe/particulate/opc_r1/opc_r1.py
Expand Up @@ -60,7 +60,7 @@ class OPCR1(AlphasenseOPC):
__CMD_RESET = 0x06

__RESPONSE_BUSY = 0x31
__RESPONSE_READY = (0x00, 0xff, 0xf3)
__RESPONSE_NOT_BUSY = (0x00, 0xff, 0xf3)

__SPI_CLOCK = 326000 # Minimum speed for OPCube
__SPI_MODE = 1
Expand Down

0 comments on commit 158fb6e

Please sign in to comment.