Exemplo n.º 1
0
        public void Start()
        {
            if (disposed)
            {
                throw new ObjectDisposedException(GetType().Name);
            }

            try
            {
                engine = new NMEAProtocolEngine((double)settings["movement_threshold"].Value);
                if ((bool)settings["mirror"].Value)
                {
                    out_port        = application.GetPort(this, (string)settings["out_port"].Value);
                    out_port.Read  += new PortReadEvent(out_port_Read);
                    out_port.Error += new PortErrorEvent(out_port_Error);
                    out_port.Open();
                }
                in_port        = application.GetPort(this, (string)settings["in_port"].Value);
                in_port.Read  += new PortReadEvent(in_port_Read);
                in_port.Error += new PortErrorEvent(in_port_Error);
                bool bSucc = in_port.Open();
                if (!bSucc)
                {
                    application.LogMessage(this, "Error: Failed to open input port");
                }
            }
            catch
            {
                engine = null;
                if (in_port != null)
                {
                    in_port.Close();
                    in_port.Dispose();
                    in_port = null;
                }
                if (out_port != null)
                {
                    out_port.Close();
                    out_port.Dispose();
                    out_port = null;
                }
                throw;
            }
        }
Exemplo n.º 2
0
        public void Start()
        {
            if (disposed)
            {
                throw new ObjectDisposedException(GetType().Name);
            }

            try
            {
                if (in_port != null)
                {
                    in_port.Read  += new PortReadEvent(in_port_Read);
                    in_port.Error += new PortErrorEvent(in_port_Error);
                    in_port.Open();
                }

                if (out_port != null)
                {
                    out_port.Read  += new PortReadEvent(out_port_Read);
                    out_port.Error += new PortErrorEvent(out_port_Error);
                    out_port.Open();
                }
            }
            catch
            {
                if (in_port != null)
                {
                    in_port.Close();
                }
                if (out_port != null)
                {
                    out_port.Close();
                }
                throw;
            }
        }
Exemplo n.º 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 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 Start()
		{
			if (disposed)
				throw new ObjectDisposedException(GetType().Name);

			try
			{
				engine = new NMEAProtocolEngine((double)settings["movement_threshold"].Value);
				if ((bool)settings["mirror"].Value)
				{
					out_port = application.GetPort(this, (string)settings["out_port"].Value);
					out_port.Read += new PortReadEvent(out_port_Read);
					out_port.Error += new PortErrorEvent(out_port_Error);
					out_port.Open();
				}
				in_port = application.GetPort(this, (string)settings["in_port"].Value);
				in_port.Read += new PortReadEvent(in_port_Read);
				in_port.Error += new PortErrorEvent(in_port_Error);
				in_port.Open();
			}
			catch
			{
				engine = null;
				if (in_port != null)
				{
					in_port.Close();
					in_port.Dispose();
					in_port = null;
				}
				if (out_port != null)
				{
					out_port.Close();
					out_port.Dispose();
					out_port = null;
				}
				throw;
			}
		}