Skip to content

Commit

Permalink
Started work on ThorLabs PM100USB support. #11
Browse files Browse the repository at this point in the history
cgranade committed Mar 15, 2014
1 parent 0c97746 commit 4d38e88
Showing 1 changed file with 124 additions and 0 deletions.
124 changes: 124 additions & 0 deletions python/src/instruments/thorlabs/pm100usb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
##
# pm100usb.py: Driver class for the PM100USB power meter.
##
# © 2013 Steven Casagrande (scasagrande@galvant.ca).
#
# This file is a part of the InstrumentKit project.
# Licensed under the AGPL version 3.
##
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
##

## FEATURES ####################################################################

from __future__ import division

## IMPORTS #####################################################################

from instruments.generic_scpi import SCPIInstrument
from flufl.enum import IntEnum

import quantities as pq
from collections import namedtuple

## LOGGING #####################################################################

import logging
logger = logging.getLogger(__name__)
logger.addHandler(logging.NullHandler())

## CLASSES #####################################################################

class PM100USB(SCPIInstrument):

## ENUMS ##

class SensorFlags(IntEnum):
is_power_sensor = 1
is_energy_sensor = 2
response_settable = 16
wavelength_settable = 32
tau_settable = 64
has_temperature_sensor = 256

# We will cheat and also represent things by a named tuple over bools.
# TODO: make a flagtuple into a new type in util_fns, copying this out
# as a starting point.
_SensorFlags = namedtuple("SensorFlags", [
flag.name for flag in SensorFlags
])

## INNER CLASSES ##

def Sensor(object):
def __init__(self, parent):
self._parent = parent

# Pull details about the sensor from SYST:SENSOR:IDN?
sensor_idn = parent.sendcmd("SYST:SENSOR:IDN?")
(
self._name, self._serial_number, self._calibration_message,
self._sensor_type, self._sensor_subtype, self._flags
) = sensor_idn.split(",")

# Normalize things to enums as appropriate.
# We want flags to be a named tuple over bools.
self._flags = self._SensorFlags(**{
e.name: bool(e & self._flags)
for e in self.SensorFlags
})

@property
def name(self):
return self._name
@property
def serial_number(self):
return self._serial_number
@property
def calibration_message(self):
return self._calibration_message
@property
def type(self):
return (self._sensor_type, self._sensor_subtype)
@property
def flags(self):
return self._flags

## SENSING CONFIGURATION PROPERTIES ##

@property
def averaging_count(self):
"""
Integer specifying how many samples to collect and average over for
each measurement, with each sample taking approximately 3 ms.
"""
return int(self.query("SENS:AVER:COUN?"))
@averaging_count.setter
def averaging_count(self, newval):
if newval < 1:
raise ValueError("Must count at least one time.")
self.sendcmd("SENS:AVER:COUN {}".format(newval))


## METHODS ##

def read(self):
# TODO: wrap in something that will add units!
# Doing so will take access to an actual device, however, since
# the ThorLabs manual is pathetically incomplete on that point.
# Specifically, what does "CONF?" return?
return float(self.query('READ?'))

0 comments on commit 4d38e88

Please sign in to comment.