qpit / thorlabs_apt

python module for Thorlabs' APT library
GNU General Public License v2.0
80 stars 47 forks source link

Nanotrack #1

Closed mabl closed 8 years ago

mabl commented 8 years ago

Hi,

I'd like to add support for the Nanotrack controllers. However, I have not found any documentation of the ATP.dll. Is this available somewhere?

Very best, Matthias

mabl commented 8 years ago

Ok, it looks like this is futile since it is not exported by apt.dll...

tobiasgehring commented 8 years ago

OK. APT.DLL seems to be quite limited and not documented at all. So you either have to use the ActiveX controls :( or better, the underlying ftdi protocol. For the latter there is a python library: https://github.com/freespace/pyAPT Haven't tried it myself though.

On 02/11/2016 05:55 PM, Matthias Blaicher wrote:

Ok, it looks like this is futile since it is not exported by apt.dll...

— Reply to this email directly or view it on GitHub https://github.com/qpit/thorlabs_apt/issues/1#issuecomment-182957099.

mabl commented 8 years ago

I got it working with python .net:

import clr
import sys

sys.path.append(r'C:\Program Files\Thorlabs\Kinesis')

clr.AddReference("Thorlabs.MotionControl.DeviceManagerCLI")
clr.AddReference("Thorlabs.MotionControl.GenericNanoTrakCLI")
clr.AddReference("Thorlabs.MotionControl.TCube.NanoTrakCLI")

from Thorlabs.MotionControl.DeviceManagerCLI import DeviceManagerCLI
from Thorlabs.MotionControl.GenericNanoTrakCLI import NanoTrakStatus, TIAReading, TIARangeParameters
from Thorlabs.MotionControl.TCube.NanoTrakCLI import TCubeNanoTrak

class NanoTrak:
    def __init__(self, device_id):
        DeviceManagerCLI.BuildDeviceList()
        if not DeviceManagerCLI.GetDeviceList().Contains(device_id):
            raise RuntimeError('Unknown device id')

        device = TCubeNanoTrak.CreateTCubeNanoTrak(device_id)
        device.Connect(device_id)
        if not device.IsSettingsInitialized():
            device.WaitForSettingsInitialized(5000)

        device.StartPolling(250)

        #device.SetTIARangeMode(TIARangeParameters.TIARangeModes.AutoRangeAtSelected, TIARangeParameters.OddOrEven.All);

        #nanotrak_settings = device.GetNanoTrakConfiguration(device_id)
        self._device = device

    def close(self):
        if self._device:
            self._device.StopPolling()
            self._device.Disconnect()
            self._device = None

    def __del__(self):
        self.close()

    @property
    def tracking(self):
        return self._device.GetMode() != NanoTrakStatus.OperatingModes.Latch

    @tracking.setter
    def tracking(self, enabled):
        if enabled:
            self._device.SetMode(NanoTrakStatus.OperatingModes.Tracking)
        else:
            self._device.SetMode(NanoTrakStatus.OperatingModes.Latch)

    @property
    def power(self):
        tia_reading = self._device.GetReading()
        # if tia_reading.UnderOrOverRead != TIAReading.UnderOrOver.Within:
        #     raise ValueError('TIA out of range!')
        return tia_reading.AbsoluteReading

    @property
    def cycle_position(self):
        pos = self._device.GetCirclePosition()
        return pos.HPosition, pos.VPosition