From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
04-18-2007 01:03 PM
04-19-2007 03:35 PM
04-19-2007 10:09 PM
Joe,
What hardware are you using, and can you please elaborate on ’14 different times’. Does this mean you want to capture one counter 14 different times, a different counter each time for 14 times, etc?
You can find a good shipping example here: C:\Program Files\National Instruments\MeasurementStudioVS2005\DotNET\Examples\DAQmx\Counter\Count Digital Events\CountDigEventsBuffContinuous_ExtClk\vb
The counter data will be put into an array, which is obtained during the function callback of BeginReadSingleSampleDouble(). More information on how the counter data is put into this array can be found in the help file. For the program above, the counter data is obtained and then the callback function is called. Inside that callback function, it reads the counters again and calls itself. This makes it a continuous loop.
04-25-2007 01:39 PM
I have 2 PCI-6602 boards and am using 14 different counters. The problem is that counter 1 through 14 should be tripped in order, but if they are not or if one counter is not tripped at all then i would like to disregard the counter that is not tripped. The program that i have written works if all the counters are tripped. The problem is if one is missed. If one is misssed then the response time of the program is extremly slow and unreliable. I am using the BeginReadSampleDouble method of CounterReader and calling the method EndReadSingleSampleDouble() to receive the data and ends the read. The problem is if one of the counters is not tripped then it never ends the read. So what i do is wait in a loop to until at least one of the 14 counters is tripped and then i wait 2 seconds. *I am not sure what the time is for each counter, but what is do know is that it will not take more than 0.75 second for the last counter to be tripped. So by waiting 2 seconds i should have gotten all of the couters that were tripped, and if any are not tripped then i set the variable pertaining to that counter to -1. After all the counter stopped and read for the times all of the task must be stopped and disposed of. This is were the problem occurs. I a counter is not tripped then when is gets to the routine where the task are stopped and disposed then it seems to lock up or take very long to occur. So what i really need to know is how do i stop a BeginReadSingleSampleDouble or set a time out for it. Below is the code.
04-25-2007 01:41 PM
SaveLabel.Visible =
False TrymeasureButton.Enabled =
False 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 'Clear all times For i = 1 To 14Times(i) = 0
Next 'Create task, configure, and start each task. 1 channel per task For i = 1 To 14TaskNum(i) =
New TaskTaskNum(i).CIChannels.CreateTwoEdgeSeparationChannel(DeviceName(i), _
"", MinTime, MaxTime, CITwoEdgeSeparationFirstEdge.Rising, CITwoEdgeSeparationSecondEdge.Rising, _
CITwoEdgeSeparationUnits.Seconds)
TaskNum(i).Start()
Next i For i = 1 To 14StartRead(TaskNum(i), i)
Next (i) Dim GotSomeTimes As Boolean = False Do Until GotSomeTimesDoEvents()
For i = 1 To 14 If Times(i) <> 0 Then GotSomeTimes = True Next Loop Time1 = Now.SecondDelay = 2
If Time1 >= 60 - Delay Then Time1 = 0 Do Until Now.Second >= Time1 + DelayDoEvents()
Loop 'If a screen is not tripped then return (-1) For i = 1 To 14 If Times(i) = 0 ThenTimes(i) = -1
Dim ReadIn As String End If Next 'display values 'Error Handeling sequence Catch Dim exception As DaqExceptionMessageBox.Show(Exception.Message)
Finally 'this will end all task For i = 1 To 14TaskNum(i).Stop()
TaskNum(i).Dispose()
Next imeasureButton.Enabled =
True End Try End Sub Public Sub StartRead(ByVal t As Task, ByVal i As Integer)counterInReader(i) =
New CounterReader(t.Stream)Dim handle as IAsyncResult
handle = counterInReader(i).BeginReadSingleSampleDouble(AddressOf OnDataReady, i)
End Sub
Public Sub OnDataReady(ByVal x As IAsyncResult) Dim ReadIn As StringReadIn = x.AsyncState
'this is the value of the second parameter for function BeginReadSingleSampleDouble 'This is how the function distinguishes between async. responses.Times(ReadIn) = counterInReader(ReadIn).EndReadSingleSampleDouble(x)
End Sub Sub SetUpArray() End Class04-25-2007 05:42 PM
You can use a timeout in order to prevent the program from waiting a long time until you get a tripped timer. The timeout property is set by getting a Stream object from your Task, and then setting the Timeout property of Stream.
04-27-2007 07:11 AM
David,
Thank you for your help it was useful. It works much better but is inconsistent. Sometimes the program will get stuck on the task.stop if a time is not received, but the task.stream.timeout should have taken care of that. I have a question. The help file says "Gets or sets the amount of time in milliseconds to wait for reads or writes to complete." but it doesn't say when the timeout start to count. Is it when the read starts or when the timeout value is set?
04-30-2007 02:08 PM
Joe,
The counter timeout is started when the BeginReadSingleSampleDouble() is called. One recommended change to your code, I would highly recommend putting the New CounterReader(t.Stream) in the upper while loop, as putting it in the bottom while loop can affect the timing and contribute to the errors you are seeing.
05-02-2007 12:34 PM
David,
Thank you for the info.
Unfortunatley putting the New CounterReader(t.Stream) in the upper while loop did not help. The program is still unpredictable so i went back to just doing a regual real time stream of the task and setting a timeout for the stream. This will allow me to get all of the time if they are good, and if i miss one or more then it will return -1 for the first counter missed and whatever counter is after the first missed counter will also return -1. This way i will atleast know where the first problem occured. I will utilize the program like this for now but i am hoping to be able to get consistent reads by way of asynchronous. The way i am doing this is that i have written a program into a basic stamp chip which spits out 14 different pulses at a know interval. I then feed these pulses into the PCI-6602 boards. I have no problems at all when i read all the times (14) in using the real time read ReadSingleSampleDouble(), but when i use the async. read then sometimes i miss some readings, even when all the times(14) are tripped. This is to inconsistent for me to use so I would like to know if i can contact you or somebody else at National Istruments to talk to over the phone about this problem in more detail.
Thank you
05-02-2007 02:19 PM
Joe,
If you would like phone support, you may call 1-866-IEEE-488 (433-3488). Our sales team will help in getting you the best support for this issue.