05-12-2009 05:44 AM - edited 05-12-2009 05:46 AM
I am using LabVIEW 8.2.1. and I use the Application Builder to generate DLL-files from LabVIEW VI's. I would like to create a DLL that generates a square wave on my PXI-4461. I used the DAQ assistant to generate the code for the PXI-4461 and since I want a continuous signal, the code is generated inside a while-loop. I have no problems starting my square wave, but I am unsuccessful stopping it. I know for sure that arrays are passed by reference so I decided to pass a stop flag inside an array to the DLL from my (C#) application. However, the value of the stop flag is not updated inside the while-loop in the LabVIEW-code, I confirmed this by adding a message box inside my LabVIEW code. What is wrong with my code? A picture of my VI is attached and the relevant C# code looks like this:
private void testButton_Click(object sender, EventArgs e)
{
LabViewInterface.startSendingOutSquareWave();
System.Threading.Thread.Sleep(3000);
LabViewInterface.stopSendingOutSquareWave();
MessageBox.Show("Have now tried to stop the square wave");
}
public class LabViewInterface
{
private static volatile IntPtr stopFlagPtr = Marshal.AllocHGlobal(8);
[DllImport("SendOutSquareWave.dll")]
private static extern void SendOutSquareWave(IntPtr stopArray, int stopLength);
public static void startSendingOutSquareWave()
{
Marshal.Copy(new double[] { 0 }, 0, stopFlagPtr, 1);
Thread workerThread = new Thread(delegate()
{
unsafe
{ // Call dll
SendOutSquareWave(stopFlagPtr, 1);
}
});
workerThread.Start();
}
public static void stopSendingOutSquareWave()
{
Marshal.Copy(new double[] { 1 }, 0, stopFlagPtr, 1);
}
}
05-12-2009 08:02 AM
05-12-2009 09:11 AM
05-12-2009 09:16 AM
In this case it doesn't make a difference whether I use the keyword ref or not, I have tried.