LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Run VIs on LVRT

Just giving a hint here if anybody is interested in running a bunch of VIs on a PC running LV RT (Pharlap/ETS) if he doesnt have the Real-Time Labview addon.

 

just create a dll like the following one (which i called LVRTInjector.dll (I used a VC++  2008 Express installation I had at hand, default Win32 project, DLL type). 

 

 

// dllmain.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"

bool Initialized = false;

DWORD WINAPI StarterProc(
  LPVOID lpParameter
);

BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
					 )
{	
	DWORD ThreadId;
	HANDLE ThreadHandle;

	switch (ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:
		break;
	
	case DLL_THREAD_ATTACH:
		if(Initialized) return TRUE;

		Initialized = TRUE;

		printf("1st Stage Injector\n");

		ThreadHandle = CreateThread(NULL,0,StarterProc,NULL,	0,&ThreadId);

		if (NULL == ThreadHandle)
		{
			printf("Failed creating Injector thread\n");
		}

		break;
	case DLL_THREAD_DETACH:
		break;
	case DLL_PROCESS_DETACH:
		break;
	}
	return TRUE;
}

DWORD WINAPI StarterProc(
  LPVOID lpParameter
)
{	
	void (*StartFunc) ();
	HMODULE Loader;
	int i = 15;
	Loader = LoadLibrary("C:\\ni-rt\\startup\\2ndStageLoader.dll");
	if(Loader != NULL)
	{
		printf("Loaded C:\\ni-rt\\startup\\2ndStageLoader.dll\n");
		printf("Acquiring function Startup....");
		StartFunc = (void (__stdcall *)(void))GetProcAddress(Loader, "Startup");

		if(StartFunc != NULL)
		{
			printf("Success\n");
			for(i = 15; i > 0; i--)
			{
				printf("2nd Stage Loader - Executing in: %d\n", i);
				Sleep(1000);
			}			
			printf("Executing\n");
			StartFunc();
		}
		else
		{
			printf("Failed\n");
		}

	}
	else
	{
		printf("...error. 2nd Stage Loader not present in C:\\ni-rt\\startup\\ folder\n");
	}

	return 0;
}

Once you create this DLL add it to the list of StartupDLLs in your ni-rt.ini file under the [LVRT] key.

 

Then create a new Labview project and create a DLL of it (like in this example http://ftp.ni.com/pub/devzone/tut/calllvbuiltdllfromcpp.zip) make sure this contains a function called Startup.vi and that the Labview generated dll is named 2ndStageLoader.dll (dont mind DLLPrintf, it's a debug helper I made)

2ndstage.png

 

Startup.vi diagram is like follows

startupvi.png

now close the Labview DLL project and create a standalone VI called starter.vi (discard the PRINT E vi, just my debug)

startervi.png

 

Now you are ready to run your project.

 

Create a new project and add a source distribution, make sure the source distribution name is app and that the LLB name is going to be app.llb

 

distrib.png

 

start.vi is the starting point of you application

 

In the source distribution properties make sure that under "Source Files" the start.vi is always included

 

source files.png

 

The Destination Directory under Destination is set as LLB

 

destinations.png

 

 

And additional exclusion must look like this

 

Additional Exlusions.png

 

Now using any FTP client, just drop the ni-rt.ini in you LVRT pc root folder, then add the

2ndStageLoader.dll, starter.vi and app.llb into you real-time PC ni-rt\startup folder and just reboot after reeboting the Injector will load the 2nd Stage Loader and wait 15 seconds (to allow the RT to finish loading) then it will call it's Startup function, which in turn will call the starter.vi which will then start your app by calling start.vi

0 Kudos
Message 1 of 5
(3,557 Views)

Very interesting that you were able to "hack" access to the PharLap system.  However, other than "doing mischief", I can't envision a need for all this effort.  If you really need the benefits of LabVIEW Real-Time (which we do), then the simplicity of developing LabVIEW RT code with the LabVIEW RT Toolkit/Module (sorry, I don't remember which is the correct designation) seems so "worth it".

 

Here's a (very poor) analogy.  If you want to develop code to run on an NI FPGA chip, you can, of course, program directly to the FPGA, or you can use LabVIEW and let NI do the compilation and translation for you.  It's no contest ...

 

Bob Schor

0 Kudos
Message 2 of 5
(3,501 Views)

Is it really a good practice to say "I know the LV RT addon is legally required to be licensed to do this.  But, if you want to get around that licensing, here's how to do so" and post it on the company's forums?

0 Kudos
Message 3 of 5
(3,486 Views)

I dont understand your statement. The RT addon is not legally required to do anything. It is required if you want the RT addon capabilities. Which have nothing to do with running a bunch of VI on the RT. Sure the add on makes it simple and allows you to debug and other nice features. Can you please point what clause this is breaking?

0 Kudos
Message 4 of 5
(3,459 Views)

Bob, i'm not "hacking" anything. The system allows to run DLLs and I am showing how handy that is. Jeez. How many harsh words for a CreateThread + a bunch of Invokes->Run VI.

0 Kudos
Message 5 of 5
(3,457 Views)