07-29-2015 10:24 PM
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
07-30-2015 01:16 AM
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!
07-30-2015 10:09 PM
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
07-31-2015 01:22 AM - edited 07-31-2015 01:24 AM
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:
As indicated in the image: NEVER delete labes from controls/indicators! Either hide them in the UI and/or display captions for the user!
07-31-2015 08:30 AM
@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.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
16 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
07-31-2015 10:54 PM
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
08-01-2015 10:31 AM
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
08-01-2015 11:41 AM
08-02-2015 09:34 AM - edited 08-02-2015 09:35 AM
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
08-02-2015 12:41 PM
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.