LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Help with reading information coming from a software into LabVIEW through Serial port

how do I implement an if else statement on LabVIEW? I am trying to use Mathscript.

 

eg. input I into mathscript. C and D are outputs but will be using only one according to if else statement

 

if I =1 or 2 or 3

C=I and do a case structure

else

D=I and do some other structure.

 

When I do this, error is "LabVIEW:  The given name does not correspond to a known function, variable, or symbol."

 

It is just that I have to use one of the 2 outputs at one time.

 

V

I may not be perfect, but I'm all I got!
0 Kudos
Message 51 of 66
(1,671 Views)

Is that you actual syntax? Have you looked in the Help under Mathscript? The syntax is fully documented.

 

If that's all you're doing with Mathscript then it's overkill. Why don't you just use plain ol' G-code?

0 Kudos
Message 52 of 66
(1,663 Views)

Hi guys,

 

I went through Mathscript help and now I hv got it working.

 

My case structure has a condition where if it occurs, while loop stops which stops the program. But wht seems to happen is that the serial port reads the next command faster than the while loop timer and so the loop ends and starts again because the serial read buffer has the command.

 

My  question now is. ... How do i correct that? How do I make sure that the condition stops the while loop so that even if the serial port has read the next command, that condition doesnot start the while loop again?

 

V

I may not be perfect, but I'm all I got!
0 Kudos
Message 53 of 66
(1,642 Views)
It sounds to me like you may have a race condition. If you post your code it will be easier to diagnose.
0 Kudos
Message 54 of 66
(1,634 Views)
I think it is time for you to post the latest copy of your VI so we can see how it is working now.  It is difficult to debug a paragraph. Smiley Wink
0 Kudos
Message 55 of 66
(1,633 Views)

HI Guys,

 

Sorry for the late reply to your posting. Was caught up with something else and Thanksgiving.!! 🙂 I cannot attach the whole program, but I am attaching a simulation of the control program I am using. The main part that I am looking at is the Serial communication. 

 

Like I had mentioned before, the problem with the program's while loop ending and starting again is  Resolved but in many cases it happens again.

 

I have one more problem now. 😞 If you take a look at the program, serial communication breaks when Start/Stop phase occurs (I have replaced a huge case structure with Start/Stop LED) What happens is when Start/Stop Boolean control is true, labview takes over running the Start/Stop case structure that results in break in constant communication. Only until the case has completed does the communication continue. BUt, what I need is communication through serial port at all times, even when control is transferred to the case structure. Does that mean that I have to include the serial communication blocks inside the Start/Stop case structure?I hope my question is clear. Please let me know

 

VJ

 

 

I may not be perfect, but I'm all I got!
0 Kudos
Message 56 of 66
(1,568 Views)

FYI, there is no HUGE case structure in the simulation I have attached, but assume instead of the Start/Stop LED, there is a huge case structure that runs for 18 min. 🙂

 

V

I may not be perfect, but I'm all I got!
0 Kudos
Message 57 of 66
(1,566 Views)

VeeJay wrote:

there is a huge case structure that runs for 18 min. 🙂


18 min Smiley Surprised Smiley Wink

0 Kudos
Message 58 of 66
(1,562 Views)
Yes 18 minutes.... 😉
I may not be perfect, but I'm all I got!
0 Kudos
Message 59 of 66
(1,558 Views)

VeeJay wrote: 

Like I had mentioned before, the problem with the program's while loop ending and starting again is  Resolved but in many cases it happens again.


If it still happens then it's not resolved, now is it?

 


I have one more problem now. 😞 If you take a look at the program, serial communication breaks when Start/Stop phase occurs (I have replaced a huge case structure with Start/Stop LED) What happens is when Start/Stop Boolean control is true, labview takes over running the Start/Stop case structure that results in break in constant communication. Only until the case has completed does the communication continue. BUt, what I need is communication through serial port at all times, even when control is transferred to the case structure. Does that mean that I have to include the serial communication blocks inside the Start/Stop case structure?I hope my question is clear. Please let me know

I have no idea which is the "Start/Stop" case structure. There are 4 cases, but none are labeled, so only you know what they are. I have some comments regarding the code:

  • Do not initialize the serial port inside the loop. This should be outside the loop.
  • Why are you using Mathscript for trivial calculations? They incur a ridiculous amount of overhead for something that can be done with a comparison function and a Select function. 
  • I don't understand what you're doing with controls/indicators of the same name. This is confusing. Is somebody supposed to look at the control or the indicator? It appears in the code that you are writing to the controls through property nodes, and you're simply writing to the indicator directly from the control. This is pointless. Even more pointless is reading an indicator's value via a property node and then writing the value back using the terminal! Do you just like to use up CPU time?
  • You really should consider using a state machine architecture.

EDIT: Additional comment: Anything that holds up code for 18 minutes is a clear mark of a bad design/implementation. You should not have anything that blocks code for that amount of time.
Message Edited by smercurio_fc on 11-30-2009 11:27 AM
Message 60 of 66
(1,556 Views)