Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing measurements #13

Closed
Henttinen opened this issue Oct 17, 2023 · 1 comment
Closed

Missing measurements #13

Henttinen opened this issue Oct 17, 2023 · 1 comment
Assignees

Comments

@Henttinen
Copy link

Hi,
I am trying to use the PM100USB1 with a ES120C2 sensor, running on a Python script that is recording the data received from the sensor.

The problem is, that sometimes we don't get any data, from a 1Hz pulsing rate.

The code we are using for the measuring

import time
from datetime import datetime
from ctypes import cdll, c_long, c_ulong, c_uint16, c_uint32, c_float, byref, create_string_buffer, c_bool, c_char_p, c_int, c_int16, c_double, sizeof
from TLPMX import TLPMX
from TLPMX import TLPM_DEFAULT_CHANNEL
import os


class energy:
    def __init__(self, measureTime: int = 30) -> None:
        self.measureTime = measureTime
        self.tlpm = TLPMX()
        deviceCount = c_uint32(0)
        self.tlpm.findRsrc(byref(deviceCount))

        resourceName = create_string_buffer(1024)
        i: int = 0

        for i in range(0, deviceCount.value):
            self.tlpm.getRsrcName(c_int(i), resourceName)

        self.tlpm.open(resourceName, c_bool(True), c_bool(True))

        self.tlpm.setAttenuation(c_double(0), TLPM_DEFAULT_CHANNEL)
        self.tlpm.setWavelength(c_double(1574), TLPM_DEFAULT_CHANNEL)
        self.tlpm.setBeamDia(c_double(20), TLPM_DEFAULT_CHANNEL)
        self.tlpm.setPeakThreshold(c_double(0), TLPM_DEFAULT_CHANNEL)
        self.tlpm.setCurrentRange(c_double(1/1000), TLPM_DEFAULT_CHANNEL)
        self.tlpm.setEnergyRange(c_double(1/1000), TLPM_DEFAULT_CHANNEL)

        minEnergyRange = c_double()
        self.tlpm.getEnergyRange(
            1, byref(minEnergyRange), TLPM_DEFAULT_CHANNEL)
        print(f'Min energy range in J: {minEnergyRange.value}')

        self.measurementList = []
        start_time = time.perf_counter()
        while (time.perf_counter()-start_time) < self.measureTime:
            energy = c_double()
            self.tlpm.measEnergy((byref(energy)), TLPM_DEFAULT_CHANNEL)
            epoch = time.time()
            self.measurementList.append((epoch, energy.value))
        cwd: str = os.getcwd()

        fileFolder: str = f'{cwd}/enegytest/'
        os.makedirs(fileFolder, exist_ok=True)
        dtFormat: str = datetime.now().strftime('%Y-%m-%d-%H.%M.%S')
        fileName: str = f'{fileFolder}/{dtFormat}.csv'
        f = open(fileName, 'w+')
        f.write('index,epoch,energy_J\n')
        for i, (epoch, energy) in enumerate(self.measurementList, 1):
            f.write(f'{i},{epoch},{energy}\n')
        f.close()


if __name__ == '__main__':
    em = energy()

Footnotes

  1. https://www.thorlabs.com/newgrouppage9.cfm?objectgroup_id=4037&pn=PM100USB

  2. https://www.thorlabs.com/newgrouppage9.cfm?objectgroup_id=3337&pn=ES120C

@gboedecker
Copy link
Contributor

Make sure to select a suitable threshold and energy range. It is easier to test this in the Optical Power Meter GUI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants