Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with PXI-6534 DIsposing Change Detection Task

Solved!
Go to solution

I have run into the following problem.  I am using a PXI-6534 and PXI-6602 with vb.net to do change detection with a time stamp.  My code works great and I get data exactly as I want, the problem comes when I try to call the task.dispose function.

 

When I call the dispose, it throws an exception with error code -200088, Task Does not exist.  But the task is still stopped and I can run my code again and everything works fine.  If I don't call the task.dispose, I get an error when I try to run my code again.  The hardware seems to get left in an unknown state, and I have to restart my computer to get it back. (the NI MAX won't even reset the 6602, it just says that the board does not exist.)

 

Also interesting, is the exception thrown does not seem to get captured by the Try   Catch method.  The code goes through the Try  Catch with no problems (stepping through the code anyway), but the message box with the exception pops up, either right away, or when exiting the subroutine.

 

Also, I am using TestStand 4.2 to call these functions, if that makes a difference.

 

Any help would be greatly appreciated!  Its very frustrating that everything works, and I get my data perfectly, but that I can't run the code without the exception popping up, and I can't seem to catch the exception!

 

 

Here is the code that I am using:

 

    Public Sub StartChangeDetect_UUT1()
        If myCDrunningTaskA Is Nothing Then
            Try
                ' Create the task
                uut1ChangeDetectTask = New Task()

                '************************ Create the digital input virtual channel alias
                'Assign ports to digital virtual channel
                uut1ChangeDetectTask.DIChannels.CreateChannel("Dev1/port0:3", "ChangeDetectUUT1", ChannelLineGrouping.OneChannelForAllLines)
                'uut1ChangeDetectTask.DIChannels.All.DigitalFilterEnable = True
                'uut1ChangeDetectTask.DIChannels.All.DigitalFilterMinimumPulseWidth = 0.000001
                uut1ChangeDetectTask.DIChannels.All.InvertLines = True
                uut1ChangeDetectTask.DIChannels.All.DataTransferMechanism = DIDataTransferMechanism.Dma

                'Assign ports to monitor for change detection, both rising and falling edges
                Dim rising As String
                Dim falling As String

                rising = "Dev1/port0:3"
                falling = "Dev1/port0:3"
                uut1ChangeDetectTask.Timing.ConfigureChangeDetection(rising, falling, SampleQuantityMode.ContinuousSamples, 4000000)


                'export change detect event to PXI backplane so we can get timestamps from timer.
                uut1ChangeDetectTask.ExportSignals.ChangeDetectionEventOutputTerminal = "/Dev1/PXI_Trig0"
                uut1ChangeDetectTask.ExportSignals.ChangeDetectionEventPulsePolarity = ChangeDetectionEventPulsePolarity.ActiveHigh

                'uut1ChangeDetectTask.Stream.Timeout = 20000


                ' Verify the Task
                uut1ChangeDetectTask.Control(TaskAction.Verify)


                ' Set up the data table
                Initializeuut1DataTable()



                ' Create the readers for the DI and the CI
                uut1ChangeDetectReader = New DigitalSingleChannelReader(uut1ChangeDetectTask.Stream)

                uut1CDCallback = New AsyncCallback(AddressOf uut1ChangeDetectCallback)
                uut1ChangeDetectReader.SynchronizeCallbacks = False
                ' Set up our first callback

                uut1ChangeDetectReader.BeginReadMultiSamplePortUInt32(-1, uut1CDCallback, uut1ChangeDetectTask)
                myCDrunningTaskA = uut1ChangeDetectTask

                'Set up Timer for time stamp

                uut1TimeStampTask = New Task()
                '****************set up PXI-6602 timer to get buffered change events.  ie capture timer output on  the PXI_Trig0
                'we can then correlate this timer capture buffer to the change detect buffer to get the time stamps

                uut1TimeStampTask.CIChannels.CreatePeriodChannel("Dev5/ctr0", "TimeStamp1", 0.0000001, 0.02, CIPeriodStartingEdge.Rising _
                             , CIPeriodMeasurementMethod.LowFrequencyOneCounter, 4, 4, CIPeriodUnits.Seconds)
                uut1TimeStampTask.CIChannels.All.CounterTimebaseRate = 20000000.0

                'Use exported change detect from 6534 board to take counter sample
                uut1TimeStampTask.Timing.ConfigureImplicit(SampleQuantityMode.ContinuousSamples)
                uut1TimeStampTask.CIChannels.All.PeriodTerminal = "/Dev5/PXI_trig0"
                'uut1TimeStampTask.CIChannels.All.DuplicateCountPrevention = False
                uut1TimeStampTask.CIChannels.All.DataTransferMechanism = CIDataTransferMechanism.Dma


                ' Set timeout
                'uut1TimeStampTask.Stream.Timeout = 20000
                ' Verify the Task
                uut1TimeStampTask.Control(TaskAction.Verify)
                uut1TimeStampReader = New CounterReader(uut1TimeStampTask.Stream)
                uut1TSCallback = New AsyncCallback(AddressOf uut1TimeStampCallback)

                

                uut1TimeStampReader.SynchronizeCallbacks = False
                uut1TimeStampReader.BeginReadMultiSampleDouble(-1, uut1TSCallback, uut1TimeStampTask)
                myTSrunningTaskA = uut1TimeStampTask



            Catch exception As DaqException
                ' Display Errors
                MessageBox.Show(exception.Message)
                uut1StopChangeDetection("C:\PT3771\TestResults\")
            End Try
        End If
    End Sub

   
	Private Sub uut1ChangeDetectCallback(ByVal result As IAsyncResult)
		Try
			'If runningTask Is ar.AsyncState Then
            If myCDrunningTaskA Is uut1ChangeDetectTask Then
                ' Read the available data from the channels
                Dim data As UInt32() = uut1ChangeDetectReader.EndReadMultiSamplePortUInt32(result)

                Dim b As UInt32
                For Each b In data
                    ' in TestData waveform Y axix is data, x axis is time 

                    uut1TestData.SetY(uut1ChangeDataIndex, b)
                    uut1ChangeDataIndex += 1

                Next b

                '' Set up a new callback
                uut1ChangeDetectReader.BeginReadMultiSamplePortUInt32(-1, uut1CDCallback, uut1ChangeDetectTask)
            End If
        Catch exception As DaqException
            ' Display Errors
            MessageBox.Show(exception.Message)
            uut1StopChangeDetection("C:\PT3771\TestResults\")
        End Try
	End Sub	'DigitalCallback

    Private Sub uut1TimeStampCallback(ByVal result As IAsyncResult)
        Try
            'If runningTask Is ar.AsyncState Then
            If myTSrunningTaskA Is uut1TimeStampTask Then
                ' Read the available data from the channels
                Dim data2 As Double() = uut1TimeStampReader.EndReadMultiSampleDouble(result)

                ' in TestData waveform Y axix is data, x axis is time 
                Dim b As Double
                For Each b In data2
                    uut1TimeSum = uut1TimeSum + b
                    uut1TestData.SetX(uut1TimeStampIndex, uut1TimeSum)
                    uut1TimeStampIndex += 1
                Next b

                ' Set up a new callback
                uut1TimeStampReader.BeginReadMultiSampleDouble(-1, uut1TSCallback, uut1TimeStampReader)

            End If
        Catch exception As DaqException
            ' Display Errors
            MessageBox.Show(exception.Message)
            uut1StopChangeDetection("C:\PT3771\TestResults\")
        End Try
    End Sub 'CounterCallback


	Public Sub uut1StopChangeDetection(ByVal location As String)

        Try
            If Not (myTSrunningTaskA Is Nothing) Then
                uut1TimeStampTask.Dispose()
                myTSrunningTaskA = Nothing

            End If

            If Not (myCDrunningTaskA Is Nothing) Then
                uut1ChangeDetectTask.Dispose()
                myCDrunningTaskA = Nothing

            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

        uut1TestData.UpdatePointCount()
        uut1TestData.SaveToDisk("C:\PT3771\TestResults\uut1TestWaveFile.csv")
        uut1TestData.SaveToDiskBinary("C:\PT3771\TestResults\uut1TestWaveFile")
	End Sub	'StopTask

 

0 Kudos
Message 1 of 5
(4,319 Views)

Hello tboydston,

 

Thanks for posting. This is an interesting issue that you are seeing. Let me make sure I understand: you said that when you run your code with the task.dispose method called, you get error -200088, but you can run the task again afterward just fine. When you run the code again, do you also get the same error message when you dispose of the task again?

 

I briefly looked over your code and I had a few questions/suggestions:

 

-Where exactly is the error thrown, and is the error thrown on the first task dispose or the second? Try stepping through the code to see exactly which call causes the error.

-It appears that the Sub that calls the dispose task, uut1StopChangeDetection, is called at the end of the other sections in the case of an exception elsewhere in the program. Perhaps one issue could be that the dispose task is being called more than once, thereby trying to dispose of a task that is already gone. 

-Are you able to run other similar programs without getting an error? One good place to start would be the .NET example programs that ship with the DAQmx driver (found in Start>>Programs>>National Instruments>>NI-DAQ>>Text-Based Code Support>>.NET 3.5/4 Examples).

 

Let me know when you get a chance, thanks!

 

Regards,

Joe S.

0 Kudos
Message 2 of 5
(4,303 Views)

Joe,

 

Thanks for responding.

 

To answer your first question, if I call the task.dispose for the tasks in question, uut1TimeStampTask and uut1ChangeDetectTask, I can run the code over and over, but I will get the message box for the exceptions thrown everytime the code is run.  If I don't dispose of these tasks, when I try to run the code again, the PXI-6602 hardware is locked up such that I have to reboot the PXI chassis and the PC.   I can reset the PXI-6534 with MAX, but MAX won't even recognize that the PXI-6602 is there until I reboot.

 

Also, I should have been more clear that both of the tasks are throwing exceptions when they are disposed.

 

When I step through the code, the exception is not thrown for these tasks until the code gets past the try catch sequence.  So its like the dispose is being done 2 times in a row quickly, and the first one is successful and exits the try catch, but then the second throws the exception because the first one worked?  Is it possible for me to use NI-Spy to see if this is happening?

 

I did use a .net example to build my change detect task, but there were no examples of how to do change detection using the timer card for a time stamp.  I ran accross some old examples that used the older DAQ drivers with C and Labview, but nothing with the DAQmx.  Do you have any examples of change detection using a DIO card and timer card together to get an accurate timestamp?

 

Also, on a unrelated note, do you know if the PXI-6534 supports digital input filtering?

 

Thanks again for your help.

 

Thad

0 Kudos
Message 3 of 5
(4,300 Views)
Solution
Accepted by tboydston

Joe,

 

Latest update.  It seems that when the task.dispose is ran, the callbacks seem to get called one last time.  I took out the call to the stopUUT1ChangeDetect in both callbacks ( so the dispose wouldn't get run a second time)  and no more exceptions were thrown.

 

Thanks for your help!  Although if you would still answer my question on the PXI-6534 digital input filtering I would appreciate it.

 

Thanks again.

 

Thad

0 Kudos
Message 4 of 5
(4,299 Views)

Thad,

 

Glad to hear that we have removed the exceptions! According to the NI-DAQmx Help, Digital Filtering Considerations for DIO Devices, the 653x family of devices does not support digital input filtering. I hope this helps!

 

Regards,

Joe S. 

0 Kudos
Message 5 of 5
(4,289 Views)