Home > Software > Programming and SDK > Forum > DI-155 Maximum polling speed using ActiveX and Visual Basic 6

DI-155 Maximum polling speed using ActiveX and Visual Basic 6

Dec 30, 2014
Ton ten Haaf wrote
DI-155 What is the Maximum Polling Speed using one channel?

The Dataq DI-155 is to be used to collect voltage values during a short period (perhaps 2 seconds max) as fast as possible.

O.S.: Windows 7 (32 bit) Ultimate
Programming Language: Visual Basic 6.0 SP6

Question 1: Delay
There seems to be a delay of approximately 700 ms between execution of the commands “UltimaSerial.Start” and UltimaSerial.AnalogInput(Ch1)
Why this delay?

Question 2: Polling Speed
The loop containing UltimaSerial.AnalogInput(Ch1) is executed approximately 150000 times in the allotted time. [See sub Timer1 below for applicable script]
The read voltage values, however, are about 7000 time the same and then change, stay exactly the same again for 7000 loops and then change again, etc.
In other words the scripts is not collecting a new value in every loop by executing AnalogInput(Ch1) but in actual fact a new value is read from the DI-155 only every 7000 loops, resulting in an actual polling speed of approximately 20 times per second which is extremely slow and unacceptable.
For obvious reasons the voltage generator generates a continuous changing voltage value for testing purposes.

Is there anything obvious I am doing wrong?

Any advice will be highly appreciated.

Below some snippets from my script.

Setting of DI-155:

Private Sub cmdStart_Click()
lngCounter = 0
UltimaSerial.Device = 155
UltimaSerial.CommPort = 9
UltimaSerial.AcquisitionMode = 0 '0 = NoCondition
UltimaSerial.ChannelCount = 1
UltimaSerial.EventLevel = 20
UltimaSerial.PGain(0) = 20 '+/- 2.5V
UltimaSerial.SampleRate = 240 '240 = Run as fast as possible
sngAvailDataPoints = 0
txtLoopCount.Text = "0"
lngGetTickCountStart = GetTickCount
Timer1.Enabled = TruePrivate Sub Timer1_Timer()
End Sub

During 1000 milliseconds the AnalogInput is polled and the received value stored in variable “sngResult”
A counter is used to count the number of loops is performed during the 1000 milliseconds.

Private Sub Timer1_Timer()
lngWaitTimeStop = GetTickCount
Do Until GetTickCount - lngGetTickCountStart >= 1000 'Read Voltage value during 1 second
sngReading = UltimaSerial.AnalogInput(Ch1) ‘ Collecting the Reading from Channel 0
lngCounter = lngCounter + 1
sngResult(lngCounter) = sngReading
Label1.Caption = sngResult(lngCounter)
sngReading = 0
End Sub

At the end of the specified period the results are stored for further calculations.

Private Sub CmdStop_Click()
sngAvailDataPoints = UltimaSerial.AvailableData
Timer1.Enabled = False
txtLoopCount.Text = Str(lngCounter)
txtDataPoints.Text = Str(sngAvailDataPoints)
'Save Received Results in a text file and check how many new results received
Open "C:\ath_dev\Dataq.txt" For Output As #1
Close #1
sngDifferenceCounter = 0
sngNewValue = 0
Open "C:\ath_dev\Dataq.txt" For Append As #1
For sngWrite = 1 To (lngCounter - 1)
Print #1, Str(sngWrite); " ; "; Str(sngResult(sngWrite))
If sngResult(sngWrite) < sngNewValue Or sngResult(sngWrite) > sngNewValue Then
sngNewValue = sngResult(sngWrite)
sngDifferenceCounter = sngDifferenceCounter + 1
End If
Next sngWrite
Close #1

lblNewValueCount.Caption = Str(sngDifferenceCounter)

'Show time taken (in ms) between activating the Start button and actual receiving the
first result from the DI-155
lblWaitTime.Caption = Str(lngWaitTimeStop - lngWaitTimeStart)
End Sub
3 Answers
Dec 30, 2014
Ken agent wrote
The .SampleRate maximum value for the DI-155 with one channel enabled is 10000. Instead of using the .AnalogInput method to poll random samples, sampling fast with data continuity requires using the .GetData or .GetDataEx method inside an UltimaSerial_NewData event handler. On www.ultimaserial.com/standard.html see the GetData example. With a single channel, you can plot the data directly from Variant V without declaring Channel1 or extracting data to it.
Jan 03, 2015
Ton ten Haaf wrote
Thanks for the ply.

I changed the script to use .GetData however seem to collect only approximately 200 samples per second.
This a far cry from 10000.

It would be appreciated if you could suggest an improvement in script to speed the scanning process.

Attached please find the result file.

Private Sub Form_Load()

Dim strReceived As String
'For DI-148/158/710 series support, please visit www.ultimaserial.com first
List1.AddItem "155"
Combo1.AddItem "9"
End Sub

Private Sub Command1_Click()
UltimaSerial.Device = 155
UltimaSerial.CommPort = 9

UltimaSerial.AcquisitionMode = NoCondition
UltimaSerial.ChannelCount = 1
'To config channels, please visit www.ultimaserial.com

UltimaSerial.SampleRate = 240
UltimaSerial.EventLevel = 400 '2 'Chart it when we have 2 or more points.
UltimaSerial.PGain(0) = 5 'Gain 5 = +/- 10V, Gain 10= +/- 5V, Gain 20= +/- 2.5V
Open "c:\ath_dev\Dataq_155_Scan_Test.txt" For Output As #1
Label4.Caption = "Serial Number: " + UltimaSerial.SerialNumber
'Text3.Text = UltimaSerial.SampleRate
lngBeginCycle = GetTickCount
End Sub

Private Sub UltimaSerial_NewData(ByVal Count As Integer)

v = UltimaSerial.GetData() 'Get data
strReceived = ""

cn = UBound(v, 1) 'cn = number of channel -1
pts = UBound(v, 2) 'pts = number of data -1

ReDim channel1(0, 0 To pts) As Integer
'create an array to accept channel1

For i = 0 To pts
channel1(0, i) = v(0, i) 'Extract channel 1 from V
'Save received data
For i = 0 To pts
strReceived = strReceived + Trim(Str(channel1(0, i))) + " ; "
Print #1, strReceived, Str(pts), Str(GetTickCount - lngBeginCycle)
'End cycle after x seconds
lngEndTime = GetTickCount
If lngEndTime - lngBeginCycle > 10000 Then
End If
End Sub

Private Sub Command2_Click()
Close #1
End Sub

Jan 03, 2015
Ken agent wrote
To sample faster than 240 samples/sec, use:
UltimaSerial.SampleRate = 10000

With "UltimaSerial.EventLevel = 400", the NewData event will then fire about every 40 ms.