10-18-2007 01:11 PM
10-22-2007 10:11 AM
10-22-2007 12:52 PM
Song,
In VB.NET I added the following to DAQTask.User.vb
Protected Overrides Sub OnTaskStopping(ByVal e As System.EventArgs) MyBase.Task.Control(TaskAction.Abort) MyBase.OnTaskStopping(e) End SubThe sub is called whenever the task completes either normally or when I explicitly use DAQTaskComponent1.StopTask in my UI. I don't like calling Abort under all circumstances, but when I tried to use MyTask.Task.IsDone I get an unhandled exception if an asynchronous read is in progress.
Is the method I'm using something that NI recommends?
Steve
10-22-2007 08:50 PM
10-23-2007 05:45 PM
1) I'm attaching several screen shots.
Asynch1.jpeg
This is a VS2005 debug screen shot that includes a watch on the task. All I did was call StopTask from the UI when I hit a stop button. Notice that the IsDone property shows as "error: cannot obtain value". Lots of other properties have the same error, for example the AI channel which I'm acquiring.
The ACQ is asynch generated by DAQ Assistant, not a MAX task.
In Asynch2.jpeg I show the simple method that I originally tried to use to catch if the task is done. When that code is used and I stop the task before completion using a stop button in the UI then after the task timeout period elapses I get the result shown in Asynch3.jpeg. The error code is -200284.
2) This is real hardware. PXI-1036, PXI-PCI bridge (MXI-4) and PXI-6281 DAQ
3) I'm calling IsDone from the OnTaskStopping event handler.
4) The OnTaskStopping code is included in the snap shots. Code that sets up the ACQ is below and the rest of it is auto-generated.
'Raises the TaskCreated event.Protected Overrides Sub OnTaskCreated(ByVal e As EventArgs)
'TODO: Perform custom DAQmx task configuration, such as advanced timing and triggering, here.
' ' Refer to "Adding Custom Functionality to a .NET DAQ Component" in the NI Measurement ' Studio Help for an example of advanced DAQmx task configuration. MyBase.OnTaskCreated(e) 'Set the ACQ timeout to 150% of the expected move time. Much safer than infinityTask.Stream.Timeout = 1000 * 1.5 * HallGlobals.HallScanClass.NZ * HallGlobals.HallScanClass.DZ / HallGlobals.HallScanClass.ZScanSpeed
Dim ChannelLabel As String = HallRunner.MainScanForm.ComboChannels.SelectedItem Dim ChannelName As String = HallRunner.MainScanForm.ComboVoltageSource.SelectedItem Dim ADRange As Double = HallRunner.MainScanForm.ComboRange.SelectedItem Dim AIScale As String = HallRunner.MainScanForm.ComboScales.SelectedItem If AIScale Like "HPI*" Or AIScale Like "DTM*" ThenAIScale = AIScale &
"-" & HallRunner.MainScanForm.ComboHPRange.SelectedItem & "kG" End If 'Added acq of 2nd channel. This is a temperature channel and is not user selected right now 'TODO: Make properties of 2nd channel user selectableTask.AIChannels.CreateVoltageChannel(ChannelLabel, ChannelName, AITerminalConfiguration.Differential, -ADRange, ADRange, AIScale)
Task.AIChannels.CreateThermocoupleChannel(
"Dev1/ai0", "Thermocouple", 0, 100, AIThermocoupleType.K, AITemperatureUnits.DegreesC, 0) Dim TaskAIChannel As NationalInstruments.DAQmx.AIChannelTaskAIChannel = Task.AIChannels.Item(0)
TaskAIChannel.RangeHigh = ADRange
TaskAIChannel.RangeLow = -ADRange
TaskAIChannel.CustomScaleName = AIScale
TaskAIChannel.VoltageUnits = AIVoltageUnits.FromCustomScale
Task.Timing.ConfigureSampleClock("PFI1", 100000, SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples, HallRunner.MainScanForm.NumberOfPoints.Value) End SubSteve
10-24-2007 03:19 PM