LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

modifying user input in for loop

Hello,

 

I am making a program in order to control two velmex motors. As part of my program, I have two nested for loops. The inner for loop formats a user specified input in ascii commands and the outer loop tells the program how many times to run that specific inner loop pattern. 

 

I want to modify the program so that two motors work together in a "snake pattern". In other words, the first outer loop should take the original user input, but then the second time the outer loop runs the direction of one of the motors (all of the associated values with one motor are stored in an individual cluster and these clusters are sorted and placed into an array), should be reveresed by mulltiplying the step size * -1. The third time the outer loop runs, the direction of one the motors (the same motor) should be reveresed again so it is moving in its original direction etc.

Hope that made sense...

 

I have attached my code for clarification - any help would be really appreciated

Thanks,

Mridu

0 Kudos
Message 1 of 24
(3,696 Views)

Hi mnanda,

 

there are several ways to achieve your goal.

 

- Most straight-forward: have the user input this "snake pattern". You program is kept simple and small, but the user will hate you.

- Implement some logic to calculate this pattern. You seem to know, how it should look like, so you should be able top develop some logic…

- Think about using a state machine. This will greatyl help for problems like this: once you implement some basic states like "move forward" and "move backward" you only need to call the states in the correct order!

 

And while you do all this: learn LabVIEW.

- THINK DATAFLOW and you will not need all those sequence structures!

- The most simple way to remove sequence structures is to use a small subVI for a wait function with some additional error in/out terminals…

- Why do you use 4 FormatIntoString functions followed by a huge ConcatString function when all this could be done using ONE FormatIntoString?

- Using BytesAtPort is senseless when your serial communication uses a TermChar as you have configured!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 24
(3,642 Views)

Hi GerdW,

 

Thank you for your response. Couple more questions though..

1) Can you explain the meaning/difference between bytes at port and termination characters? I did some research on it and am still confused..

2) Also, how is it possible to connacatonate the strings with the FormatIntoString function? Could you show me an example using my original code?

 

Thanks for all your help, I realy appreciate it!

Regards,

Mridu

0 Kudos
Message 3 of 24
(3,555 Views)

Hi mnanda,

 

1: When using the TermChar feature VISARead will wait for a) the number of bytes to read (using a constant as input!), b) the termchar to arrive at the port c) timeout as usual. No need to check the bytes received in the buffer so far, no need to concatenate the received strings, no need for additional error checking…

 

2: Easy as this:

check.png

As indicated in the image: NEVER delete labes from controls/indicators! Either hide them in the UI and/or display captions for the user!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 4 of 24
(3,519 Views)

@GerdW wrote:

 

As indicated in the image: NEVER delete labes from controls/indicators! Either hide them in the UI and/or display captions for the user!


If it helps, try to think of these labels as the names of variables in text based language.  They aren't really variables, and in LabVIEW the variables are the wires.  But you can see why having an empty variable name in a texed based language could be difficult to understand and follow.

Message 5 of 24
(3,487 Views)

Hello, 

 

Thank you both for your help; that really cleared some things up. GerdW, one more question, what do you mean by no need for addition error checking?

 

Regards,

Mridu

0 Kudos
Message 6 of 24
(3,443 Views)

Also, can you explain to me the reason for the delay before read (I am just modifying the default exapmle program in the labview folders)

Thanks,

mridu

0 Kudos
Message 7 of 24
(3,371 Views)
The example programs for serial are not the best and they have a delay because of the Bytes at Serial Port being used. That requires a wait in order for the instrument to have time to respond. When you use a termination character and no Bytes at Serial Port, a wait is not needed.
Message 8 of 24
(3,348 Views)

Hi all,

When I deleted the bytes at port property node, I am getting "VISA Read: Contains bad or unwired terminal error" How should I fix this?

Thanks,

Mridu

0 Kudos
Message 9 of 24
(3,235 Views)

You have to wire in SOME value.

 

If your device uses a termination character, then "bytes at port" is generally the wrong way to determine how many bytes to read.  (I really regret that NI examples seem to emphasize bytes at port.  It seems to cause problems for anyone who really doesn't understand how serial communications works.)  You should wire in a constant in a constant that is larger than the longest message you ever expect to see.

 

Bytes at Port should only be used in a situation where someone is creating a terminal type of program, figure out how many bytes are there, read them, display them, when you don't care about whether a message is complete or not.

Message 10 of 24
(3,190 Views)