12-07-2020 01:17 PM
It seems so straight forward and yet I can't figure out why the last statement in this example is taking over 100 ms to execute. The first 4 statements execute in under 5 ms. If I put a loop around the value statement and execute is 10 times, it still takes around 70 ms each. Any suggestions on how to do a single digital input on a single channel faster?
Address = "NIDigitalIOMod1/Port0/Line0"
digitalReadTask = New Task
digitalReadTask.DIChannels.CreateChannel(Address, "DigRead", ChannelLineGrouping.OneChannelForEachLine)
Dim Reader As New DigitalSingleChannelReader(digitalReadTask.Stream)
value = Not Reader.ReadSingleSampleSingleLine()
03-03-2021 02:40 PM
Theoretically speaking, any type of hardware interface that does a "ReadSingleSample" isn't meant for iterative speeds. In my opinion 70ms is pretty fast for a Single read on a Digital Input.
If you want speed, then change your TaskThread and Channel Type to handle Continuous reading and use a Callback, and then when you want the data (probably in some other thread), then you'll need to fetch it from wherever you collect data to (according to your Callback's design). I recommend looking at some of NI's Continuous Read examples.