09-05-2008 12:10 PM
I've found a strange situation while using the NI-Motion driver in VB 6.0. It appears that running Windows Media Player reduces the time it takes to make calls to the NI-Motion driver. I wrote a sample program to demonstrate this. This program calls a NI-Motion function (flex_enable_limits) 3000 times and measures how long this process takes. If I run this program after booting up my computer, it takes about 24 seconds to complete the 3000 calls. Then I open Windows Media Player 11 and close it. The same program takes 6 seconds to run (1/4 of the time) after running WMP.
I am running this on a Pentium 4 processor with Windows XP. I am using NI-Motion 7.6 with Visual Basic 6.0.
What is WMP doing to speed up calls to the NI-Motion driver?
The sample program:
Option Explicit
Declare Function flex_enable_limits Lib "FlexMotion32.dll" (ByVal boardID%, ByVal limitType%, ByVal forwardLimitMap%, ByVal reverseLimitMap%) As Long
Public Sub Main()
Dim ErrVal As Long
Dim StartTimer As Single
Dim LoopIdx As Long
Dim Var1 As Long
' This is a simple calculation loop used to make sure Windows isn't doing anything to slow down the program
DoEvents
StartTimer = Timer
For LoopIdx = 1 To 300000000
Var1 = Var1 + 1
Next LoopIdx
Debug.Print "Calc Loop Time = " & CStr(Timer - StartTimer) & " seconds"
' On my computer, this section takes 24 seconds before running WMP and takes 6 seconds after running WMP
DoEvents
StartTimer = Timer
For LoopIdx = 1 To 3000
ErrVal = flex_enable_limits(1, 0, 0, 6)
Next LoopIdx
Debug.Print "NI-Motion Loop Time = " & CStr(Timer - StartTimer) & " seconds"
Debug.Print "------------------------"
End Sub
09-08-2008 05:04 PM
09-09-2008 11:52 AM
Here is the link to the project files.
The results seem very repeatable to me. I have tried this on two different systems (a Dell Pentium 4 desktop and an Advantech Dual Core industrial PC) and I am seeing similar results.
I tried running the program 3 times after rebooting. The calculation loop took 4.4 seconds, 4.5 seconds, and 4.4 seconds for each try. The loop that call the NI-Motion driver took 23.6 seconds, 23.3 seconds, and 23.3 seconds on each try.
Next I opened Windows Media Player and left it open for a few seconds while it started up. Then I closed Windows Media Player and tried the program again.
After running Windows Media Player, the calculation loop had no change in times as I would expect. The calculation loop took 4.5 seconds on all 3 tries. However, the loop that calls the NI-Motion driver now only took 6.1 seconds, 5.8 seconds, and 5.9 seconds for each try. This loop is running 4 times faster after running Windows Media Player.
09-10-2008 06:34 PM
Hi chvogt,
When I run the code it gets to displaying the loop calculation time, but then gets stuck and never makes it to the NI Motion call time. Can you tell what needs to be changed to fix this?
09-11-2008 08:52 AM
The time it takes to do each loop is arbitrary depending on the speed of your PC. You can reduce the number of loops to reduce the amount of time you wait.
My original sample program timed how long it took to perform a fixed number of iterations. The problem with this method is you don't know how long it will take to run through each loop until you run the program. So I changed my method and made a new program that counts how many loops can be completed in a fixed amount of time. This way you will know how long to wait for each loop to finish. In the new program, you specify the duration to run each loop and the program counts how many loop iterations it can perform in the specified amount of time. I also dressed this up a little with a simple user interface.
You can download the new test program from here
Be sure to check out the 'Read Me' PDF for additional information.
09-12-2008 11:00 AM
09-15-2008 06:24 AM
So far I have only encountered this issue while using a PCI-7344 board. I tried this test on a virtual PCI-7344 board created in NI-MAX but it doesn't behave any differently after running WMP.
I have tried different PCI-7344 boards in different computers and they all run the test program faster after running WMP.
09-16-2008 02:18 PM
09-17-2008 08:44 AM
I understand the problems that can come up while running applications in Windows. However, if Windows was doing something that would vary the speed of the loops, I would expect to see it affect both the calculation and the NI-Motion loops. It's true that the computer is doing different things when making a call to NI-Motion versus just adding up some numbers but what really doesn't make sense to me is that running WMP makes the test program run faster not slower (at least on the computers I've checked). Also, it's not just a little faster, it is 4 times faster. Most of the problems I've encountered with Windows is that things start to slow down when you start running more processes, not speed up.
Some more info:
I appreciate the attention that you have been giving to this issue and I will continue to see if I can come up with a way to reproduce this on your system.
09-17-2008 11:44 AM
David
I might have found the reason why you aren't able to reproduce the problem with the test program. It appears that Internet Explorer also speeds up the NI-Motion loop. I rebooted my PC and tried the test program. The NI-Motion loops run at 128 loops/sec consistently. I then started Internet Explorer instead of WMP, let it run for a few seconds and closed it. Now the NI-Motion loops are running at about 1020 loops/sec which is the same speed you were reporting. Note that the speed increase after running WMP is about 4x faster (510 loops/sec) but it is about 8x faster after running IE (1020 loops/sec).
I have verified this on 2 different PCs with 2 different PCI-7344 and the results are repeatable. However, I found that you need to actually be connected to the Internet for this to work. If I run Internet Explorer on a PC that doesn't have an internet connection, there is no change in the time and the loop still runs at 128 loops/sec.