09-25-2012 02:51 PM - edited 09-25-2012 02:54 PM
Hey,
Very new to LabVIEW and having trouble getting the UDP VI's to work properly. I'm trying to use the UDP VI's to send data that is acquired in my main VI from a FieldPoint device to a Sub VI when a button is pressed. I can get it to work when I made a basic VI to run in parallel with my main VI just to try and understand the UDP setup, but when I copy it over to my Sub VI it will only send the first reading then doesn't update. Any ideas why one works and the other doesn't?
Thanks in advance for any help or suggestions,
dnorman
SubVI setup
Solved! Go to Solution.
09-26-2012 01:28 PM
I still can't seem to find the error. I'm guessing it is just some small error that I'm overlooking, but then again I'm new to LabVIEW. Anyone with a bit more experience see a blaring error that I'm missing?
Thanks,
dnorman
09-26-2012 02:05 PM
If you save your VI for an older version of LabVIEW (anything prior to 2012) I'm willing to take a look. However, I really don't understand your question, nor your VI (based on the screenshots). Wires should run left-to-right (this is a style, not function, issue) and it's odd that you'd put the UDP open and close outside a case structure but put the read inside it. Normally you open the UDP socket once when the code starts and close it at the end, not open it and close it for every individual packet you send or receive.
09-26-2012 02:19 PM - edited 09-26-2012 02:21 PM
Hello dnorman,
There are some great UDP examples that are shipped with LabVIEW
From LabVIEW go to Help»Find Examples...
Then from the Example Finder choose Networking»TCP&UDP
There are two VIs in this folder, UDP Sender.vi and UDP Receiver.vi
I would highly recommend starting from these examples and modifying as needed.
Thank you,
Joel C
National Instruments
09-26-2012 02:28 PM
Are you checking for errors at all on the sending side?
You have only attached the receiver, which also seems to have some weird coding constructs. It seems to use 100% cpu while doing nothing but spin the loop as fast as it can.
Where is the sender code shown in the image? Can you attach it too?
From the looks of your image, you seem to create and shutdown the connection with every iteration of the loop. Why? Is the local port important, the receiver does not seem to care about its value, so leave it disconnected. Why are you sending to the broadcast address?
Have a look at the shipping examples. I would recommend to prepend the data size so the receiver can determine how much to read.
In this particular case, I would recommend to use network shared variables instead. No need to roll your own.
09-26-2012 02:31 PM
Thanks for the reply. This is my first time working with LabVIEW so I'm still getting used to everything. I inherited a project at work from a previous employee after IT managed to erase 75% of his VI from the computer it was ran on.
I have already looked at the examples prior to posting here. The VI that I posted is the one that I made just to test the UDP setup. It works just like I want it to. The screenshots are from my main and sub VI's. The sub VI, to my knowledge, is setup the exact same way as my example VI, but doesn't work and I can't figure out why.
The open and close are outside because depending on the case there is different information sent.
Thanks,
dnorman
09-26-2012 02:39 PM - edited 09-26-2012 02:40 PM
If you keep your code this way, with a read in the case structure, you need to wire your refnum and error through the false case of the case structure. The way you have it set up now, it will "return default value" from the false case, so as soon as your program enters the false case, you lose your refnum to the open connection (because the default value is a null refnum). Also, with regards to the fact that each case has different data, don't put the read in the case structure, but do put the "string to number" in a case structure. If you have the read outside the case structure, you won't even have to deal with the previous mentioned issue about the refnum, because your refnum won't even have to be passed into the case.
09-26-2012 02:40 PM - edited 09-26-2012 02:45 PM
You again attached the same VI. Where is the code that sends?
@dnorman wrote:
The open and close are outside because depending on the case there is different information sent.
I am now talking a bout the picture on the right, where we are missing the real code: The open and close belong outside the while loop, they only need to bew done once per run. If there is different information being sent as a function of a case structure, all that needs to be in the case structure is the "different inforrmation". No need to duplicate UDP write.
Please show us your code!
09-26-2012 02:44 PM
@for(imstuck) wrote:
You need to wire your refnum and error through the false case of the case structure. The way you have it set up now, it will "return default value" from the false case, so as soon as it enters the false case, you lose your refnum to the open connection.
Since he reads the connection with every iteration from the tunnel, the missing reference will only matter if the VI is stopped. However the while loop is hardwired, so "UDP close" is unreachable anyway. THe only way is to abort, which will close the connection anyway.
09-26-2012 02:50 PM - edited 09-26-2012 02:51 PM
To add to what has been stated already.
Wire from left to right. It makes the code a lot easier to read.
Do not use the Abort button to stop a VI. Close it out properly. In this case, add a stop button instead of the false constant to stop the loop and close out the connection.
Wire the references through the case structures. You do not want to lose those. Bad things will happen if you do. I know from experience.
Here's a cleaned up version of your VI.