Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

VB .NET, daqmx 7.5, repeated asynchronous output task failure

I'm getting an unusual error (-200557 : property cannot be set while the task is running) during task configuration on second instance. 

It's unusual because the task isn't running yet.

My application outputs a waveform asynchronously and then disposes the AO task.

When the waveform is changed, and the task is started again (as a new task), I get the error while trying to configure timing, triggering, etc. 
Even if I explicitly stop the task before the config, the error persists.

Any thoughts on this would be appreciated

Here's the basic code idea (it's multifunction, but the input seems fine with the recursion)

        inputTask = New Task("AsyncMITask")
        AsyncAIReader = New AnalogMultiChannelReader(inputTask.Stream)
        outputTask = New Task("AsyncMOTask")
        AsyncAOWriter = New AnalogSingleChannelWriter(outputTask.Stream)
        AsyncAOCallBack = New AsyncCallback(AddressOf AsyncAOWrite)

        Try
            inputTask.AIChannels.CreateVoltageChannel(AsyncAIChanString, "", AITerminalConfiguration.Differential, -10, 10, AIVoltageUnits.Volts)
            inputTask.Timing.ConfigureSampleClock("", AsyncAIFreq, SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples)
            inputTask.Stream.ReadAllAvailableSamples = False
            inputTask.Triggers.StartTrigger.ConfigureDigitalEdgeTrigger("/Dev1/PFI0", DigitalEdgeStartTriggerEdge.Rising)


            outputTask.AOChannels.CreateVoltageChannel(sAOChan, "", -10, 10, AOVoltageUnits.Volts)
            outputTask.Timing.ConfigureSampleClock("", AsyncAOFreq, SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples, 3 * ASyncAOTotalPoints)
            outputTask.Stream.WriteRegenerationMode = WriteRegenerationMode.DoNotAllowRegeneration
            outputTask.Triggers.StartTrigger.ConfigureDigitalEdgeTrigger("/Dev1/PFI0", DigitalEdgeStartTriggerEdge.Rising)

            AsyncAOWriter.BeginWriteMultiSample(False, AsyncAOEQData, AsyncAOCallBack, Nothing)

            inputTask.Control(TaskAction.Verify)
            outputTask.Control(TaskAction.Verify)

            outputTask.Start()
            inputTask.Start()

            AsyncInputTaskRunning = True
            AsyncOutputTaskRunning = True

            AsyncAICallBack = New AsyncCallback(AddressOf AsyncAIRead)

            AsyncAIReader.BeginReadMultiSample(AsyncAIBufferLength, AsyncAICallBack, Nothing)


        Catch ex As NationalInstruments.DAQmx.DaqException
            MsgBox(ex.Message)
        End Try
----------------------------------
If the task really were running already, I wouldn't be able to start a new instance of it and would get the familiar -50103 error
I've debugged the dispose event, so I know that it is happening.

thanks in advance.


0 Kudos
Message 1 of 2
(3,300 Views)
Hi Nate,

I'm not quite sure why you are getting the error you are seeing.  Granted, something has to be making it appear that your task is running when it isn't.  For this case it may help if we can find out what line of code you are seeing the error at.  That way we can figure out which line we are dealing with and narrow down where the error is.

In the start of your post you mentioned that you were trying to output a waveform and then change it and output the new waveform.  That sounds a lot like Non-regeneration which allows you to write a new waveform to your AO buffer without having to start and stop the task.  If that is something you didn't know about then take a look at some of the information below:
The command that you need is as follows. You can also find this information on the command by going to Start > All Programs > National Instruments > NI-DAQ > NI DAQmx Function Reference Help and searching for the command:

"DAQmxSetWriteRegenMode(TaskHandle taskHandle, int32 data);

"Data Type: int32
Description:
Specifies whether to allow NI-DAQmx to generate the same data multiple times.
If you enable regeneration and write new data to the buffer, NI-DAQmx can generate a combination of old and new data, a phenomenon called glitching.

"Valid values:
- DAQmx_Val_AllowRegen - 10097
Allow DAQmx to regenerate samples that the device previously generated. When you choose this value, the write marker returns to the beginning of the buffer after the device generates all samples currently in the buffer.
- DAQmx_Val_DoNotAllowRegen - 10158
Do not allow NI-DAQmx to regenerate samples the device previously generated. When you choose this value, NI-DAQmx waits for you to write more samples to the buffer or until the timeout expires.

"You can get/set/reset this property using:
  DAQmxGetWriteRegenMode
  DAQmxSetWriteRegenMode
  DAQmxResetWriteRegenMode
"

If you can use LabVIEW there is already an existing example online: DAQmx - Continuous Reconfigurable Waveform Generation Using Non-Regeneration
Block Diagram Steps:
1. Create an Analog Output Voltage channel.
2. Configure the task to prohibit the automatic regeneration of data.
3. Call the DAQmx (Sample Clock) VI to set the sample clock rate. Additionally, set the sample mode to Continuous.
4. Read the actual sample clock rate (eventually coerced depending on the hardware used).
5. Compute the desired waveform, using the buffer size and the actual update rate. This VI keeps track of the phase of the waveform to ensure that the generated signal is continuous.
6. Write the waveform to the output buffer.
7a. Call the Start VI. This is only needed when the loop is executed for the first time.
7b. Do nothing.
8. Loop continuously until user presses the Stop button. Every iteration computes and writes a new waveform to the buffer.
9. Call the Clear Task VI to clear the Task.
10. Use the popup dialog box to display an error or warning if any.
Regards,
0 Kudos
Message 2 of 2
(3,283 Views)