LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

UDP COMMUNICATION FROM ONE SYTEM TO ANOTHER USING TYPE CAST

Solved!
Go to solution

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

                   

Download All
0 Kudos
Message 1 of 8
(4,045 Views)

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.

 

 

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

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

Download All
0 Kudos
Message 3 of 8
(4,010 Views)

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.


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
0 Kudos
Message 4 of 8
(3,999 Views)

@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.

0 Kudos
Message 5 of 8
(3,987 Views)

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.

 

 

 

 

Download All
0 Kudos
Message 6 of 8
(3,981 Views)
Solution
Accepted by SRIFOUR

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.

 

 

Message 7 of 8
(3,974 Views)

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.Smiley Wink

 

Sincerely

Srinath R

 

 

0 Kudos
Message 8 of 8
(3,889 Views)