LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

transforming c files to labview

int n, m;
	char path_to_cams[64];
	char cameratype[64];
	char path_to_cam[64];
	char path[128];
	char sno[64];
	char pathn[128];
	char pathm[128];
	int type;
	int countn, countm;


	/* Initialize NxLib and enumerate cameras */
	nxLibInitialize(&error, NXLIBTRUE);
	if (nx_result(error)) return -1;

	/* Open TCP port to use NxTreeEdit */
	nxLibOpenTcpPort(&error, 24001, &port);
	if (nx_result(error)) return -1;

	/* Path to the cameras node */
	strcpy(path_to_cams, "/Cameras/BySerialNo");

	/* Get number of connected cameras */
	num_cams = nxLibGetCount(&error, path_to_cams);
	if (nx_result(error)) return -1;

	/* Print information for all cameras in the tree */
	printf("Serial No   Model       Type           Status\n");
	for (n=0; n<num_cams; ++n)
	{
		sprintf(path, "%s/\\%d/SerialNumber", path_to_cams, n);
		printf("%-12s", nxLibGetString(&error, path));
		sprintf(path, "%s/\\%d/ModelName", path_to_cams, n);
		printf("%-12s", nxLibGetString(&error, path));
		sprintf(path, "%s/\\%d/Type", path_to_cams, n);
		printf("%-15s", nxLibGetString(&error, path));

		char* status;
		sprintf(path, "%s/\\%d/Status/Open", path_to_cams, n);
		if (nxLibGetBool(&error, path)) {
			status = "Open";
		} else {
			sprintf(path, "%s/\\%d/Status/Available", path_to_cams, n);
			if (nxLibGetBool(&error, path)) {
				status = "Available";
			} else {
				status = "In Use";
			}
		}

		printf("%-12s\n", status);
	}

	/* Identify first Ensenso camera */
	sno[0] = '\0';
	for (n=0; n<num_cams; n++)
	{
		sprintf(path, "%s/\\%d/Type", path_to_cams, n);
		strcpy(cameratype, nxLibGetString(&error, path));
		if (cameratype[0] == 'S')
		{
			sprintf(path, "%s/\\%d/SerialNumber", path_to_cams, n);
			strcpy(sno, nxLibGetString(&error, path));
			break;
		}
	}
	if (sno[0] == '\0')
	{
		printf("No stereo camera found!\n");
		return -1;
	}
	else printf("Opening camera %s\n", sno);
	
	/* Open camera with serial number */
	sprintf(path_to_cam, "/Cameras/BySerialNo/%s", sno);
	printf("Path to camera: %s\n", path_to_cam);

	nxLibSetString(&error, "/Execute/Parameters/Cameras", sno);
	if (nx_result(error)) return -1;
	nxLibSetString(&error, "/Execute/Command", "Open");
	if (nx_result(error)) return -1;
	nxLibWaitForType(&error, "/Execute/Command", NxLibItemTypeNull, 5);
	if (nx_result(error)) return -1;
	/* Check if command has succeeded: ErrorSymbol not existing */

	/* Access example matrix: */
	/* Calibration/Stereo/Reprojection is a 4x4 matrix */
	sprintf(path, "%s/Calibration/Stereo/Reprojection", path_to_cam);
	printf("Item path: %s\n", path);
	if (nxLibGetType(&error, path) != NxLibItemTypeArray)
	{
		if (nx_result(error)) return -1;
		printf("Type of %s is not Array!\n", path);
		return -1;
	}
	countn = nxLibGetCount(&error, path);
	if (nx_result(error)) return -1;
	printf("Array has %d elements\n", countn);

	for (n=0; n<countn; n++)
	{
		/* Check each element: either Number or Array */
		sprintf(pathn, "%s/\\%d", path, n);
		if (nxLibGetType(&error, pathn) == NxLibItemTypeNumber)
		{
			printf("Array element %d is Number: %f\n", n, nxLibGetDouble(&error, pathn));
			if (nx_result(error)) return -1;
		}
		else if (nxLibGetType(&error, pathn) == NxLibItemTypeArray)
		{
			countm = nxLibGetCount(&error, pathn);
			if (nx_result(error)) return -1;
			printf("Array element %d has %d elements:", n, countm);
			for (m=0; m<countm; m++) 
			{
				sprintf(pathm, "%s/\\%d", pathn, m);
				printf(" %f", nxLibGetDouble(&error, pathm));
				if (nx_result(error)) return -1;
			}
			printf("\n");
		}
		else
		{
			printf("Array element %d is not neither Array nor Number!", n);
		}
	}

	printf("Press enter to quit.\n");
	getchar();
    
	/* Close TCP port */
	nxLibCloseTcpPort(&error);
	if (nx_result(error)) return -1;

	/* Close NxLib */
	nxLibFinalize(&error);

	return 0;
}

#ifndef __NXLIB_H__
#define __NXLIB_H__

#include "nxLibVersion.h"
#include "nxLibConstants.h"

#if defined (_WIN32) || defined (__WINDOWS__)
	#if defined(NxLib32_EXPORTS) || defined(NxLib64_EXPORTS)
		#define NXLIB_EXPORT __declspec(dllexport)
	#else
		#define NXLIB_EXPORT __declspec(dllimport)
	#endif
#else /* defined (_WIN32) */
	#define NXLIB_EXPORT
#endif

#ifndef ATTR_UNUSED
	#if defined (_WIN32) || defined (__WINDOWS__)
		#define ATTR_UNUSED
	#else /* defined (_WIN32) */
		#define ATTR_UNUSED __attribute__((unused))
	#endif
