Real-Time Measurement and Control

cancel
Showing results for 
Search instead for 
Did you mean: 

UDP Read doesn't work on Real Time Target

Solved!
Go to solution

Hi,

 

I am currently running LabVIEW RT 8.6.1 on a PXI 8106 RT controller.  LabWindows/CVI Runtime Engine for RT 9.0.0 is also installed as I am developing using LabWindows/CVI 9.0.  I am trying to send some UDP data from an external PC over the network to the software running on the controller but this isn't working.  The UDP data packets are definitely getting sent out (I can receive them on my PC when I reconfigure the transmitter with my PCs IP address) but the UDP callback function is not being called.  The call to CreateUDPChannelConfig returns OK.  Here is the (very simple) code I have written based on the NI UDP read example:

 

 

#include <udpsupp.h>
#include <cvirte.h>
#include <rtutil.h>

// Global variables
static int reader_channel = 0;

// Global functions
int CVICALLBACK UDPCallback (unsigned channel, int eventType, int errCode, void *callbackData);

/// HIFN The main entry-point function for the Real-Time DLL.
void CVIFUNC_C RTmain (void)
{
	int errno;
	
	if (InitCVIRTE (0, 0, 0) == 0)
		return;    /* out of memory */

	// Create UDP receive task
	errno = CreateUDPChannelConfig(49152, UDP_ANY_ADDRESS, 0, UDPCallback, NULL, &reader_channel);
	
	while (!RTIsShuttingDown ())
	{
		SleepUS (1000);
	}	

	CloseCVIRTE ();
}

int CVICALLBACK UDPCallback (unsigned channel, int eventType, int errCode, void *callbackData)
{
	static int udp_received = 0, default_rx = 0;
	
	switch (eventType)
	{
		case UDP_DATAREADY:
			udp_received++;
			break;
		default:
			default_rx++;
			break;
	}
	
	return 1;
}

All that is happening is that the software is just waiting for the callback to get called (which it never does).  I found this posting which describes a similar problem but the developer was using LabVIEW and although he found a way round the problem, it was never understood as to why this worked.

 

Thanks

Martin

 

Message 1 of 2
(3,661 Views)
Solution
Accepted by topic author greenstuff

Hey,

 

Although the problem is now solved, I thought I would post up the code for others to view in case the same error is encountered. The modified code is tested and works. it is saved as an attached png file.

 

Regards

Andrew George @ NI UK
Message 2 of 2
(3,526 Views)