From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Trouble with NI USB-6008 counter

Ok so I follwed the example for counters with a slight modification, the exmple has the code in a form and I put mine in a class so I could use it from different forms within my software so my counter functions look like this.

Public Sub StartCount(strChannel As String)
Try
'Create the task
If CountStarted = False Then
myTimer = New Timer
myTimer.Interval = 100
MyTask = New Task()
MyTask.CIChannels.CreateCountEdgesChannel(strMyNIDev & "/" & strChannel, "", CICountEdgesActiveEdge.Falling, 0, CICountEdgesCountDirection.Up)
myCICountReader = New CounterReader(MyTask.Stream)
MyTask.Start()
myTimer.Enabled = True
CountStarted = True
End If
Catch ex As Exception
MyGenProc.ErrorHndl(ex)
MyTask.Dispose()
End Try
End Sub

Public Sub StopCount()
Try
myTimer.Enabled = False
CountStarted = False
MyTask.Stop()
MyTask.Dispose()
MyTask = Nothing
Catch ex As Exception
MyGenProc.ErrorHndl(ex)
CountStarted = False
End Try
End Sub

I call the StartCount from my main form and a timer in the class returns the count to the form, all this works well what I have a problem with is when I stop the count and try to restart it it throughs an error in this location  MyTask.Start() in StartCount about how the object is not set. I will get a more detailed error when I get to work tomorrow as I don't have the equipent on hand at the momoent. Is there something I missing?

 

0 Kudos
Message 1 of 14
(5,023 Views)

That is the all code you have in your class?

 

I don't see declarations for myTask, myTimer, etc.

 

 

0 Kudos
Message 2 of 14
(5,005 Views)

Sorry for that in the declaration section in my code they are defined as such

 

 Private MyTask As Task
 Private WithEvents myTimer As Timer

The problem is not with that it does not work, it works fine until I stop the counter stream and try to restart it, this code is from the examples that NI include adn the only difference is tha my code is in a class and there's was in the form.

 

This is the error I am getting

 

NI Platform Services: The specified resource is reserved. The operation could not be completed as specified.

 

Task Name: _unnamedTask<1E>

 

Status Code: -50103

 

If any more information is need please let me know. And as always thanks in advance for any help and have a great day.

0 Kudos
Message 3 of 14
(4,952 Views)

Perhaps it is better if you post which example you are using.

0 Kudos
Message 4 of 14
(4,948 Views)

Did you want me to upload all the files? I.E. .sou, .vbproj...ect

0 Kudos
Message 5 of 14
(4,945 Views)

No, I mean which NI-installed example are you using?

0 Kudos
Message 6 of 14
(4,943 Views)

Again sorry just trying to make sure I get you what you need, I am using the example located in this file 

 

\National Instruments\NI-DAQ\Examples\DotNET4.5\Counter\Count Digital Events\CountDigEvents\VB\

0 Kudos
Message 7 of 14
(4,937 Views)

I see what they did.

 

Please provide the class you wrote.  I am not sure you felt the need to create your own class.

 

If you have your own class, then you need to be instantiating that class in your form.

 

What is the code for the startButton_Click( ) in your form?

 

0 Kudos
Message 8 of 14
(4,930 Views)

I made a class because this software will be a common software which to launch multiple different software for different equipment. I wanted to create a common software that my user could easily understand how to do thing in each "peice of the pie" and each one could potentially use these class's. So with that said here is how I use it from this peice of the pie.

 

Declaration in main form

 Dim MyDaq As MyNI

when the usuer presses the start button:

MyDaq = New MyNI
MyDaq.GetNIDevices()
MyDaq.SetNIDev("USB-6008")
MyDaq.StartCount("ctr0")

and when the user presses the stop button:

 MyDaq.StopCount()
 MyDaq = Nothing

now I have tried putting the new statement for declaring MyDaq in the Dim statement but it always seems to give me the same error in the afore mention error it's like it's not releasing the USB resource. And sorry for not getting back to this sooner had bigger fish to fry so to speak. Again thank you for and advice and help. Have a great day.

 

0 Kudos
Message 9 of 14
(4,872 Views)

I don't have any such problems with a simulated USB-6008 created in NI-MAX.

I am able to start and stop multiple times.

 

 

0 Kudos
Message 10 of 14
(4,857 Views)