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

Can't set the temperature on TC200 Thorlabs #331

Closed
njrebelo opened this issue Feb 18, 2022 · 16 comments
Closed

Can't set the temperature on TC200 Thorlabs #331

njrebelo opened this issue Feb 18, 2022 · 16 comments

Comments

@njrebelo
Copy link

image

I have written this code:

import instruments as ik

com='COM7'
baud_rate = 115200

temperature_sensor=ik.thorlabs.TC200.open_serial(com,baud_rate)
print(temperature_sensor.temperature)

temperature_sensor.temperature_set(35)

and no matter what I do the erros is always the same:
Traceback (most recent call last):
File "C:\Users\mc2\Desktop\TC200_automation.py", line 9, in
temperature_sensor.temperature_set(35)
File "C:\Users\mc2\AppData\Local\Programs\Python\Python36\lib\site-packages\instruments\thorlabs\tc200.py", line 198, in temperature_set
return float(response) * pq.degC
ValueError: could not convert string to float: ' 30.0elsius'

What can I do?

@scasagrande
Copy link
Contributor

temperature_set is a property, not a function to be called

try temperature_sensor.temperature_set = 35

@trappitsch
Copy link
Contributor

Looks to me like your device is sending back the string 30 Celsius when you run print(temperature_sensor.temperature).
With your code initialized as above in the image, up to line 6, could you run the following lines individually and post the output (error or not):

print(temperature_sensor.query("tset?"))
print(temperature_sensor.query("tact?"))

Also: what version of instrumentkit do you have installed?

@trappitsch
Copy link
Contributor

temperature_set is a property, not a function to be called

try temperature_sensor.temperature_set = 35

That's definitely an issue as well!

@scasagrande Looks like the error shows up at the print statement though... ik has the following for the temperature read:

response = (
            self.query("tset?").replace(" C", "").replace(" F", "").replace(" K", "")
        )

The fact it complains about 30.0elsius looks like the " C" is properly stripped, but the device seems to return the full string.

@scasagrande
Copy link
Contributor

@trappitsch the print statement worked, you can see it just above the traceback in the screenshot 21.9 degC

We're trying to set a property, but we're calling the getter function, which is why this then gets called, https://github.com/Galvant/InstrumentKit/blob/v0.6.0/instruments/thorlabs/tc200.py#L186, which looks like has an error that @trappitsch you did correctly identify. I wonder if there is a device setting that is changing the data format coming back from the instrument

@scasagrande
Copy link
Contributor

scasagrande commented Feb 18, 2022

Or maybe its just that tact returns with the short form of the units (because that did succeed), while tset? returns the long form?

@scasagrande
Copy link
Contributor

Also this is likely 0.6 based on pq.degC instead of u.degC

@trappitsch
Copy link
Contributor

@scasagrande Good point, I missed that return in the output. Also about the version. So maybe @njrebelo could still run the two queries I posted and try to set the temperature as @scasagrande pointed out above.

If it really sends back mixed messages (" C" for some and " Celsius"), it wouldn't be too hard a fix to implement.

@scasagrande
Copy link
Contributor

@trappitsch agreed

if I get a moment this weekend I'll take a look in the manual and see what it says

@scasagrande
Copy link
Contributor

So in typical Thorlabs fashion the manual is very unhelpful. It doesn't give example return values for the queries.

@trappitsch
Copy link
Contributor

trappitsch commented Feb 19, 2022

That sounds about right... Hopefully @njrebelo can send some typical output for tset and tact

@njrebelo
Copy link
Author

Thank you so much for all the help, you guys were super helpful.
I its running now as I want it to.

image

@scasagrande
Copy link
Contributor

@njrebelo could you still try this for us? print(temperature_sensor.query("tset?"))

@njrebelo
Copy link
Author

image
Sorry wasn´t in the lab much this week

@scasagrande
Copy link
Contributor

np @njrebelo , thank you for getting us that data!

@trappitsch
Copy link
Contributor

Hmm, this is interesting and weird. It really looks like tact? sends back C for the unit and tset? Celsius. I guess we can add a replace routine that acts on Celsius before acting on C, just to be on the safe side in case this is a settings thing...

trappitsch added a commit to trappitsch/InstrumentKit that referenced this issue Mar 1, 2022
See issue instrumentkit#331, it seems like `tset?` returns ` Celsius` as the unit.
scasagrande pushed a commit that referenced this issue Mar 3, 2022
See issue #331, it seems like `tset?` returns ` Celsius` as the unit.
@scasagrande
Copy link
Contributor

Fixed in #333

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

3 participants