LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Visa in state machine

Solved!
Go to solution

Hi!, I'm new in Labview and I'm struggling to find out he right approach for my problem.
My program has to control a motor by sending commands through VISA to a microcontroller (start, stop, set speed, go forward, go backward, go to start position string commands). It also has to receive data of a sensor from the same microcontroller. I decided to create my program with a state machine approach. I attach a simplified version of my states diagram. It has some explanations between brackets about the commands that I have to send when passing between states.
The running and gathering data is the hardest and I think if know how to implement it, I can easily implement the others. In this state I have to receive data from the microcontroller periodically, and the period should be defined by the user and goes from 15s to 1min. Besides it has to change to pause state when:
- The user clicks a pause button
- The output of a timer SubVI changes to true
- The data receivced is grater than a certain value
- The end postion string is received from VISA
I'm also programming the microcontroller, so I can send data in the way that I believe that is more convenient, that is I could send data from the micro every 15s-1min or just send data when the micro receives a string that labview is requesting data.
So, after all this explanation my question is how could I implement the communication in the running and gathering data state? I mean the code implementation in labview and if the micro sould send data periodically without receiving a request from labiew or only send data when it receives this request from labview.
I can upload the code I've done so far, but I don't think it would be useful as it is missing all the VISA communication code.
Sorry for such a long explanation.
Sorry for my English, it's not my main language and I might have made some mistakes
Thank you for your time

0 Kudos
Message 1 of 5
(3,606 Views)

Assuming you do not need a sample at an exact rate, then have the microprocessor only send the data as a reply.  It will be a lot easier on both sides this way.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 5
(3,587 Views)

Hard to reply without seeing your code by here it goes...

 

You should have VIPM, if not, download it from JKI.net.

 

Use VIPM to install the JKI State Machine this architecture should work well for what you propose.

 

It has an event structure built in, so you can see when the user clicks pause. You could set up a time case of 1 s (or any value you choose), and count how many timeouts occur so you can then go to your receive data state, or when to go to a send data state, etc. Can't suggest too much more without seeing what you have.

 

Good luck

mcduff

0 Kudos
Message 3 of 5
(3,582 Views)
Solution
Accepted by topic author javier555

For getting data periodically you have a couple options. Your "running and collecting data" state can be broken up into two states, "check time" and "collect data". Or it could all be a single state and your data collection code is in a case structure, that is only true when the time has elapsed.

 

If you are already using an event structure to handle button presses, you could set the timeout to the data interval (in milliseconds). At the start of the program set it to -1, then when the user starts data collection set it to 15000 for example. Then when timeout occurs go to the data collection state. Note that you can only use this method if you don't expect the user to press any buttons (besides pause / stop) while the data collection is happening. Every time any event is triggered, it restarts the timeout counter for the event structure.

0 Kudos
Message 4 of 5
(3,581 Views)

Thank you, I didn't realize that by dividing running and collecting state in two states everything is simpler. Now I think I know how to solve it. 

0 Kudos
Message 5 of 5
(3,541 Views)