ADC40 with USB Parallel Port Adapter causes system slowdown

Post general discussions on using our drivers to write your own software here
Post Reply
OliverDaniell
User
User
Posts: 4
Joined: Thu Feb 02, 2006 8:26 am

ADC40 with USB Parallel Port Adapter causes system slowdown

Post by OliverDaniell »

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

		/// 
		/// Stores the port that the software connects to
		/// 
		private int port;

		/// 
		/// myTimer is used to take readings from the HS10 at regular intervals
		/// 
		Timer myTimer;
		
		/// 
		/// myAverage is used to return a smoother output from the raw laser data.
		/// 
		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
		/// 
		/// Create new timer event and set Averager buffer size to 4
		/// 
		public HS10()
		{
			myTimer = new Timer(DefaultTimerLength);
			myTimer.Enabled = false;
			myTimer.Elapsed += new System.Timers.ElapsedEventHandler(myTimer_Elapsed);
			myAverage = new Averager();
		}
		#region ILaser Members

		/// 
		/// Connect to the HS10
		/// 
		/// Connected = true, Connection error = false
		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;
		}
		
		/// 
		/// Disconnect from the HS10
		/// 
		public void Disconnect()
		{
			myTimer.Enabled = false;
			adc10_close_unit(port);
		}

		/// 
		/// LaserUpdated events are fired when new data is recieved from the Laser
		/// 
		public event LaserUpdatedHandler LaserUpdated;
		/// 
		/// Takes reading from the HS10 and fires a LaserUpdated event
		/// 
		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

Post by OliverDaniell »

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

Post by OliverDaniell »

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

Post by OliverDaniell »

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

Post Reply