Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

How to set time out for counterInReader function

I have written a program in VB.net to caputer 14 concatinated times and would like to know how to set a specific time for the counterInReader function.  I wrote the same program in VB6.0 and used   DAQmxErrChk (DAQmxReadCounterScalarF64(TaskHandleArray(i), InitialTimeOut, ReadTime(i), ByVal 0&)), were InitilaTimeOut = -1, this would cause the read function to wait until the forst counter timers returned a value.  I would like to know if there is a function in VB.net that will allow me to set a specific wait time for the counter read.  Because i would like to be able to vary the wait time for different measurements.  Thnak you.  
   
0 Kudos
Message 1 of 5
(4,607 Views)
Hi,

Could you give me a little more information on your application please.  What kind of signal are you measuring on your counter and what are you measuring?  Are you measuring a frequency, or period or something else?  Also, are you using some kind of trigger that is causing the wait? Are you using Measurement Studio with VB.NET?

Thank you,
Raajit L
National Instruments
0 Kudos
Message 2 of 5
(4,566 Views)
Hi,

Could you give me a little more information on your application please.  What kind of signal are you measuring on your counter and what are you measuring?  Are you measuring a frequency, or period or something else?  Also, are you using some kind of trigger that is causing the wait? Are you using Measurement Studio with VB.NET?

Thank you,

Raajit L
Applications Engineering
National Instruments

