Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

daqmx error on dispose: pure virtual function call

Hello,

 

I have a problem when I stopping the task. I develop in C# into Visual Studio 2012, the program create a task on demand (1 task analog and 1 or more tasks counter). When I stop the tasks I have an error "pure virtual function call". I have found information but nothing for me.

 

When my program run into Visual Studio 2012 all work correctly, but out of Visaul Studio, I am a "pure virtual function call" !!!

 

This is the code (c#) of my stop function:

public void Stop()

{

   try

   {

      task.Stop();
      task.Dispose();                 // pure virtual function call

   }

   catch(Exception ex)

   {

       ...

   }

}

 

The error is on the Dispose, if I delete this line, I'm not the error but it's not possible to create another task with same line/name.

 

Do you have a solution?

 

Thanks

 

PS: Sorry for my bad english

0 Kudos
Message 1 of 4
(4,969 Views)

Hello Lachinaj,

To troubleshoot we would need to see a bit more of the code you execute before this function. Maybe you can show a short example of that? Does your device react as expected during earlier parts of the code?

 

Kind regards,

 

Jos Deurloo

national Instruments

Applications Engineer

 

0 Kudos
Message 2 of 4
(4,869 Views)

Hello,

 

All the application work correctly, and acquisition is correcte.

I'm tested it with NI simulated daqmx device and I'm not problem. 

I'm used a similar code (same acquisition) with DAQmx 8.6 and I'm nothing problem.

I'm tested it in 9.7 and 9.8 on windows XP and windows 7 with Framework 3.5, 4.0 and 4.5 but I'm always the same error.

 

This is my init code:

private Task task = null;
private AILine line = null;
private mainFrame parent = null;
private TcpClient client = null;
AnalogMultiChannelReader reader = null;
private AsyncCallback myCallBack = null;

public void run() { try { System.Console.WriteLine("AcquisitionAI"); task = new Task(line.line.Replace("/", "").Replace(",", "")); task.AIChannels.CreateVoltageChannel(line.line, "", AITerminalConfiguration.Differential, line.min, line.max, AIVoltageUnits.Volts); task.Timing.ConfigureSampleClock(null, line.rate, SampleClockActiveEdge.Rising, (line.mode == AILine.Mode.Finite)?SampleQuantityMode.FiniteSamples:SampleQuantityMode.ContinuousSamples, line.samples); if (line.pretriger > 0) { task.Triggers.ReferenceTrigger.ConfigureAnalogEdgeTrigger(line.trigger, (line.triggerslope == AILine.Slope.Rising) ? AnalogEdgeReferenceTriggerSlope.Rising : AnalogEdgeReferenceTriggerSlope.Falling, line.valTrigger, line.pretriger); } else { task.Triggers.StartTrigger.ConfigureAnalogEdgeTrigger(line.trigger, (line.triggerslope == AILine.Slope.Rising) ? AnalogEdgeStartTriggerSlope.Rising : AnalogEdgeStartTriggerSlope.Falling, line.valTrigger); } task.Control(TaskAction.Verify); task.Start(); reader = new AnalogMultiChannelReader(task.Stream); myCallBack = new AsyncCallback(AnalogiqueReadCallback); reader.SynchronizeCallbacks = true; reader.BeginReadMultiSample(line.samples, myCallBack, task); parent.Invoke(parent.m_DelegateSetAI, new Object[]{true, line}); parent.Invoke(parent.m_DelegateAddLog, new Object[] { "Start Acquisition AI" }); } catch (Exception e) { parent.Invoke(parent.m_DelegateSetAI, new Object[] { false, line }); Trace.TraceError(DateTime.Now + " : (ThAcquisitionAI:run) line: " + line + " " + e.Message); try { client.Client.Send(System.Text.Encoding.ASCII.GetBytes("<Comm><Error line='"+line.line+"'>" + e.Message + "</Error></Comm>")); } catch (Exception) { } parent.Invoke(parent.m_DelegateAddLog, new Object[] { "" }); parent.Invoke(parent.m_DelegateAddLog, new Object[] { "============== ERROR =============="}); parent.Invoke(parent.m_DelegateAddLog, new Object[] { "Run Acquisition AI Error:"}); foreach (string str in e.Message.Split("\n".ToCharArray())) { parent.Invoke(parent.m_DelegateAddLog, new Object[] { str }); } parent.Invoke(parent.m_DelegateAddLog, new Object[] { "===================================" }); parent.Invoke(parent.m_DelegateAddLog, new Object[] { "" }); } }

 

 

and the function receive

 

public void AnalogiqueReadCallback(IAsyncResult ar)
        {
            try
            {
                if (task == ar.AsyncState)
                {
                    double[,] value = reader.EndReadMultiSample(ar);
                    if (value.Length != 0)
                    {
                        if (client != null)
                        {
                            string[] lines = line.line.Split(",".ToCharArray());

                            for (int i = 0; i < value.GetLength(0); i++)
                            {
                                string values = "";
                                for (int j = 0; j < value.GetLength(1); j++)
                                {
                                    values += value[i, j] + ";";
                                }
                                client.Client.Send(System.Text.Encoding.ASCII.GetBytes("<Comm><Result num='" + num + "' line='" + line.line.Substring(0, line.line.IndexOf('/') + 1) + "ai" + i + "' value='" + values.Substring(0, values.Length - 1) + "'/></Comm>"));
                            }
                        }
                    }
                    task.Stop();
                    if ((task != null) && (client.Connected))
                    {
                        task.Start();
                        reader.BeginReadMultiSample(line.samples, myCallBack, task);
                    }
                }
            }
            catch (DaqException e)
            {
                if (e.Error == -200284)  // All sample not acquire
                {
                    try
                    {
                        task.Stop();
                        task.Start();
                        reader.BeginReadMultiSample(line.samples, myCallBack, task);
                    }
                    catch (NullReferenceException)
                    {
                    }
                    catch (ObjectDisposedException)
                    {
                    }
                }
                else if (e.Error == -200088)    // Abort
                {
                    parent.Invoke(parent.m_DelegateAddLog, new Object[] { "Abort: " + e.Message });
                }
                else if (e.Error == -88710)      // Abort
                {
                    parent.Invoke(parent.m_DelegateAddLog, new Object[] { "Abort: " + e.Message });
                }
                else
                {
                    parent.Invoke(parent.m_DelegateAddLog, new Object[] { "Restart error: " + e.Message });
                    try { client.Client.Send(System.Text.Encoding.ASCII.GetBytes("<Comm><Error line='" + line.line + "'>" + e.Message + "</Error></Comm>")); }
                    catch (Exception) { }
                }
            }
            catch (Exception e)
            {
                parent.Invoke(parent.m_DelegateAddLog, new Object[] { "Read AI error: " + e.Message });
                Trace.TraceError(DateTime.Now + " : (ThAcquisitionAI:AnalogiqueReadCallback) " + e.Message);
            }
        }

Thanks for your help

0 Kudos
Message 3 of 4
(4,582 Views)

Hello Lachinaj,

 

Firstly, I would like to know more when you mention these sentences.

- "When my program run into Visual Studio 2012 all work correctly, but out of Visual Studio, I am a "pure virtual function call" !!!" (What do you mean with out of the Visual Studio ?)

- "I'm used a similar code (same acquisition) with DAQmx 8.6 and I'm nothing problem." (What do you mean with similar code ? What are the changes you make ?)

So, please elaborate more on this issue so that I can provide you with help on the matter.

 

Secondly, when you do the installation of the DAQmx driver, you have to add support for .NET Framework which can be 3.5 4.0 or 4.5 version and then you can go to this path location (C:\Users\Public\Documents\National Instruments\NI-DAQ\Examples)and see the DotNET folder and inside that folder you will find examples that will show you how the function of "Dispose" is written in C# and compare it with your program.

I run one of the examples in that folder (C:\Users\Public\Documents\National Instruments\NI-DAQ\Examples\DotNET4.0\Analog In\Measure Voltage\AcqVoltageSamples_IntClk\CSand\AcqVoltageSamples_IntClk.2010.csproj) and it run without any errors in my PC, where I use Visual Studio 2012 & DAQmx 9.8 and also I run the project in both debug and release mode. Furthermore, I took the binary exe in the desktop and run it from there and still the project worked fine and no error was showing up. That being said, I was unable to reproduce your issue and I will need more information on what is going wrong at your side in order for me to provide you with support in this case. 

 

Looking forward to hearing from you.

Thank you in advance.

 

Best regards,

Leke Raifi

 

National Instruments Netherlands

Application Engineer (Intern)

Certified LabVIEW Associate Developer  

0 Kudos
Message 4 of 4
(4,328 Views)