Skip to content

Commit

Permalink
add python package, add gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
lrlunin committed Jul 27, 2023
1 parent f7cab14 commit 8f6e1bf
Show file tree
Hide file tree
Showing 7 changed files with 181 additions and 111 deletions.
19 changes: 19 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
__pycache__/
.DS_Store
.vscode
site/

# Distribution / packaging
bin/
build/
develop-eggs/
dist/
eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
1 change: 0 additions & 1 deletion ThorlabsPM100

This file was deleted.

110 changes: 0 additions & 110 deletions ThorlabsPM100Tango.py

This file was deleted.

24 changes: 24 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from setuptools import setup, find_packages

setup(
name="tangods_thorlabspm100",
version="0.0.1",
description="Tango Device for ThorlabsPM100",
author="Daniel Schick",
author_email="dschick@mbi-berlin.de",
python_requires=">=3.6",
entry_points={"console_scripts": ["ThorlabsPM100 = tangods_thorlabspm100:main"]},
license="MIT",
packages=["tangods_thorlabspm100"],
install_requires=[
"pytango",
"ThorlabsPM100",
],
url="https://github.com/MBI-Div-b/pytango-ThorlabsPM100",
keywords=[
"tango device",
"tango",
"pytango",
"thorlabsPM100"
],
)
126 changes: 126 additions & 0 deletions tangods_thorlabspm100/ThorlabsPM100Tango.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#!/usr/bin/python3 -u

from ThorlabsPM100 import ThorlabsPM100 as tlpm100
from ThorlabsPM100 import USBTMC

from tango import AttrQuality, AttrWriteType, DispLevel, DevState, DebugIt
from tango.server import Device, attribute, command, pipe, device_property


class ThorlabsPM100(Device):
Port = device_property(
dtype="str",
default_value="/dev/ttyTLPM100",
)

sn = attribute(
label="SN", dtype="str", access=AttrWriteType.READ, doc="Sensor serial number"
)

model = attribute(
label="Model", dtype="str", access=AttrWriteType.READ, doc="Sensor model"
)

wavelength = attribute(
label="Wavelength",
dtype="float",
display_level=DispLevel.OPERATOR,
access=AttrWriteType.READ_WRITE,
doc="Correction wavelength",
)

power = attribute(
label="Power",
dtype="float",
format="%8.3f",
display_level=DispLevel.OPERATOR,
access=AttrWriteType.READ,
doc="Measured power",
)

conversion = attribute(
label="Conversion factor",
dtype="float",
format="%6.3e",
display_level=DispLevel.OPERATOR,
access=AttrWriteType.READ_WRITE,
doc="Conversion factor",
memorized=True,
hw_memorized=True,
)

auto_range = attribute(
label="Auto range",
dtype="bool",
display_level=DispLevel.OPERATOR,
access=AttrWriteType.READ_WRITE,
)

upper_range = attribute(
label="Range",
dtype="float",
format="%6.3e",
display_level=DispLevel.OPERATOR,
access=AttrWriteType.READ_WRITE,
)

def init_device(self):
Device.init_device(self)
self.set_state(DevState.INIT)

try:
self.info_stream("Connecting on Port: {:s}".format(self.Port))
self.inst = USBTMC(device=self.Port)
self.power_meter = tlpm100(inst=self.inst)
self.set_state(DevState.ON)
idn = self.power_meter.system.sensor.idn.split(",")
self.__model = idn[0]
self.__sn = idn[1]
self.info_stream(
"Connected to {:s} with SN: {:s}".format(self.__model, self.__sn)
)
except:
self.info_stream("Not able to connect on Port: {:s}".format(self.Port))
self.set_state(DevState.OFF)

self.__conversion_factor = 1.0

def read_sn(self):
return self.__sn

def read_model(self):
return self.__model

def read_wavelength(self):
return self.power_meter.sense.correction.wavelength

def write_wavelength(self, value):
self.wavelength = value
self.power_meter.sense.correction.wavelength = value

def read_auto_range(self):
return bool(self.power_meter.sense.power.dc.range.auto)

def write_auto_range(self, value):
self.power_meter.sense.power.dc.range.auto = int(value)

def read_upper_range(self):
return float(self.power_meter.sense.power.dc.range.upper)

def write_upper_range(self, value):
self.power_meter.sense.power.dc.range.upper = value

def read_conversion(self):
return self.__conversion_factor

def write_conversion(self, value):
self.__conversion_factor = value

def read_power(self):
self.debug_stream("read power")
power = self.power_meter.read
return float(power * self.__conversion_factor)


if __name__ == "__main__":
ThorlabsPM100.run_server()
9 changes: 9 additions & 0 deletions tangods_thorlabspm100/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from .ThorlabsPM100Tango import ThorlabsPM100


def main():
import sys
import tango.server

args = ["ThorlabsPM100"] + sys.argv[1:]
tango.server.run((ThorlabsPM100,), args=args)
3 changes: 3 additions & 0 deletions tangods_thorlabspm100/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import main

main()

0 comments on commit 8f6e1bf

Please sign in to comment.