Test and Measurement Forum

ADC40 with USB Parallel Port Adapter causes system slowdown

Post general discussions on using our drivers to write your own software here

ADC40 with USB Parallel Port Adapter causes system slowdown

Postby OliverDaniell » Thu Feb 02, 2006 8:48 am

I have been using an ADC40 with a Pico USB to Parallel Port Adapter for about 2 months to monitor the voltage output from a device. The device is used infrequently, every few weeks, and has worked without problems since my software was installed.

However in the last 2 weeks i have noticed strange behaviour when using the ADC40 with the USB adapter. The system processor usage starts at arround 40% and steadily climbs, over about 1 minute, to 100% making the system and software unusable.

When i disconnect the ADC40 from the USB adapter and plug it straight into the parallel port its behaviour returns to normal, and my software runs with less than 10% processor usage.

I think i am running the latest drivers, however as you do not include the version number on the driver this is very hard to verify. I am instead finding the version number by looking at the help file included, version 1.2. In your reply it would be best to assume i am running the latest drivers. In any case i will be downloading and installing these immediately after my post and i will post a reply within the next 30 minutes if that has helped.


Code: Select all
using System;
using System.Timers;
using System.Runtime.InteropServices;
using System.Diagnostics;
namespace Renishaw.Linear
{
   /// <summary>
   /// HS10 contains the methods to communicate with the HS10 laser
   /// </summary>
   public class HS10 : ILaser
   {
      #region Constants
      /// <summary>
      /// defaultTimerLength is the ammount of time to wait before firing a timer event
      /// </summary>
      private const int DefaultTimerLength = 1;
      /// <summary>
      /// usbPort is the port to which the USB ADC is connected
      /// </summary>
      private const int UsbPort = 101;
      /// <summary>
      /// parallelPort is the port to which the parallel ADC is connected
      /// </summary>
      private const int ParallelPort = 1;
      /// <summary>
      /// product is the product code for the ADC40
      /// </summary>
      private const int Product = 40;
      /// <summary>
      /// Scales the 0 - 128 signal from the ADC too - 32
      /// </summary>
      private const double Rescale = 0.25;
      /// <summary>
      /// The voltage that indicates max signal strength
      /// </summary>
      private const double MaxSignalStrength = 4.5;
      /// <summary>
      /// The highest voltage that the ADC can read
      /// </summary>
      private const double MaxVoltage = 5;
      /// <summary>
      /// Subtracting this value from the Adc Value will set an adc reading of OV to 0 in the software
      /// </summary>
      private const int ADCValueToZero = 128;
      #endregion
      #region Fields

      /// <summary>
      /// Stores the port that the software connects to
      /// </summary>
      private int port;

      /// <summary>
      /// myTimer is used to take readings from the HS10 at regular intervals
      /// </summary>
      Timer myTimer;
      
      /// <summary>
      /// myAverage is used to return a smoother output from the raw laser data.
      /// </summary>
      private Averager myAverage;
      #endregion
      #region Dll Imports
      [DllImport("adc1032.dll",CharSet=CharSet.Auto,
          CallingConvention=CallingConvention.StdCall)]
      static extern int adc10_open_unit(int port, int product);

      [DllImport("adc1032.dll",CharSet=CharSet.Auto,
          CallingConvention=CallingConvention.StdCall)]
      static extern int adc10_set_unit(int port);

      [DllImport("adc1032.dll",CharSet=CharSet.Auto,
          CallingConvention=CallingConvention.StdCall)]
      static extern int adc10_close_unit(int port);

      [DllImport("adc1032.dll",CharSet=CharSet.Auto,
          CallingConvention=CallingConvention.StdCall)]
      static extern short adc10_get_value();

      #endregion
      /// <summary>
      /// Create new timer event and set Averager buffer size to 4
      /// </summary>
      public HS10()
      {
         myTimer = new Timer(DefaultTimerLength);
         myTimer.Enabled = false;
         myTimer.Elapsed += new System.Timers.ElapsedEventHandler(myTimer_Elapsed);
         myAverage = new Averager();
      }
      #region ILaser Members

      /// <summary>
      /// Connect to the HS10
      /// </summary>
      /// <returns>Connected = true, Connection error = false</returns>
      public bool Connect()
      {
         bool retVal = false;
         adc10_open_unit(ParallelPort,Product);
         adc10_open_unit(UsbPort,Product);
            if (adc10_set_unit(UsbPort) == 1)
            {
               port = UsbPort;
               myTimer.Enabled = true;
               retVal = true;
            }
            else
            {
               if (adc10_set_unit(ParallelPort) == 1)
               {
                  port = ParallelPort;
                  myTimer.Enabled = true;
                  retVal = true;
               }
               else
               {
                  retVal = false;
               }
            }
         
         return retVal;
      }
      
      /// <summary>
      /// Disconnect from the HS10
      /// </summary>
      public void Disconnect()
      {
         myTimer.Enabled = false;
         adc10_close_unit(port);
      }

      /// <summary>
      /// LaserUpdated events are fired when new data is recieved from the Laser
      /// </summary>
      public event LaserUpdatedHandler LaserUpdated;
      /// <summary>
      /// Takes reading from the HS10 and fires a LaserUpdated event
      /// </summary>
      private void myTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
      {
         if (myTimer.Enabled)
         {

            int temp = 0;
            try
            {
               temp = adc10_get_value();
            }
            catch
            {
               System.Diagnostics.Debug.WriteLine("Error with ADC 40");
            }
            temp = System.Convert.ToInt32((temp - ADCValueToZero) * Rescale/MaxSignalStrength*MaxVoltage);
            LaserUpdated(this,new LaserUpdatedEventArgs(temp));
         }
      }

      #endregion

      
   }
}


I have included my C# code sample above.

Thanks in advance for any help you can give
OliverDaniell
User
User
 
Posts: 4
Joined: Thu Feb 02, 2006 8:26 am

Postby OliverDaniell » Thu Feb 02, 2006 9:12 am

Hi
The latest drivers have now been installed the problem remains the same.

The memory usage also increases as the program is left running. From my understanding .net should not allow memory leaks so could this indicate a memory leak in your drivers?

I should also add that i am certain the problem occurs within the code module i have submitted. I have various other devices implemeting the ILaser interface and these all run without any problems.
OliverDaniell
User
User
 
Posts: 4
Joined: Thu Feb 02, 2006 8:26 am

Postby OliverDaniell » Thu Feb 02, 2006 10:56 am

Ok so i have done a bit more debugging and just connecting to the ADC40 through the usb port
Code: Select all
adc10_open_unit(UsbPort,Product);
shoots the processor usage straight up to 50%. Thats without polling the device for information.
OliverDaniell
User
User
 
Posts: 4
Joined: Thu Feb 02, 2006 8:26 am

Postby OliverDaniell » Thu Feb 02, 2006 11:21 am

In response to our phone conversation here is a free compiler and debugger from microsoft that will be capable of running my code
http://msdn.microsoft.com/vstudio/expre ... fault.aspx
OliverDaniell
User
User
 
Posts: 4
Joined: Thu Feb 02, 2006 8:26 am


Return to General Software Discussions

Who is online

Users browsing this forum: No registered users and 0 guests