[Part 1] High-speed wavelength switching of multi-wavelength LED light source for microscopes using pySerial [Part 2] Controlling the camera with Python [For research]
I would like to share how to control automatic stages in Python. I didn't even look for an article on how to control Thorlabs Inc.'s automatic stages in Python. Therefore, I decided to write it myself, and wrote an article about the essence of know-how gained through trial and error. The automatic stage used this time is the stage of Thorlabs Inc. This stage can be incorporated into the company's microscope. The self-made microscope is expandable, giving you more freedom. By centralizing measurement and analysis, analog microscopic observations can be automated and multivariate data analysis can be seamlessly introduced.
-Small stepping motor ZFS25B (Thorlabs Inc.) -Stepping Motor Controller KST101 (Thorlabs Inc.)
-Controller Hub KCH301 (Thorlabs Inc.)
The following two are required to operate the Thorlabs automatic stage.
kinesis
Install kinesis from here.
Kinesis is a library that includes GUI-based software and DLL (Dynamic Link Library) files that operate in a local PC environment.
Select the version that suits your PC environment. A GUI-based application is included, but if you don't use it this time and Thorlabs.MotionControl.KCube.StepperMotor.dll
is saved in the following directory, there is no problem.
C:/Program Files/Thorlabs/Kinesis
This time it's Windows 10 x64, so select Kinesis 64-Bit Software for 64-Bit Windows
. Click Download.
Installing. ..
Done.
** MSL-Equipment module ** Install the module MSL-Equipment to control the Thorlabas automatic stage. This library is published free of charge by the New Zealand research institute Measurement Standards Laboratory of New Zealand.
First, copy and paste the following command and execute it.
Create a virtual environment thorlabs_demo with the conda command.
conda create -n thorlabs_demo python=3.6
Install MSL-Equipment with the following command.
pip install https://github.com/MSLNZ/msl-equipment/archive/master.zip
For example, try the following with Anaconda prompt. The installation is complete. You're ready.
Installation procedure (original) https://msl-equipment.readthedocs.io/en/latest/install.html
The sample program looks for kst101.py
in the following directory.
C: \ Users \ your username \ anaconda3 \ Lib \ site-packages \ msl \ examples \ equipment \ resources \ thorlabs
You can copy and paste the program below.
Now, let's take a look at the sample program.
It seems to work just by changing the part of serial = '26001809'
to the serial number of the device you are using.
kst101.py
"""
This example shows how to communicate with Thorlabs KST101, KCube Stepper Motor.
"""
# this "if" statement is used so that Sphinx does not execute this script when the docs are being built
if __name__ == '__main__':
import os
from pprint import pprint
from msl.equipment import EquipmentRecord, ConnectionRecord, Backend
from msl.equipment.resources.thorlabs import MotionControl
# ensure that the Kinesis folder is available on PATH
os.environ['PATH'] += os.pathsep + 'C:/Program Files/Thorlabs/Kinesis'
# rather than reading the EquipmentRecord from a database we can create it manually
record = EquipmentRecord(
manufacturer='Thorlabs',
model='KST101',
serial='26002319', # update the serial number for your KST101
connection=ConnectionRecord(
backend=Backend.MSL,
address='SDK::Thorlabs.MotionControl.KCube.StepperMotor.dll',
),
)
def wait():
motor.clear_message_queue()
while True:
status = motor.convert_message(*motor.wait_for_message())['id']
if status == 'Homed' or status == 'Moved':
break
position = motor.get_position()
real = motor.get_real_value_from_device_unit(position, 'DISTANCE')
print(' at position {} [device units] {:.3f} [real-world units]'.format(position, real))
# avoid the FT_DeviceNotFound error
MotionControl.build_device_list()
# connect to the KCube Stepper Motor
motor = record.connect()
print('Connected to {}'.format(motor))
# load the configuration settings (so that we can use the get_real_value_from_device_unit() method)
motor.load_settings()
# start polling at 200 ms
motor.start_polling(200)
# home the device
print('Homing...')
motor.home()
wait()
print('Homing done. At position {} [device units]'.format(motor.get_position()))
# move to position 100000
print('Moving to 100000...')
motor.move_to_position(100000)
wait()
print('Moving done. At position {} [device units]'.format(motor.get_position()))
# move by a relative amount of -5000
print('Moving by -5000...')
motor.move_relative(-5000)
wait()
print('Moving done. At position {} [device units]'.format(motor.get_position()))
# jog forwards
print('Jogging forwards by {} [device units]'.format(motor.get_jog_step_size()))
motor.move_jog('Forwards')
wait()
print('Jogging done. At position {} [device units]'.format(motor.get_position()))
# stop polling and close the connection
motor.stop_polling()
motor.disconnect()
# you can access the default settings for the motor to pass to the set_*() methods
print('\nThe default motor settings are:')
pprint(motor.settings)
There was an 8-digit serial number on the back of the kst101.
Change serial = '26001809'
in the above program to serial = '26002319'
.
Once you run the program and it works, you're done.
If you have any other questions, please feel free to contact us using the form below.
http://www.opto-line.co.jp/contact/