Пример #1
0
        public void Stop()
        {
            if (disposed)
            {
                throw new ObjectDisposedException(GetType().Name);
            }

            started = false;

            protocolTimer.Change(Timeout.Infinite, Timeout.Infinite);

            if (engineMutex.WaitOne())
            {
                try
                {
                    if (appPortMutex.WaitOne())
                    {
                        try
                        {
                            outputThread.Abort();
                            outputThread = null;

                            appPort.Close();
                            appPort.Dispose();
                            appPort = null;

                            engine = null;
                        }
                        finally
                        {
                            appPortMutex.ReleaseMutex();
                        }
                    }
                    else
                    {
                        throw new Exception("Failed to lock application port mutex");
                    }
                }
                finally
                {
                    engineMutex.ReleaseMutex();
                }
            }
            else
            {
                throw new Exception("Failed to lock protocol engine mutex");
            }
        }
Пример #2
0
        protected void Dispose(bool disposing)
        {
            if (!disposed)
            {
                if (disposing)
                {
                    if (started)
                    {
                        Stop();
                    }
                    protocolTimer.Dispose();
                }

                application  = null;
                config       = null;
                engine       = null;
                appPort      = null;
                outputThread = null;

                disposed = true;
            }
        }
Пример #3
0
        public void Start()
        {
            if (disposed)
            {
                throw new ObjectDisposedException(GetType().Name);
            }

            if (engineMutex.WaitOne())
            {
                try
                {
                    if (appPortMutex.WaitOne())
                    {
                        try
                        {
                            try
                            {
                                engine = new GarminProtocolEngine((short)((int)settings["gpsProductId"].Value),
                                                                  (short)((int)settings["gpsSoftwareVersion"].Value),
                                                                  (string)settings["gpsProductDescription"].Value,
                                                                  (uint)((long)settings["gpsUnitId"].Value), (int)settings["snrMin"].Value,
                                                                  (int)settings["snrMax"].Value);

                                appPort        = application.GetPort(this, (string)settings["appPort"].Value);
                                appPort.Read  += new PortReadEvent(appPort_Read);
                                appPort.Error += new PortErrorEvent(appPort_Error);
                                appPort.Open();

                                outputThread          = new EventThread(new EventThreadCallback(OutputThreadCallback));
                                outputThread.Priority = ThreadPriority.Normal;
                                outputThread.Start();

                                protocolTimer.Change(0, 1000);
                            }
                            catch
                            {
                                protocolTimer.Change(Timeout.Infinite, Timeout.Infinite);
                                if (outputThread != null)
                                {
                                    outputThread.Abort();
                                    outputThread = null;
                                }
                                if (appPort != null)
                                {
                                    appPort.Close();
                                    appPort.Dispose();
                                    appPort = null;
                                }
                                engine = null;
                                throw;
                            }
                        }
                        finally
                        {
                            appPortMutex.ReleaseMutex();
                        }
                    }
                    else
                    {
                        throw new Exception("Failed to lock application port mutex");
                    }
                }
                finally
                {
                    engineMutex.ReleaseMutex();
                }
            }
            else
            {
                throw new Exception("Failed to lock protocol engine mutex");
            }

            started = true;
        }
		public void Stop()
		{
			if (disposed)
				throw new ObjectDisposedException(GetType().Name);

			started = false;

			protocolTimer.Change(Timeout.Infinite, Timeout.Infinite);

			if (engineMutex.WaitOne())
			{
				try
				{
					if (appPortMutex.WaitOne())
					{
						try
						{
							outputThread.Abort();
							outputThread = null;

							appPort.Close();
							appPort.Dispose();
							appPort = null;

							engine = null;
						}
						finally
						{
							appPortMutex.ReleaseMutex();
						}
					}
					else 
						throw new Exception("Failed to lock application port mutex");
				}
				finally
				{
					engineMutex.ReleaseMutex();
				}
			}
			else
				throw new Exception("Failed to lock protocol engine mutex");
		}
		public void Start()
		{
			if (disposed)
				throw new ObjectDisposedException(GetType().Name);

			if (engineMutex.WaitOne())
			{
				try
				{
					if (appPortMutex.WaitOne())
					{
						try 
						{
							try 
							{
								engine = new GarminProtocolEngine((short)((int)settings["gpsProductId"].Value),
									(short)((int)settings["gpsSoftwareVersion"].Value),
									(string)settings["gpsProductDescription"].Value,
									(uint)((long)settings["gpsUnitId"].Value), (int)settings["snrMin"].Value,
									(int)settings["snrMax"].Value);

								appPort = application.GetPort(this, (string)settings["appPort"].Value);
								appPort.Read += new PortReadEvent(appPort_Read);
								appPort.Error += new PortErrorEvent(appPort_Error);
								appPort.Open();

								outputThread = new EventThread(new EventThreadCallback(OutputThreadCallback));
								outputThread.Priority = ThreadPriority.Normal;
								outputThread.Start();

								protocolTimer.Change(0, 1000);
							}
							catch
							{
								protocolTimer.Change(Timeout.Infinite, Timeout.Infinite);
								if (outputThread != null)
								{
									outputThread.Abort();
									outputThread = null;
								}
								if (appPort != null)
								{
									appPort.Close();
									appPort.Dispose();
									appPort = null;
								}
								engine = null;
								throw;
							}
						}
						finally
						{
							appPortMutex.ReleaseMutex();
						}
					}
					else
						throw new Exception("Failed to lock application port mutex");
				}
				finally
				{
					engineMutex.ReleaseMutex();
				}
			}
			else
				throw new Exception("Failed to lock protocol engine mutex");

			started = true;
		}
		protected void Dispose(bool disposing)
		{
			if (! disposed)
			{
				if (disposing)
				{
					if (started)
						Stop();
					protocolTimer.Dispose();
				}

				application = null;
				config = null;
				engine = null;
				appPort = null;
				outputThread = null;

				disposed = true;
			}
		}