Industrial Communications

cancel
Showing results for 
Search instead for 
Did you mean: 

LabVIEW newbie - TCP communications

Hello All!

 

I was posting about error 66 but I realized my mistake. If anyone runs into the issue where your server seems to receive a message from your client but only after the client disconnects and generates error code 66, it's possibly due to telling LabVIEW TCP Read to read far more Bytes than the client is actually sending. A common enough standard is to prepend your message with 2 Bytes in "Network-Byte Order" (Big-Endian) that represents the Byte-length of the message to receive. This is large enough for most purposes, since 2 Bytes represents 2^16 possible values, lending to a maximum message length of 65,535 Bytes.

 

I've included an image of how to read a string, convert it into a Byte-array, reverse it, index the array, use a logical shift to shift the 2nd element by 8 bits, and add the shifted element to the 1st to convert the pair into a usable little-endian integer for the next read. Works well enough for me.

Jfran82_0-1649655297384.png

 

Still new to LabVIEW, if anyone has better methods, I'd be happy to see them!

0 Kudos
Message 1 of 4
(1,483 Views)

Unfortunately, a blurry, truncated picture of very messy code is not suitable to demonstrate anything at all.

 

Did you ever look at the shipping examples?

 

(Whatever you are doing here can be done with 20% of the code. And why would you convert to little endian? Pure Rube Goldberg.

Your code is completely wrong and will not work, because shifting a U8 by 8 positions does not leave anything, right?. Index array is also resizable.

Why are you trying to micormanage datatypes. sending 4 bytes I32 ( a much, much more "common standard"!) would be more natural, even if you never use all bits. No coercion dots!)

 

Here's are two alternative versions to get a big endian U16 out of 2 bytes....

 

altenbach_0-1649702298802.png

 

0 Kudos
Message 2 of 4
(1,460 Views)

Hey Altenbach, thanks for the clarification. No, I haven't seen the shipping examples. I did not find them in the examples folder. Would this be what you are referring to?
Archived: Download NI-DAQmx Shipping Examples for LabVIEW 2012 or Compatible - NI Community

0 Kudos
Message 3 of 4
(1,449 Views)

No, in LabVIEW go to "menu...help...find examples" to open the NI example finder. All these examples come preinstalled with LabVIEW!

 

Search for "TCP" and open the example project called "Simple TCP.lvproj"

 

altenbach_0-1649719490461.png

 

0 Kudos
Message 4 of 4
(1,446 Views)