08-21-2023 05:52 PM
Hello LabView Community,
I just started using LabView in university and am now tasked with building a rotation stage controller, which will later be mounted with a neutral density wheel.
I got it working pretty well and can move the stage around how I want to, the only problem is, that I can not get it to display its current position in LabView. If I use a "VISA Write" prompt and give the stage the command "0gp" it should give me its current position in hexadecimal, but the return count in the "VISA Write" is only an integer, so I don't know how to continue.
I attached the VI, so you can take a look at it and maybe even give me general feedback, as I am new to LabView.
Cheers,
Karl
Solved! Go to Solution.
08-21-2023 08:56 PM
Welcome to the LabVIEW Forums, Leo.
A nice thing about LabVIEW is it really is an Engineering Workbench (the last two letters of "LabVIEW"). What is probably going on is a VISA communication issue. I can't look at your code because I'm a long-term LabVIEW User, and our "team" are all using LabVIEW 2019, and so I cannot open your VI and look at your code. [You can fix this by using the "Save for Previous Version" option and specifying LabVIEW 2019, which should be readable by LabVIEW 2019, 2020, 2021, 2022, and 2023].
Here's how you can "explore the options":
The first thing you want to do is to set up the Serial Port parameters for your VISA connection, These are such things as the Baud Rate (the speed at which the digital pulses conveying the information go up and down, or the speed of data transmission), the Parity, # Bits, and # Stop Bits (often N, 8, 1, No parity, 8 bits, 1 stop bit). VISA has something called a Termination Character, which you want to set, and make 0x0A = 10.
Now you want to try sending a command to your device, and seeing if you can read a response. Look in the manual -- there is probably an "Initialization" command, which often gets a response back. This may be on another tab in the Tester. Once you send the command, you need to read the response. How much should you read? Well, you don't know, because you (probably) can't predict the future and know how many characters the response should be! But VISA knows, and will send you a "Bytes at Port" (how many bytes is it ready to send to you). You should not use Bytes at Port, especially if you turned on the Termination Character (see end of previous paragraph). Tell VISA to read 1000 bytes. It will probably send back 5-20 bytes, the last one being a "Line Feed" (0x0A, 10 decimal), which makes VISA stop reading and return the just-read bytes to you.
Once you get this to work, you can try more complex commands.
Now, when you write your code, you go through the same steps. You do a VISA Configure Serial Port (most of the inputs to this are probably correct, except possibly the Baud Rate, whose default of 9600 is probably much too low). Follow this with a VISA Write, then a VISA Read, with a byte count of 1000, and look at the (much shorter) string that is returned.
Give it a try, let us know if/how it worked. And (re-)attach your code saved for a "previous version", please.
Bob Schor
08-22-2023 09:59 AM
Hello Bob,
thanks for the reply. I am already able to move to motor and send it the commands I want, I also know which commands to send and what I would receive, because I used software by ThorLabs, where I get those informations.
Problem is, that I know I would receive a hexadecimal (so a string) output, and all the VISA terminals I found so far, only either allow me to send in a string and receive an integer, or vice versa, but I would need something to receive and output a string.
When I tried using "VISA Write" it would just give me a random integer, which sadly was of no help.
I converted the VI to the 2019 version though, so maybe that can clear things up.
Cheers,
Karl
08-22-2023 10:25 AM
PS: Still can not quite to get it to work, but could I just have a "VISA Read" after a "VISA Write" to make it work?
08-22-2023 12:43 PM
@LeoTrotzki wrote:
PS: Still can not quite to get it to work, but could I just have a "VISA Read" after a "VISA Write" to make it work?
It depends. When you do a VISA Write, you are often "sending a command". Look in the manual for your Controller -- when you send that command (like "Where Am I?"), does it send an answer (like "X = 20 cm")? If so, it has responded by sending you something to read, so in this case, yes, it is waiting for you to issue a VISA Read. [If you read my previous long response, you'll know to ask for a "big read", like 1000 characters ...].
Bob Schor
08-22-2023 03:07 PM
Thanks a lot for the help!
I can now get readings that are the same as the software provided by ThorLabs, I have to use some workarounds though. LabVIEW always skips the first 2 steps and also every other step, probably because I have my while loop weird. I just add the degrees per step times 2 to the current position and multiply my reading by 2 afterwards. I guess it could become a problem later, but for now this works.
If you have any idea for a smarter workaround, I would greatly appreciate!
Cheers,
Karl
08-22-2023 04:38 PM
For anyone wondering how I got it working now, when you have the same problem:
I opened a new "VISA Serial" and made a separate while loop for it, because the other loop was bound to a timer, since I wanted the motor to move in certain time steps.
In the new while loop I put in a "VISA Write" followed by a "VISA Read" and gave it the correct command being "0gp". In the software provided by ThorLabs I could figure out how many bytes I would need in general and how many I would have to cut off.
So now I am getting a correct reading without any kind of workaround.
Cheers,
Karl
08-22-2023 05:53 PM
Your attached "Wheel Controller.vi" (thanks!) is written with LabVIEW 2023. I routinely use LabVIEW 2019, so I cannot open your VI and make more specific suggestions because I'm only "guessing" at your code.
Could you open your own VI, then do a "Save for Previous Version" (on the File menu) and specify LabVIEW 2019? [Perhaps call it "Wheel Controller 2019.vi"]. I'm sure you'll hear from me, and from other long-time LabVIEW users (we generally do not install a new version of LabVIEW every year because of the compatibility issues with older LabVIEW installation).
Bob Schor
08-23-2023 12:14 PM
I did that for that file, don't know why that is not working.
I did the same process again and this is the file, maybe it works now?
08-24-2023 09:25 AM
Oops, my bad -- I must have opened the original 2023 version by mistake.
To make up for your extra effort (and my carelessness), here are some suggestions for "improving your code" and "getting better at LabVIEW".
Bob Schor