cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

Sending a value from Labview to a running dll

Solved!
Go to solution
Highlighted

Sending a value from Labview to a running dll

Hello everyone,

as a follow up to this thread, I am trying to send a value to a running dll. 

Here is a test example which I wrote, and I was expecting to be able to stop the running loop in the dll by setting the pStop pointer to "1" from Labview by pressing the pStop button.

 

__declspec(dllexport) int test_value_from_LV(unsigned int *pStop)
{
	std::ofstream logFile;
	logFile.open("log.txt");
	if (!logFile.is_open()) { return -1; }
	unsigned int value = 0;
	
	for (int i = 0; i < 100; i++) {
		
		if (*pStop == 1)
			i = 1000;
		
		value = *pStop;
		logFile << "pStop: " + std::to_string(value) + "\n";
		Sleep(100); //wait 100ms
	}
	
	logFile.close();
	return 0;
}

This is the block diagram with the settings and the outputs of the MoveBlock.

The log.txt in the dll saves "pStop: 883828976" even after pressing the pStop button.

Any help or hint is appreciated.

 

2.JPG1.JPG

 

The source code of the dll is available and is written in C++. Labview 2015, 64Bit, windows 7.

Thank you in advance.

 

0 Kudos
Message 1 of 3
(116 Views)
Solution
Accepted by topic author Skydive
02-11-2019 05:13 AM

Re: Sending a value from Labview to a running dll

Think about what source and destination mean here. Do you really want to copy the contents of your pointer to the value read from the boolean control?

 

And think about what will happen with your pointer if you terminate the loop before your loop inside the DLL has finished!

 

And an int32 is only 4 byte, if you try to copy 8 bytes as you do now, you overwrite memory that you should never touch, and once you change source and destination you still read memory that you shouldn't.

Rolf Kalbermatter
Averna BV
LabVIEW ArchitectLabVIEW ChampionLabVIEW Instructor
Message 2 of 3
(66 Views)

Re: Sending a value from Labview to a running dll

Hi Rolf,

Thanks for the hints.

 

I switched the src and dst and its parameters accordingly at MoveBlock and it workes as expected.

I'm not really sure if I got your second point correctly, but in the real VI, the LV loop will be stoped after the dll finished his loop (or externally stopped). So I guess the DSDisposePtr will just kill the pointer as it is no more needed!?

 

Thanks again for the worthy guides..

Arash

 

 

0 Kudos
Message 3 of 3
(36 Views)