LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Using LabView to serial interface my microscope how I make a user interface to make the stage move by pressing buttons?

I have used LabView very little and am trying to write a program to control a microscope. I want to be able to give it commands such as to get the stage to move left, right, forward, back, and return to zero. I'm having trouble implementing the code into my block diagram. I've been reading LabView 8.6 tutorials for a couple of weeks and I'm still learning. What I know that  is that I need a event structure inside a while-loop for the user interface but I've been stuck.

 

Thanks for any help! If you need me to try and provide more information please say so.

0 Kudos
Message 1 of 19
(4,217 Views)

You've got two major problems right now.  Your serial port code is all outside of the while loop, so it will only execute once.  Also, you have a race condition with your VISA writes.  Will the command get written first to the serial port or the carriage return?

 

The rest of the code is just too incomplete and a mashup to even comment on.

 

If you know you need an event structure in a while loop, then why not post your best attempt at that, then we can comment on how to make that better.

0 Kudos
Message 2 of 19
(4,198 Views)

Alright so my serial port code should be inside a while loop unfortunately it doesn't work whenever I enter a command to move the stage. It sits there maybe I'm missing something.

So let me give you an overview to what happens in my code, so the configure serial port is very crucial. The VISA Write writes the bytes to the port. The first VISA Write takes the string to write command. I connected the second VISA write to make it easier whenever I enter a command, the \r will iniate the command as a whole. Example L\r will move the stage to Left once, ending up at VISA Read then closing. All of this found in separate case structures.

 

Now the user interface to control the the movement of the microscope is one of my issues, making several attempts to make it work yielded no results. My best work not the best but a attempt is attached, also one of the things with this I'm having trouble with is getting the button to talk to the stage. On previous buttons I worked on I could press the button and light up an LED on the front panel, I thought the same principle would relate to the movement of the stage, no such luck.

 

I hope I cleared up some misconceptions on my part, I appreciate your patience.

 

0 Kudos
Message 3 of 19
(4,184 Views)

In your Write case, you have two separate write funtions, one for the command and one for \r.  They both run in parallel.  Which one will run first?  Will it be cmd then \r, or will it be \r then cmd.  This is probably why it isn't working.  You don't need two write functions.  Use Concatenate String function to combine your command then \r into one string.  Use one write function.  This will send the proper sequence of cmd\r.

 

What is your bottom loop supposed to do?

 

- tbob

Inventor of the WORM Global
0 Kudos
Message 4 of 19
(4,173 Views)

None of that makes any sense. Your serial write/read will still only execute once, you did not create an event for the 'Left' button, and that conversion to an array, search array, to number code is just silly. The concantanate string in the top true case is also silly. What do you think that does?

 

Look again at the examples. You want an event for each button and inside each event, you want the indicator and the VISA Write of the command that corresponds to that movement.

0 Kudos
Message 5 of 19
(4,166 Views)

In the Write case I have them both running parallel you would enter the cmd and then \r would be attached to it. Alright I understand I fixed that it less clutter now.

The bottom loop I'm attempting to interface that so I can press a button such as left to move the stage left. Yet I have not yet figured out how to incorporate that into the program. I need some help on that part, I get the basics on it but I'm at a loss.

0 Kudos
Message 6 of 19
(4,164 Views)

Now you have NO event structure. Try to do what I suggested with the VISA Write inside an event. Do NOT place any code outside the event structure like you had before.

0 Kudos
Message 7 of 19
(4,155 Views)

You need an event structure.  Put a button on the front panel to allow the user to first enter a command, like L to move left, then the user would press the button (OK button) and the event would fire.  Put your serial write code inside the OK Button Value Change event.  So after entering a command, the user presses OK and the command is written.

 

I will create a small example for you.

- tbob

Inventor of the WORM Global
0 Kudos
Message 8 of 19
(4,151 Views)

Alright so now I need to improve it previous suggestion was to put the all the code into a while loop. Previously I was doing work, the stage was moving and the commands were being taken. The concantanate string has been fixed. Building off this LV example is what I've been working on, yielding good results but no luck on needing the stage to move by pressing a button is part of my problem.

 

Ok that advice is sound I'll take that and let you guys know. I appreciate the help.

0 Kudos
Message 9 of 19
(4,139 Views)

Look at the attached vi.  It uses an Event Structure.  Study it.  When the user presses the OK button, the OK Value Change event runs and the command is sent to the serial port, followed by a serial read.  Then the loop iterates again, and since no event is happening, the Timeout event runs.  No code here so nothing happens over and over again until the user presses a button.  The user can enter a new command then press OK.  Or the user can press the Stop button and the Stop Value Change event will run.  This will stop the loop.  After the loop stops, the VISA session is closed.  The shift registers for error and session handle are highly desired to transfer the data from each loop iteration to the next.

 

- tbob

Inventor of the WORM Global
0 Kudos
Message 10 of 19
(4,129 Views)