LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to unpack binary data from UDP port?

I have a device that is sending data to the computer via UDP.   I currently have python code that "unpacks" this data and turns it into something meaningful but I'm having trouble understanding how I can do this in cvi.  I can read the packed data using UDPRead but then in printing it out I just get a bunch of weird ascii and eventually I get a nul-terminated string and the program quits.  I guess I have to convert the data from binary to dec first but not exactly sure how. Are there any built-in cvi functions I can take advantage of?  I've attached the main python function that I've been using to accomplish this. Thanks!
 
0 Kudos
Message 1 of 5
(5,059 Views)
Hi Hillb,

There is a simple CVI shipping example that demonstrates how to do a UDP read.  I suggest that be the first place you look if you haven't looked at it already.

If you installed CVI in the default directory you can find this example here:
C:\Documents and Settings\All Users\Documents\National Instruments\CVI85\samples\udp\UDPReader.prj

I'll also suggest you take a look at this Developer Zone article:
"Building Networked Applications with the LabWindows™/CVI UDP Support Library"
http://zone.ni.com/devzone/cda/tut/p/id/6723

It explains a lot of the concepts and terminology CVI uses when doing UDP communication.

Let me know if you have more questions about these.


Kristen
National Instruments
0 Kudos
Message 2 of 5
(5,027 Views)

...and after you have read your message into an unsigned char variable (e.g. "msg[ ]") you can simply do the following to transform the message into meaningful values:

     int  cmdid, isData, result;

       cmdid = (msg[0] << 😎 + msg[1];
       isData = msg[2];
       result = (msg[3] << 😎 + msg[4];



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 3 of 5
(5,015 Views)
Thanks Roberto! I'll give it a try.  I already have UDPRead working

0 Kudos
Message 4 of 5
(5,013 Views)
hillb wrote:
"I guess I have to convert the data from binary to dec first but not exactly sure how"

computer science course, lesson 1: A VARIABLE STORES A NUMBER, NOT THE REPRESENTATION OF A NUMBER !

e.g.:
int a = 8;
'a' contains the value which is commonly represented by humans as 8 in decimal. but it is also 1000 in binary or 10 in octal of 8 in hexadecimal. thus, all those tests are true without performiong any 'conversion' on the variable:
a == 8      // decimal
a == 0x8  // hexadecimal
a == 010  // octal

(food for thought: decimal is a weird representation used by humans only because they have 10 fingers. imagine if we had 4 fingers on one hand, and 3 on the other)
0 Kudos
Message 5 of 5
(4,999 Views)