LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Translate data to ASCII using a communication protocol

Solved!
Go to solution

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

Agrypnia_0-1701865507081.png

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)

 

 

Download All
0 Kudos
Message 1 of 6
(417 Views)

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?

 

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 6
(412 Views)

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?

 

0 Kudos
Message 3 of 6
(407 Views)
Solution
Accepted by topic author Agrypnia

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!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 4 of 6
(402 Views)
Solution
Accepted by topic author Agrypnia

Most serial communication issues can be solved by watching this video: VIWeek 2020/Proper way to communicate over serial

========================
=== Engineer Ambiguously ===
========================
Message 5 of 6
(356 Views)

Thank you very much for your guidance. It is greatly appreciated.

 

Best regards,

Agrypnia

0 Kudos
Message 6 of 6
(332 Views)