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!
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.
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.
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
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?
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.
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.