LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to generate UDP traffic

I need to write a program similar to the UDP Sender.vi example to generate UDP traffic.
 
My traffic needs to be a series of 60 16-bit words. I want to form the words by entering "1010101010101010" etc. but when I do this in a string control the data gets sent as a character, not a binary integer i.e. 1 byte not 1 bit.
 
How can I do this in LabVIEW? I thought about maybe converting each 16-bit word into 2 ascii characters but I got stuck.
 
It's vital I send the data as 960 bits (60 x 16) since I am emulating a piece of hardware I want to connect my program to, but be able to test the software before I have access to the hardware.
 
Please help! Thanks
0 Kudos
Message 1 of 8
(4,713 Views)
The input to UDP Write (data in) is a string. You will need to convert your data somehow to a string.

You could pass your array of U16 to the Split Number fonction, pass this to Interleave 1D arrays, then conver the interleaved 1D array to Byte Array to String. You could also try using a typcast with an Type of string, but your byte order may not match depending on what device you are talking to on the other side...





Message Edited by Phillip Brooks on 11-28-2007 02:39 PM
0 Kudos
Message 2 of 8
(4,702 Views)

Thanks - I'll give this a go and report back.

In the meantime how is the UDP Read function likely to interpret raw bits of data in a datagram? Will it try to read them as ASCII since the data output from the VI is a string type.

0 Kudos
Message 3 of 8
(4,691 Views)

russelldav,

It sounds as though you are trying to come up with a way to create binary data streams and stuff them in a string to send using UDP Write.vi.  There are probably a million ways for you to create an interface that allows a user to enter binary data.  If you need to enter it as 16-bit 1's and 0's, you could put an array of 16-bit unsigned integers on your front panel, turn on the radix, and format to show 16-digits.  When you are ready to send, you can use Byte Array to String.vi to convert to string suitable for sending.  You will need to do some bit-jockying to get the bytes in order.  Attached is one possible 8.2.1 solution.

-cb

0 Kudos
Message 4 of 8
(4,690 Views)
10Degree - would it be possible for you to provide an example that is 7.1 friendly??
 
Ultimately I want to emulate the data because I want to test my program against receiving the 960bits. I guess formatting them into a string isn't the best way to do this as they are then not arriving as they will when I connect to my hardware.
0 Kudos
Message 5 of 8
(4,688 Views)
I would use the reverse functions. Convert the string to an array (will be U8) decimate the 1D array, then use join numbers; or typecast the data out string of UDP Read with a type of Array of U16.
 
As for the bit order, it wuill depend on how your remote side creates the string. LabVIEW's uses big endian for data storage. For and example see:
 
 
0 Kudos
Message 6 of 8
(4,683 Views)
Fantastic thanks so much guys!!! Smiley Happy
0 Kudos
Message 7 of 8
(4,677 Views)
Sorry, I can't get all the way back to 7.1.  Here is an image of the code. -cb
0 Kudos
Message 8 of 8
(4,664 Views)