LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Basic serial write read

Solved!
Go to solution

Hi

I am controlling a stepper motor using the example Basic Serial Write and Read.vi through string commands to the VISA Write. The programmable drive allows me to insert a string where all paramenter of motion are encapsulated (distance, speed, acceleration, etc.). I can modify the string by breaking it down and then append its parts to input the complete string using controls, but after the motion I would like to send automatically a "current position string" command to the drive so the drive sends me back the motor position when it ends the motion. How can I write a structure such that a string can be sent to VISA Write automatically after execution of the first string? I have attached the block diagram. Thanks for any feedback.

0 Kudos
Message 1 of 7
(5,162 Views)

Hi fjimenez,

 

doing one thing first followed by a different thing second is quite easy…

 

1) The quick&dirty way is to copy your code and execute it one after the other.

2) The more reliable way is to use a loop to execute code more than once. Combine it with LabVIEWs "autoindexing" feature of loop tunnels and an array of commands you want to send…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 7
(5,154 Views)
Simple dataflow will allow you to add a write and a read immediately after the read that you currently have. You may have to do something on a loop to determine whether the move is complete before reading it's position, though. The example you are using is probably not the best for what you want. I would suggest a state machine. You really don't want to configure the serial port each time you want to do a new move.
0 Kudos
Message 3 of 7
(5,150 Views)

Hi GerdW, thanks for your prompt reply. Could you recommend me a particular loop to accomplish this? I was thinking of a for loop, but couldn't manage to do it.

Thanks,

Francisco

0 Kudos
Message 4 of 7
(5,147 Views)

Thanks for your reply, I will have to read about it as I am a new labview user and don't know what a state machine is and didn't know there could be a problem wih configuring the port each time I send a string. Thanks, Francisco.

0 Kudos
Message 5 of 7
(5,141 Views)
Solution
Accepted by topic author fjimenez

Hi Francisco,

 

as you state you're new to LabVIEW and judging from your questions I recommend to take all those free resources offered by NI for LabVIEW beginners!

There are (lots of free) online courses!

 

Using "loops" isn't LabVIEW specific, they are the same in every programming language.

And "state machines" aren't LabVIEW specific too, you also find them implemented in nearly all programming languages. But LabVIEW comes with a ready-to-use example state machine…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 7
(5,130 Views)
Solution
Accepted by topic author fjimenez

The Simple State Machine template that ships with LabVIEW is really the best way for new developers to get familiar with LabVIEW while utilizing a semi-scalable architecture.

Here's a broad example of how a state machine works:

  • States: Init, Idle, Exit, DoThing1, DoThing2, DoThing3
  • Each state contains code that might take some time. Ideally, not too long because that's how long your code could be unresponsive.
  • The Idle state contains an event structure for all user interaction.
  • The front panel has a button that says "Do Thing 1".
  1. Loop Iteration 0: Application begins, first state is Init. The Init state does some initialization stuff and tells the application to go to the Idle state when finished.
  2. Loop Iteration 1: Application goes to Idle state. It sits there, waiting at the event structure.
  3. Time goes by, then user presses button "Do Thing 1". There is no code, or minimal code, within this event case. The output of this event state tells the application to go to the DoThing1 state.
  4. Loop Iteration 3: Application goes to DoThing1 state. There is code here that does some stuff. The output of DoThing1 state tells the application to go back to the Idle state.
  5. Loop Iteration 4: Application goes to Idle state where it waits at the event structure again.
  • Each of the states can tell the application to go to any state they want. Want to reinitialize? Go to the Init state again. Want to end the program? Go to the Exit state. Want each state to trigger another (like a sequence)? Have DoThing1 output DoThing2, which outputs DoThing3,  which outputs Idle.

 

 

"Give me six hours to chop down a tree and I will spend the first four sharpening the axe."  - Abraham Lincoln

The free tutorials for beginners that others have mentioned can be found in the Unofficial Rules and Guidelines link in my signature.

 

Thanks are best given in the form of Kudos and Marked Solutions. You received assistance from some top-tier LabVIEW experts here (Dennis and GerdW = top of the top), whom I'm sure would appreciate your gratitude. Marked Solutions help others find this post when they have the same issue and Kudos motivate us all to keep coming back to help! Smiley Wink

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 7 of 7
(5,122 Views)