LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Determine which button has been pressed

Hello!

 

I am attempting to control a DC Power Supply (the Aim TTI CPX400DP). I am communicating via TCP/IP and sockets. I am using LabVIEW 2013.

 

What I am trying to do, is when a certain button is pressed (such as "Set Voltage" or "Set Current"), I want to send a message to the power supply to set the voltage or current. Currently the method I am using (which is probably the worst method, I'm sure) is to have a case structure that reads strings, and depending on which string was sent, perform some action. These input strings are determined by which button is pressed. However, I am not really sure how to read from a series of case structures to determine what message (or what button) was pressed/sent? Attached is my VI. I'm sure my method of attempting this is wrong, so if you have any ideas to help, I am wide open to suggestions!


Thanks in advance for any help!

SM

0 Kudos
Message 1 of 8
(4,476 Views)

Update:

 

I found a way to kind of determine which button is pressed by using the "Match First String" function. So now it is working good. Is there a way to keep this program running until like a "stop" is pressed or an error is encountered or TCP connection is lost? That way I don't have to keep hitting "Run" everytime I want to send a value? Attached is the altest version of my VI.

 

Thanks,

SM

0 Kudos
Message 2 of 8
(4,458 Views)

An event structure is really what you are looking for to determine what button has been pushed and the value of that button.  You can use a simple eventstructure or something like a QMH to do this.  I dont know your end goal for the application.

 

http://www.ni.com/white-paper/3331/en/



-Matt
Message 3 of 8
(4,452 Views)

@Sman29 wrote:

 

Is there a way to keep this program running until like a "stop" is pressed 

 


I think you need to stop for a moment and view some of the information available here: Learn LabVIEW

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 4 of 8
(4,401 Views)

So I got it to work using a WHILE loop. However, one of my cases (the default/false case) isn't working properly, I keep getting a timeout error. The other 2 cases (set current and voltages) work just fine, but for some reason the default case keeps getting a timeout error... Any ideas as to what I am doing wrong? Attached is my VI and SubVI's. The "Get Output Values" is the VI that keeps getting the timeout error... Could it be due to the TCP read # of bytes to read? For example if I am trying to read 4 bytes, but there are only 2 bytes of data actually on the port, will it throw the timeout error?

 

Thanks,

SM

Download All
0 Kudos
Message 5 of 8
(4,350 Views)

Also this SubVI, I could only attach 3 items in my initial reply.

0 Kudos
Message 6 of 8
(4,348 Views)

Thank you for attaching VIs!  To get pass the "three attachment" rule, simply compress the folder holding your VIs (right-click Folder, choose Send To and use Compress) and attach the resulting .Zip file.

 

Bob Schor

Message 7 of 8
(4,327 Views)

1. For future reference, it is easiest to put your entire project into a zip file and attach that instead of all of the VI individually.

2. Seriously, learn to use the Event Structure.  It will make life a lot easier on you.

3. Please do not use references and property nodes to update an indicator.  Pass the string values out and write to the terminal directly.

4. I recommend making subVIs for each querry you are performing.  Then you can reuse those subVIs where needed.

5. It looks like your instrument sends a CR LF combination at the end of every response.  Use this to your advantage.  There is an input on the TCP Read called "Mode".  You can create a constant and set it to CRLF.  Then you just tell the TCP Read to read more bytes than you would ever expect from response and the read will be complete when that CR LF combo is read.


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
Message 8 of 8
(4,324 Views)