I am measuring events that happen randomly that transiton from 0 to 5V.  Yes i am using Measument Studios with VB.net.  The first event starts 14 counter at once.  When an event occurs, such as an object passing a light screen the first counter will stop, then when another events occurs (lightscreen interupted again) then the second counter will stop, all the way until all 14 lightsceens are tripped. I wrote a program in VB6.0 and was able to use  the function DAQmxErrChk (DAQmxReadCounterScalarF64(TaskHandleArray(i), InitialTimeOut, ReadTime(i), ByVal 0&), (**were the value for InitilaTimeOut = -1, this means wait forever) to be able to set how long the counter timer board would wait for the first lightscreen to be tripped.  Now I have programed the counter timer board in VB.net and there are no arguments in the function were i am able to set a wait time.  The way i do this in the program is to create 14 task and then start all 14 task and then wait for the functions  "counterInReader(i) = New CounterReader(TaskNum(i).Stream),  Dim data As Double = counterInReader(i).ReadSingleSampleDouble(), Times(i) = data"  to read the times.  Below is the code. I would like to be able to get all 14 times and if one is missed (a lightscreen is not tripped for whatever reason) i would still like to get the other times. Currently this is not the case, if one lightscreen is not tripped then the program give the error "Specified operation did not complete, because the specified timeout expired." "Task Name: _unnamedTask<15>" "Status Code: -200474". 

Public

Sub CounterTimes()

Try

'This will craete an internal route between terminals thru the RTSI bus

DaqSystem.Local.ConnectTerminals("/Dev2/PFI37", "/Dev2/PFI33")

DaqSystem.Local.ConnectTerminals("/Dev2/PFI37", "/Dev2/PFI29")

DaqSystem.Local.ConnectTerminals("/Dev2/PFI37", "/Dev2/PFI25")

DaqSystem.Local.ConnectTerminals("/Dev2/PFI37", "/Dev2/PFI21")

DaqSystem.Local.ConnectTerminals("/Dev2/PFI37", "/Dev2/PFI17")

DaqSystem.Local.ConnectTerminals("/Dev2/PFI37", "/Dev2/PFI13")

DaqSystem.Local.ConnectTerminals("/Dev2/PFI37", "/Dev2/PFI9")

DaqSystem.Local.ConnectTerminals("/Dev3/PFI37", "/Dev3/PFI33")

DaqSystem.Local.ConnectTerminals("/Dev3/PFI37", "/Dev3/PFI29")

DaqSystem.Local.ConnectTerminals("/Dev3/PFI37", "/Dev3/PFI25")

DaqSystem.Local.ConnectTerminals("/Dev3/PFI37", "/Dev3/PFI21")

DaqSystem.Local.ConnectTerminals("/Dev3/PFI37", "/Dev3/PFI17")

DaqSystem.Local.ConnectTerminals("/Dev3/PFI37", "/Dev3/PFI13")

DaqSystem.Local.ConnectTerminals("/Dev3/PFI37", "/Dev3/PFI9")

'setup counter names

Call SetUpArray()

'setup timing parameters

Dim MinTime As Double = 0.000001 'this is the minimum time to count

Dim MaxTime As Double = 2 'this is the maximum time to wait for a signal

'Create task, configure, and start each task. 1 channel per task

For i = 1 To 14

TaskNum(i) =

New Task

TaskNum(i).CIChannels.CreateTwoEdgeSeparationChannel(DeviceName(i), _

"", MinTime, MaxTime, CITwoEdgeSeparationFirstEdge.Rising, CITwoEdgeSeparationSecondEdge.Rising, _

CITwoEdgeSeparationUnits.Seconds)

TaskNum(i).Start()

Next i

'Read in times

'The way this is set up is that if a counter isn't tripped then

'an error will occur

For i = 1 To 14

counterInReader(i) =

New CounterReader(TaskNum(i).Stream)

Dim data As Double = counterInReader(i).ReadSingleSampleDouble()

Times(i) = data

' Times(i) = counterInReader(i).ReadSingleSampleDouble()

Next (i)

 

'Error Handeling sequence

Catch exception As DaqException

MessageBox.Show(exception.Message)

Finally

'this will end all task

For i = 1 To 14

TaskNum(i).Stop()

TaskNum(i).Dispose()

Next i

'This will disconnect the internal route between terminals

DaqSystem.Local.DisconnectTerminals("/Dev2/PFI37", "/Dev2/PFI33")

DaqSystem.Local.DisconnectTerminals("/Dev2/PFI37", "/Dev2/PFI29")

DaqSystem.Local.DisconnectTerminals("/Dev2/PFI37", "/Dev2/PFI25")

DaqSystem.Local.DisconnectTerminals("/Dev2/PFI37", "/Dev2/PFI21")

DaqSystem.Local.DisconnectTerminals("/Dev2/PFI37", "/Dev2/PFI17")

DaqSystem.Local.DisconnectTerminals("/Dev2/PFI37", "/Dev2/PFI13")

DaqSystem.Local.DisconnectTerminals("/Dev2/PFI37", "/Dev2/PFI9")

DaqSystem.Local.DisconnectTerminals("/Dev3/PFI37", "/Dev3/PFI33")

DaqSystem.Local.DisconnectTerminals("/Dev3/PFI37", "/Dev3/PFI29")

DaqSystem.Local.DisconnectTerminals("/Dev3/PFI37", "/Dev3/PFI25")

DaqSystem.Local.DisconnectTerminals("/Dev3/PFI37", "/Dev3/PFI21")

DaqSystem.Local.DisconnectTerminals("/Dev3/PFI37", "/Dev3/PFI17")

DaqSystem.Local.DisconnectTerminals("/Dev3/PFI37", "/Dev3/PFI13")

DaqSystem.Local.DisconnectTerminals("/Dev3/PFI37", "/Dev3/PFI9")

End Try

      End Class 

 

 

 

0 Kudos
Message 3 of 5
(4,551 Views)
Hi,

Would you be able to just ignore the error?  You could then pass over the read that is not occuring for whatever reason onto the others.  The main problem with this is obviously now you will be ignoring that error if it might be important later on in your application.  It seems like with the MessageBox.show line you are making this bring the error.

In case we need to communicate further.  What happened in the VB6.0 application if you did not trip one of the sensors.   It seems like you would have gotten an error there as well.  I am just trying to understand if we are trying to recreate the behavior from VB 6 or looking to develop a new application with a different end use in VB.NET.

Let me know how I can further help and I will see if there is an example doing this, but this is a pretty unique use case so there might not be any pre built code to find.  I am still trying to understand what the counter is doing for you as opposed to simply using a DIO line, but I am sure there is a reason.

Have a great day,

Michael D
Applications Engineering
National Instruments
0 Kudos
Message 4 of 5
(4,526 Views)

Hi,

Would you be able to just ignore the error?  You could then pass over the read that is not occuring for whatever reason onto the others.  The main problem with this is obviously now you will be ignoring that error if it might be important later on in your application.  It seems like with the MessageBox.show line you are making this bring the error.

In case we need to communicate further.  What happened in the VB6.0 application if you did not trip one of the sensors.   It seems like you would have gotten an error there as well.  I am just trying to understand if we are trying to recreate the behavior from VB 6 or looking to develop a new application with a different end use in VB.NET.

Let me know how I can further help and I will see if there is an example doing this, but this is a pretty unique use case so there might not be any pre built code to find.  I am still trying to understand what the counter is doing for you as opposed to simply using a DIO line, but I am sure there is a reason.

Have a great day,

Michael D
Applications Engineering
National Instruments

In VB6.0 if it did not trip one of the sensors then it also gave an error, so in that regard it is the same as the VB.net.  The only difference between the VB6.0 and VB.net is that in the VB6.0 i could set a time for each read to wait for the read to occur and if the time surpassed the wait time then it would result in an error.

Maybe i should start by simplifying this and tell you what i am trying to do and then tell you what i have tried to do.   

I am shooting a ball through 15 light screens and each light screen is connected to a counter timer the first light screen starts all of the counter timer and then each light screen is tripped which will then stop each counter timer and result in a time for each counter.  So in order to do this i needed to create 14 "tasks", 1 for each timer being used.  The problem is if i go to read the times and if one light screen is not tripped for whatever reason whether it be an electronic issue or some other issue then i would like to keep the times for the other light screens that were good and return (lets say 0 for the bad times) so this can then be used as a diagnostics tool.  

The problem is that i don't know exactly how the read functions work.  What I would like to do is shoot the ball through all the light screens and then after i know that the ball have finished going through all the screens then conduct a read but i don't know if the times are stored somewhere for each counter timer or of i have to read them as they occur, which i currently do.  And the only reason why i did it this way was because that is how all the VB.net examples did it.    

0 Kudos
Message 5 of 5
(4,509 Views)