LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Interacting with network streams with C++

Hi all,

 

For a project I wanted to my C++ driver to communicate with a labview program on a SBRio, which normally expects network streams from another LabView program. Because this task seems rather daunting I decided to first do a proof of concept and so I copied the example networks stream program and tried to put the sender side into a C program. When I run just the two labview programs the communication goes fine but in the C version it gets stuck. I managed to export the DLL and compile the C file with the DLL linked but when running the resulting executable it gets stuck with the following error:

 

'C:\Program' is not recognized as an internal or external command, operable program or batch file.

 

Does anyone have an idea on where this error is coming from and how to fix it?

Additionally, are there any better methods out there for communicating with network streams outside of labview than exporting functions DLL's?

Download All
0 Kudos
Message 1 of 3
(90 Views)

NI developed Network Streams to provide a fast and convenient mechanisms for transferring LabVIEW data from one PC to another (or to the same PC) using TCP/IP Networks.  I suspect the methodology is proprietary, involving as it does handling all the varieties of LabVIEW data types, and maintaining compatibility over all LabVIEW versions since its release in 2010.

 

While I like (and use) Network Streams, particularly when dealing with LabVIEW Real-Time routines that have a Host (PC) and Target (some form of RIO), with separate Streams for Host->Target messages, Target->Host messages, and (several) Target->Host Data streams, when I have suggested Network Streams to participants on this LabVIEW Forum, other experienced developers suggest TCP, which has the advantage of not being tied to LabVIEW.  You might want to consider using TCP for the communication channel(s) to your C++ program.

 

Bob Schor

0 Kudos
Message 2 of 3
(76 Views)

@bob007450 wrote:

are there any better methods out there for communicating with network streams outside of labview than exporting functions DLL's?


Yes, if you looking for "tiny" solution, then I would like to recommend to check Network Streams Library from LabWindows/CVI. From this library you will get header and may be you can use it directly from your "C++ driver" compiled with Visual Studio or other compiler your choice.

 

Writer:

Spoiler
int main()
{
	CNSEndpoint endpointID;
	
	/* Create a new writer endpoing and try connect to a reader endpoint      */
	/* located at //localhost/reader                                          */
	CNSNewScalarEndpoint("ni.dex://localhost:cvi_writer/writer", "//localhost/reader", CNSTypeInt32, 1000, 0, CNSDirectionWriter, CNSWaitForever, 0, &endpointID);
	
	for (int i = 0; i < 100; i++)
		CNSWriteScalar(endpointID, CNSWaitForever, i);
	
	CNSFlush(endpointID, CNSWaitForever, CNSFlushAllItemsReadFromStream);
	CNSDiscardEndpoint(endpointID);
	CNSFinish();

	return 0;
}

Reader:

 

Spoiler
int main()
{
	int val;
	CNSEndpoint endpointID;
	
	/*Create a new reader endpoing and wait for the writer endpoint to connect*/
	printf("Waiting for writer endpoint to connect...\n");
	CNSNewScalarEndpoint("reader", "", CNSTypeInt32, 1000, 0, CNSDirectionReader, CNSWaitForever, 0, &endpointID);
	
	
	for (int i = 0; i < 100; i++)
	{
		CNSReadScalar(endpointID, CNSWaitForever, &val);
		printf("%2d ", val);
		if ((i+1) % 10 == 0)
			printf("\n");
	}
	
	CNSDiscardEndpoint(endpointID);
	CNSFinish();
	
	printf("Press enter to exit..."); 
	getchar();

	return 0;
}

I think these functions above called from "C:\Program Files\National Instruments\Shared\Network Streams\cnetstreams.dll"

 

The similar question was about Shared Variables and how to communicate from non-LabVIEW environment - check Re: Python and Shared Network Variables.

 

Wrapping everything into LabVIEW-based DLL will work for sure, but will produce "heavy weight" DLL with dependencies on LabVIEW Run-Time.

Message 3 of 3
(68 Views)