09-17-2015 08:02 PM
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?
09-18-2015 08:16 AM
That is the all code you have in your class?
I don't see declarations for myTask, myTimer, etc.
09-21-2015 01:38 PM
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.
09-21-2015 01:53 PM
Perhaps it is better if you post which example you are using.
09-21-2015 02:11 PM
Did you want me to upload all the files? I.E. .sou, .vbproj...ect
09-21-2015 02:16 PM
No, I mean which NI-installed example are you using?
09-21-2015 03:26 PM
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\
09-21-2015 03:43 PM - edited 09-21-2015 03:45 PM
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?
09-26-2015 09:46 AM
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.
09-27-2015 11:48 AM
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.