Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

specified resource reserved for first 9 seconds of thread..

I get this error for the first 9 seconds of my 1 Hz thread:
 
10:52:32 ReadData
NationalInstruments.DAQmx.DaqException: The specified resource is reserved. The operation could not be completed as specified.
Task Name: mod1task
Status Code: -50103
   at nNIMSSAIL100.StatusObserverT<nNIMSSAIL100::ApiTraits<nNIMSSAIL100::DotNetApi> >.CheckWithName(StatusObserverT<nNIMSSAIL100::ApiTraits<nNIMSSAIL100::DotNetApi> >* , tCaseInsensitiveBasicString<unsigned short,_STL::char_traits<unsigned short>,_STL::allocator<unsigned short>,nNIDMXS100::tLocaleConsideringWideStringComparitor,nNIDMXS100::tLocaleConsideringWideStringCaseForcer>* pName)
   at nNIMSSAIL100.StatusObserverT<nNIMSSAIL100::ApiTraits<nNIMSSAIL100::DotNetApi> >.Check(StatusObserverT<nNIMSSAIL100::ApiTraits<nNIMSSAIL100::DotNetApi> >* , tTask* t)
   at ??$Read2D@V?$ApiTraits@VDotNetApi@nNIMSSAIL100@@@nNIMSSAIL100@@VAnalogRead@2@N@nNINETAI100@@$$FYGP$0... task, Int32 channels, Int32 samplesPerChannel, Int32 lines, Double timeout, Boolean interleaved)
   at NationalInstruments.DAQmx.Internal.AnalogMultiChannelReaderImpl.ReadMultiSample(Int32 samplesPerChannel)
   at NationalInstruments.DAQmx.AnalogMultiChannelReader.ReadMultiSample(Int32 samplesPerChannel)
   at DEER_DAQ.modFunctions.ReadData() in C:\DEER DAQ\modFunctions.vb:line 582
 
Any ideas why?  I don't have any other AI Tasks running.  I have 9 readers for 9 tasks and I call each reader one at a time for 1-7 channels (9 SCXI 1125s).
 
Thanks.
Programming Data Acquisition and Control in Measurement Studio and Labwindows/CVI
0 Kudos
Message 1 of 15
(5,438 Views)
Hello,

Is there any way that you could attach your code so as to preseve the formatting? You can only ever have a single DAQmx task running on a single DAQ board at the same time. A task for each module would not work, as each module is scanned by the cabled DAQ device. Instead, you can include all channels for all modules in a single task. If you are attempting to read these tasks sequentially so that there is no resource reservation, then I suspect it has something to do with the device remaining reserved by the driver from a previous task.

Hope this helps,
Ryan Verret
Product Marketing Engineer
Signal Generators
National Instruments
0 Kudos
Message 2 of 15
(5,427 Views)
I can't post the project because my employer is very protective of software.
 
I create a task for each module and thus a reader for each task.  When I read the data I iterate through the readers and store their data in a single array.  It works except for the first 9 seconds that the thread executes.  I do reset the modules...  I only call one task at any given time.  I do my analog reads first and then my ctr/DO/AO writes after.  None of them are being updated at the same time. 
 
I am trying to figure out what is holding them up.  I don't know if it is the hardware or the thread operating at 1 Hz that doesn't allow something to happen.  I get zeros posted to my chart at one second intervals so I know the loop is running at this time, but all of the data is zero.
Programming Data Acquisition and Control in Measurement Studio and Labwindows/CVI
0 Kudos
Message 3 of 15
(5,412 Views)

' Instantiate enough tasks for the number of modules being used.

For TaskCount = 0 To NumberOfModules - 1

Tasks(TaskCount) =

New Task("mod" & Trim(Str(TaskCount + 1)) & "task")

Next

TaskCount = 0

ChannelCount = 0

TasksChannelCount(TaskCount) = 0

Device = "SC1Mod1"

' Create task(s) until all of the channels have been accounted for.

While ChannelCount < numChannels

' Create a task until the current channels device property is equal to that of

' a different SCXI module.

While AIChannels(ChannelCount).Device = Device

TasksChannelCount(TaskCount) += 1

With AIChannels(ChannelCount)

' Input channels are either a voltage channel or a thermocouple channel.

