Thorlabs / Motion_Control_Examples

Software examples for Thorlabs motion control products (e.g. T-Cube, K-Cube, and benchtop brushless, DC, stepper, and Piezo motor controllers)
MIT License
71 stars 28 forks source link

kpz101_pythonnet #24

Closed BDImagingLab closed 8 months ago

BDImagingLab commented 1 year ago

When using this code to control the KPZ101, it shows up an error message: image Meanwhile, I can connect and control the stage with Kinesis software. When running python, it is disconnected in Kinesis. image

BDImagingLab commented 1 year ago

This is python code that I use.

import os import time import sys import clr

clr.AddReference("C:\Program Files\Thorlabs\Kinesis\Thorlabs.MotionControl.DeviceManagerCLI.dll") clr.AddReference("C:\Program Files\Thorlabs\Kinesis\Thorlabs.MotionControl.GenericMotorCLI.dll") clr.AddReference("C:\Program Files\Thorlabs\Kinesis\ThorLabs.MotionControl.KCube.PiezoCLI.dll") from Thorlabs.MotionControl.DeviceManagerCLI import from Thorlabs.MotionControl.GenericMotorCLI import from Thorlabs.MotionControl.KCube.PiezoCLI import * from System import Decimal # necessary for real world units

DeviceManagerCLI.BuildDeviceList()

create new device

serial_no = "29501195" # Replace this line with your device's serial number

Connect, begin polling, and enable

device = KCubePiezo.CreateKCubePiezo(serial_no)

Get Device Information and display description

device_info = device.GetDeviceInfo() print(device_info.Description)

iago-rst commented 1 year ago

Hi!

Are you simulating the device or is it a physical one? At least to me, InitializeSimulations() only works when the Kinesis GUI is closed. Apparently the Kinesis server can only take up to one "pipe", so either Python is connected or the GUI is connected. You can see these log messages on the Kinesis Simlulator app.

[FIXED] Now, I am also running into an issue when calling TLI_GetHardwareInfo, which is similar to .NET GetDeviceInfo(). Whenever I run this function, my kernel crashes xD

Solution: I has some mistake on the pointer arguments. The crashing probably came from an invalid memory access.

Hope this gives you some more clue as to what might be wrong!

TrumanMetz commented 8 months ago

Hi, Our apologies for the late response, but if you are still having issues with this error please reach out to our support team at techsupport@thorlabs.com to speak with one of our engineers directly.