12-06-2023 06:30 AM
Hello everyone,
My laboratory is equipped with three motorized stages (Thorlabs MTS50-Z8) that are used for precise positioning. However, we encountered an issue where the stages would not move smoothly between specific points without stopping. After extensive communication with Thorlabs, we discovered that the only way to achieve seamless movement is by using a communication protocol. I successfully connected the motor and issued commands, but I encountered a problem when trying to read the data in ASCII format to receive feedback. Although I can extract the feedback using Python code, I am unable to translate this code into LabVIEW.
I have attached the Python code in a text file and the LabVIEW code. I would greatly appreciate any advice or comments on the situation.
Thank you so much for help and your time.
LabVIEW Code
Python Code
while True:
# Get Position; MGMSG_MOT_REQ_USTATUSUPDATE
Status = "9004"
KDC101.write(unhexlify(Status + Channel + "00" + Destination + Source))
Rx = KDC101.read(20)
print(Rx)
Position = Rx[8:12]
print(Rx[8:12])
PositionDU = int.from_bytes(Position, "little")
print(PositionDU)
print(PositionDU/34304)
Solved! Go to Solution.
12-06-2023 06:35 AM - edited 12-06-2023 06:37 AM
Hi Agrypnia,
@Agrypnia wrote:
Python Code
Rx = KDC101.read(20)
In Python you read 20 bytes, but in LabVIEW you use BytesAtPort.
Why do you use different code in LabVIEW?
Why do you need to convert a string to an U8 array and back to a string?
Why has the local variable at the stop condition no label?
How do you configure the serial port?
12-06-2023 06:40 AM
Since I am new to LabVIEW, I have been referring to other code while writing my own. I have read about bytes and bits, but I still find it a bit confusing. Do you have any suggestion?
12-06-2023 06:47 AM
Hi Agrypnia,
@Agrypnia wrote:
I have read about bytes and bits, but I still find it a bit confusing. Do you have any suggestion?
Read 20 bytes instead of using BytesAtPort.
When handling serial communication with LabVIEW you should ALWAYS refer to this explanation!
12-06-2023 09:14 AM
Most serial communication issues can be solved by watching this video: VIWeek 2020/Proper way to communicate over serial
12-06-2023 09:40 AM - edited 12-06-2023 09:42 AM
Thank you very much for your guidance. It is greatly appreciated.
Best regards,
Agrypnia