Select Case AIChannels(ChannelCount).Type

Case Is = "Temperature"

Tasks(TaskCount).AIChannels.CreateThermocoupleChannel(.Device & "/" & _

.Channel, Trim(.Name), .Min, .Max, AIThermocoupleType.K, _

AITemperatureUnits.DegreesC)

Tasks(TaskCount).AIChannels(.Name).AutoZeroMode = AIAutoZeroMode.None

Tasks(TaskCount).AIChannels(.Name).LowpassEnable =

True

Tasks(TaskCount).AIChannels(.Name).LowpassCutoffFrequency = 4

Case Is = "Voltage"

Tasks(TaskCount).AIChannels.CreateVoltageChannel(.Device & "/" & .Channel, _

.Name, AITerminalConfiguration.Differential, _

.Min, .Max, AIVoltageUnits.Volts)

Tasks(TaskCount).AIChannels(.Name).AutoZeroMode = AIAutoZeroMode.None

Tasks(TaskCount).AIChannels(.Name).LowpassEnable =

True

Tasks(TaskCount).AIChannels(.Name).LowpassCutoffFrequency = 4

Case Else

MsgBox("Error in channel configuration!", MsgBoxStyle.Critical, "Warning!")

frmD.txtMessage.Text = "Error in Channel Configuration. Abort." & vbNewLine _

& frmD.txtMessage.Text

Exit Sub

End Select

End With

ChannelCount += 1

End While

' Tell the task to take 100 readings of each channel at 10 kS/sec on the rising edge of the clock.

Tasks(TaskCount).Timing.ConfigureSampleClock("", 10000, SampleClockActiveEdge.Rising, _

SampleQuantityMode.FiniteSamples, 100)

Tasks(TaskCount).Control(TaskAction.Verify)

' Create a reader object for this task.

reader(TaskCount) =

New AnalogMultiChannelReader(Tasks(TaskCount).Stream)

TaskCount += 1

TasksChannelCount(TaskCount) = 0

Device = AIChannels(ChannelCount).Device

End While

Programming Data Acquisition and Control in Measurement Studio and Labwindows/CVI
0 Kudos
Message 4 of 15
(5,410 Views)

' Read data reads the voltages or temperatures from each SCXI module. The frequency

' is 1 Hz, and it will read and average 100 readings.

Public Sub ReadData()

Dim g, h, i, Count As Int16

If ChartCount >= 0 Then

Try

g = h = i = 0

For Count = 0 To NumberOfModules - 1

Task1Data = reader(Count).ReadMultiSample(100) 'ERROR HAPPENS HERE

For h = i To i + TasksChannelCount(Count) - 1

sum(h) = 0

Next

For h = i To i + TasksChannelCount(Count) - 1

For g = 0 To 99

sum(h) = sum(h) + Task1Data(h - i, g)

Next

Next

i = h

Next

For h = 0 To numChannels

With AIChannels(h)

average(h) = sum(h) / 100

value(h) = average(h) ^ 4 * .Quartic + _

average(h) ^ 3 * .Cubic + _

average(h) ^ 2 * .Quadratic + _

average(h) * .Linear + _

.Offset

End With

Next

Catch ex As Exception

swError =

