12-13-2014 01:15 AM
Dear Reader,
I am trying a simple udp communication from one system to another. I have conditions of not to change the receiving vi as it is fixed. I am attaching my vi's sending and receiving part. Please go through it and give me suggestion on how to code the sending part without changing receiving part and successfully communicating by udp.
I am just a starter in LabVIEW.I beleive Your suggestions of ideas will be valuable to step forward.
Regards
Srinath,R
Solved! Go to Solution.
12-13-2014 01:50 AM
Well, does it work?
Who wrote the receiving VI, because it has some of he weirdest bit gymnastics I have seen in a long time.
Casting a string to a DBL array, then casting it to a boolean array seems ridiculous. In between, you are even taking an array subset that just returns the input array (A subset starting with element zero and lengh of "all" does nothing!). I think the receiver should be rewritten in a more sane way. Who says that the receiver should be "fixed"?
The new sender is equally silly: Taking two booleans, converting them to a U32 integer, turning it into an U32 array with 1 element, converting that array to a DBL array with one element, then casting it to a string seems mad.
You are turning two boolean into a string of 8 characters. Seems very inefficient. Done right, you could send 8 booleans in a string with one single character!
Also, why are you sending the same data over and over as fast as the computer and network allows?
The way you are packing the data is inconsistent with the way you are unpacking it on the receiver. Also, the receiver reads 5 LEDs, while you are only sending two.
I think you should design the entire thing (sender & receiver) from scratch. Look at some of the examples that ship with LabVIEW.
12-13-2014 03:53 AM
Dear Reader,
Thank you for your quick response.
Receiving vi is an extract of a big code. I know the receiving code with the array subset part is logicless. But it make sense
in the main big code. I have mimic the main code receiving part as it is in the receivig vi. I honestly accept that Big code is not of any standard architectures or any standard procedures which has been deployed in the client place(WORKING FINE). THUS, We cannot change the receiving vi (boss order). As we can't change the receiving
package, I tried directly reversing the logic of receiving at the sending vi which was not working. Thus asked your favour. Your idea is clear from your reply to start from scratch which will be successfull. Can you please try a logic of sending package without alering the receiving package?
Please ignore the conceptless array subset logic of zero index. In the main code the array subset is used to denote middle of a huge array.Thus i
index
index
12-13-2014 07:02 AM - edited 12-13-2014 07:03 AM
The receiver uses Unflatten From String. So why wouldn't you use Flatten To String? This is very important that you use Flatten To String since the reciever expects the data to be Little Endian. The Type Cast tends to assume Big Endian.
12-13-2014 10:48 AM
@crossrulz wrote:
The receiver uses Unflatten From String. So why wouldn't you use Flatten To String? This is very important that you use Flatten To String since the reciever expects the data to be Little Endian. The Type Cast tends to assume Big Endian.
The receiver casts a string to a DBL array to a boolean array, meaning evey byte of the DBL represents a single boolean element. On the sender, the use of "boolean array to number" only utilizes two bits of one single byte to represent the two booleans. The two methods are still incompatible.
For symmetry, we would need to omit the "boolean array to number" and then cast the array directly.
Byte order is fine as long as we use typecast on both ends as it is currently done.
12-13-2014 11:00 AM - edited 12-13-2014 11:01 AM
The easiest way is to eliminate the networking and just cast to string and back. Here's a quick test bed.
All you need to do is reverse engineer the receiver, should not be too hard. You can immediately see that you current code is wrong.
Below is how this could be implemented more intelligently on both sides.
12-13-2014 11:09 AM - edited 12-13-2014 11:10 AM
One thing you need to know is that casting to a DBL (or DBL array) requires eight bytes (or an integer multiple of 8).
The sender needs to send 8 bytes, which is most easily done by reshaping (padding) the boolean array to 8 element (using reshape array) before casting it to a string.
Here is code that works. You can easily implement it into your original code.
12-17-2014 06:40 AM
Dear Sir,
Your code with the crazy receiver is working fine. Thanks For your ideas. I will in future make or deal with standard codes.
Sincerely
Srinath R