Skip to content

Commit

Permalink
Picoharp update: open/close buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
heeres committed Feb 12, 2013
1 parent 8453498 commit 173e245
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
22 changes: 14 additions & 8 deletions instrument_plugins/Picoharp.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ def __init__(self, name, devid, reset=False):

self.add_function('reset')
self.add_function('get_all')
self.add_function('open')
self.add_function('close')
self.add_function('start')
self.add_function('plot')

Expand All @@ -65,19 +67,23 @@ def __init__(self, name, devid, reset=False):
self.get_all()

def _create_dev(self):
try:
self._dev = picoquant_ph.PHDevice(self._devid)
except:
logging.error('Error loading Picoharp. In use? Check USB connection?')
self._dev = None
self._dev = picoquant_ph.PHDevice(self._devid)

def reset(self):
self.get_all()

def get_all(self):
self.get_resolution()
self.get_counts0()
self.get_counts1()
if self._dev.is_open():
self.get_resolution()
self.get_counts0()
self.get_counts1()

def close(self):
self._dev.close()

def open(self):
self._dev.open()
self._dev.initialize(picoquant_ph.MODE_HIST)

def do_get_resolution(self):
if self._dev:
Expand Down
16 changes: 14 additions & 2 deletions source/lib/dll_support/picoquant_ph.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import ctypes
import numpy as np
import logging

phlib = ctypes.windll.phlib

Expand Down Expand Up @@ -71,8 +72,13 @@ class PHDevice():

def __init__(self, devid, mode=MODE_HIST):
self._devid = devid
self.open()
self.initialize(mode)
self._is_open = False

try:
self.open()
self.initialize(mode)
except:
logging.error('Error loading Picoharp. In use? Check USB connection?')

def __del__(self):
self.close()
Expand All @@ -81,12 +87,18 @@ def open(self):
buf = ctypes.create_string_buffer(16)
ret = phlib.PH_OpenDevice(self._devid, buf)
self._serial = buf.value
if ret >= 0:
self._is_open = True
return ph_check(ret)

def close(self):
self._is_open = False
ret = phlib.PH_CloseDevice(self._devid)
return ph_check(ret)

def is_open(self):
return self._is_open

def initialize(self, mode):
'''
Initialize picoharp.
Expand Down

0 comments on commit 173e245

Please sign in to comment.