#endif

#include "nxLibFunctions.h"

#ifdef __cplusplus
extern "C" {
#endif
#ifndef NXLIB_DYNAMIC_LOAD
	NXLIB_EXPORT void nxLibInitialize  (NXLIBERR* result, NXLIBBOOL waitForInitialCameraRefresh);

	NXLIB_EXPORT void nxLibFinalize    (NXLIBERR* result);

	NXLIB_EXPORT void nxLibOpenTcpPort (NXLIBERR* result, NXLIBINT portNumber, NXLIBINT* openedPort);
	NXLIB_EXPORT void nxLibCloseTcpPort(NXLIBERR* result);
#endif
#ifdef __cplusplus
}
#endif

#ifdef __cplusplus
	static void ATTR_UNUSED nxLibInitialize(bool waitForInitialCameraRefresh = true) {
		int result;
		nxLibInitialize(&result, waitForInitialCameraRefresh);
		nxLibCheckReturnCode(result);
	}

	static void ATTR_UNUSED nxLibFinalize() {
		int result;
		nxLibFinalize(&result);
		nxLibCheckReturnCode(result);
	}

	static void ATTR_UNUSED nxLibOpenTcpPort(int portNumber = 0, int* openedPort = 0) {
		int result;
		nxLibOpenTcpPort(&result, portNumber, openedPort);
		nxLibCheckReturnCode(result);
	}

	static void ATTR_UNUSED nxLibCloseTcpPort() {
		int result;
		nxLibCloseTcpPort(&result);
		nxLibCheckReturnCode(result);
	}
#endif

#endif /*__NXLIB_H_*/

hello all,

   I am new to the Labview software so could someone help me in transforming the c interface files in labview as a block diagram .I have attached two example codes from the c file to interface the ensenso N10 camera from labview. Thanks in advance .

0 Kudos
Message 1 of 9
(4,109 Views)

I think you are in a mistake. This forum is not for finding people to do your job for free. But if you show your VI, and describe what part you find difficult to program, people will help you happily. Without showing some effort it is very unlikely that someone will program for you.

Unless you want to pay, then you can find people in this forum board:

http://forums.ni.com/t5/LabVIEW-Job-Openings/bd-p/JobPost

 

If you are a beginner in LabVIEW, you can find free and other sources (requiring SSP licence) to learn it, see the links at the top right of the forum board:

 

edit: it requires registration to download, so I have no idea about the usability, but this company provides 3rd party interfaces. The LabVIEW package might contain ready to use examples, have a look:

https://en.ids-imaging.com/ueye-interface-labview.html

0 Kudos
Message 2 of 9
(4,100 Views)

Hello blok,

 Thanks for the info but I jus need a help to operate a TCP port and how to pass the values in dll in this . Its not tat I din put a effort !! Thanks again ! 

0 Kudos
Message 3 of 9
(4,091 Views)

@sasha7691 wrote:

Hello blok,

 Thanks for the info but I jus need a help to operate a TCP port and how to pass the values in dll in this . Its not tat I din put a effort !! Thanks again ! 


If you did put effort into your project, then you could attach your project or VI(s) and describe what you tried so far, what is the problem, and what is your exact goal...

0 Kudos
Message 4 of 9
(4,086 Views)

@sasha7691 wrote:

Hello blok,

 Thanks for the info but I jus need a help to operate a TCP port and how to pass the values in dll in this . Its not tat I din put a effort !! Thanks again ! 


Look in the Example Finder (Help->Find Examples).  There are a few TCP examples in there.  There should be a DLL call example somewhere in there as well.  Might be under "Call Library Function".



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 5 of 9
(4,083 Views)

Hello crossrulz, 

 Yes I have used those example in my vi but I don't know how to proceed further by linking Nxtree edit ! 

0 Kudos
Message 6 of 9
(4,076 Views)

Hello blokk, 

I created a example block diagrams for each programming tasks and trying to understand the code ! I created a TCP port from LabVIEW forums n examples ! 

0 Kudos
Message 7 of 9
(4,073 Views)

It looks like you're trying to call functions from a DLL here, and the DLL provides functions for opening a TCP port, so you should use those functions for communicating with your device instead of using the native LabVIEW TCP functions.

 

Have you tried using the DLL Import Wizard? While it's not perfect, it will usually create VIs for most of the functions in a DLL although some may require minor adjustments. In your case, you'll need to make sure the wizard can find the additional header files nxLibVersion.h and nxLibConstants.h.

 

Once you've successfully created LabVIEW VIs for each function in the DLL that you want to call - either with the wizard, by hand, or some combination of the two - then you can start duplicating the logic from the C code in LabVIEW. It doesn't look like there's any complicated C operations in the sample code, so it should be straightforward to duplicate in LabVIEW, although you'll have to change some things - for example, in LabVIEW, you write strings to front panel indicators instead of printing them to a terminal.

 

Are you familiar enough with C to understand the sample code? If you don't understand C and you don't understand LabVIEW, you'll either need to set aside a lot of time to get this working, or you'll need to get help - from a colleague, or pay for training, or hire someone to do the work for you.

0 Kudos
Message 8 of 9
(4,005 Views)

Hello Nathand,

  Thanks for such informative response !! I m trying interface my camera in LabVIEW and it does not need TCP port beca it has USB connection .Yes I do , but passing parameters inside each DLL is wat bit confusing for me !! But thanks I got informed tat it will b helpful wit different c-example for connecting ensenso in LabVIEW 🙂 

0 Kudos
Message 9 of 9
(3,995 Views)