New StreamWriter(Application.StartupPath & "\Errors\" & RunNumber & "_" & "Error Log.txt", True)

swError.WriteLine(TimeString & vbTab & "ReadData" & vbNewLine & ex.ToString & vbNewLine & vbNewLine)

swError.Close()

frmD.ledError.Value =

True

End Try

End If

End Sub

Programming Data Acquisition and Control in Measurement Studio and Labwindows/CVI
0 Kudos
Message 5 of 15
(5,408 Views)
Hi,
First a clarification,  you *can* have multiple tasks running on a DAQ board, as long as they don't access the same circuitry on the board. So you can have AI and AO tasks running simultaneously, for example.
 
In your case, are you disposing the task between accessing the various tasks? If you don't dispose the first task, then the task will still be holding on to the boards resources. Which will give you the error that you are getting when you try to invoke task2.
You must call a dispose to release the resources, in between switching tasks.You should have a call like Tasks(TaskCount).Dispose in your code..and i didn't see one.
 
Also you could have the Temperature and  Voltage channels in a single task as long as all of these are AI. But that's a personal preference , and depends on how the rest of the code is organized. Of course if you need AO, then that has to be in a different task.
 
What you are trying to do should work. I suspect its not because you aren't disposing the task that you are finished with.Hope this helps!
Please let me know if it doesnt.
 

 
Nandan Dharwadker
Staff Software Engineer
Measurement Studio Hardware Team
0 Kudos
Message 6 of 15
(5,400 Views)
If I dispose the task will I be able to read data without creating the task again?  What does it have to do with the first 9 seconds of execution?
 
Programming Data Acquisition and Control in Measurement Studio and Labwindows/CVI
0 Kudos
Message 7 of 15
(5,402 Views)

>>>If I dispose the task will I be able to read data without creating the task again?>>>

Actually no it will not. So you will not be able to use this approach if you want to use the tasks in a loop.

Looking more closely at your code, the only reason i see that you will get this error, is if your ReadMultiSample does *not* read all of the points. 

The ConfigureSampleClock is setting up for a 100 point read. You appear to be reading a 100 points. So that seems good. Is there any case in which the data that is read back from the device does *not* read all of the points? Because that would cause this behaviour to occur.

Basically when you Read during a finite acquisition, the hardware resources get reserved (automatically - beneath the hood) , the data is read, and the hardware gets unreserved (automatically). However if the finite read returns without reading all of the points specified by the ConfigureSampleClock (irrespective of what the Read says) then the hardware is not unreserved.

So if you do something like

ConfigureSampleClock(....,...<snip>, 500) and then

myReader.ReadMultiSample(100) ' 500 points not read, so hardware is not unreserved..

myReader2.ReadMultiSample(100) <== Now this read on a different task  will fail because of the reserved resource error.

Is it possible that this could be happenning in your code. Can you check the size of the returned data and make sure that it is always the complete set of points. It appears from the code posted that it should, but its not the entire code, so its possible..

You could also cheat by unreserving the hardware,(mytask.Control(TaskAction.Unreserve) )

 but we should be taking care of the state transitions for you, so if its not working out then we would certainly like to know.

I'll now attach the sample code i used to quickly test this...and to try and simulate what you were doing..

Nandan Dharwadker
Staff Software Engineer
Measurement Studio Hardware Team
0 Kudos
Message 8 of 15
(5,391 Views)
 Dim mytask As Task = New Task("task1")

Dim mytask2 As Task = New Task("task2")

mytask.AIChannels.CreateVoltageChannel(

"Dev1/ai0:1", "", AITerminalConfiguration.Differential, -10.0, 10.0, AIVoltageUnits.Volts)

mytask2.AIChannels.CreateCurrentChannel(

"Dev1/ai2:3", "", AITerminalConfiguration.Differential, 0.0, 0.001, 100, AICurrentUnits.Amps)

mytask.Timing.ConfigureSampleClock(

"", 1000, SampleClockActiveEdge.Rising, _

SampleQuantityMode.FiniteSamples, 1000)

mytask2.Timing.ConfigureSampleClock(

"", 1000, SampleClockActiveEdge.Rising, _

SampleQuantityMode.FiniteSamples, 1000)

mytask.Control(TaskAction.Verify)

mytask2.Control(TaskAction.Verify)

Try

Dim myReader As AnalogMultiChannelReader = New AnalogMultiChannelReader(mytask.Stream)

Dim myReader2 As AnalogMultiChannelReader = New AnalogMultiChannelReader(mytask2.Stream)

Dim readPoints As Double(,) = myReader.ReadMultiSample(10) ' 10 points of a 1000, so next line will generate an exception, if i change this to 1000 it will work fine..

Dim readPoints2 As Double(,) = myReader2.ReadMultiSample(1000)

Catch exp As Exception

MessageBox.Show(exp.Message)

End Try

Nandan Dharwadker
Staff Software Engineer
Measurement Studio Hardware Team
0 Kudos
Message 9 of 15
(5,390 Views)
Why would it "not" read 100 samples from each line like I request?
Programming Data Acquisition and Control in Measurement Studio and Labwindows/CVI
0 Kudos
Message 10 of 15
(5,389 Views)