public override void OnOpen() { //��UDP�˿ڣ��ȴ����ݴ��� this.updServer = UDPServer.getUDPServer(Program.GPS_UDP_Port); updServer.evtReceived += new OnReceiveString(updServer_evtReceived); updServer.startUDPListening(); GPS = new NmeaInterpreter(); GPS.PositionReceived += new NmeaInterpreter.PositionReceivedEventHandler(GPS_PositionReceived); }
public override void OnOpen() { //打开UDP端口,等待数据传入 this.updServer = UDPServer.getUDPServer(Program.GPS_UDP_Port); updServer.evtReceived += new OnReceiveString(updServer_evtReceived); updServer.startUDPListening(); GPS = new NmeaInterpreter(); GPS.PositionReceived += new NmeaInterpreter.PositionReceivedEventHandler(GPS_PositionReceived); }
public void setDevice(ModuleCommand.command cmd, Action <ModuleCommand.command> callback) { myCallBack = callback; myCommand = cmd; //打开UDP端口,等待数据传入 this.updServer = UDPServer.getUDPServer(Program.GPS_UDP_Port); updServer.evtReceived += new OnReceiveString(updServer_evtReceived); updServer.startUDPListening(); GPS = new NmeaInterpreter(); GPS.PositionReceived += new NmeaInterpreter.PositionReceivedEventHandler(GPS_PositionReceived); Debug.WriteLine(string.Format("***** GPSService onListening... ")); }
public void setDevice(ModuleCommand.command cmd, Action<ModuleCommand.command> callback) { myCallBack = callback; myCommand = cmd; //打开UDP端口,等待数据传入 this.updServer = UDPServer.getUDPServer(Program.GPS_UDP_Port); updServer.evtReceived += new OnReceiveString(updServer_evtReceived); updServer.startUDPListening(); GPS = new NmeaInterpreter(); GPS.PositionReceived += new NmeaInterpreter.PositionReceivedEventHandler(GPS_PositionReceived); Debug.WriteLine(string.Format("***** GPSService onListening... ")); }
public GpsThread() { Devices.DeviceDetected += DeviceDetected; Devices.AllowExhaustiveSerialPortScanning = false; Devices.AllowBluetoothConnections = false; Devices.BeginDetection(); Devices.WaitForDetection(); if (dev == null) { throw new GpsThreadException("Did not find any GPS devices!"); } nmea = new NmeaInterpreter(); nmea.SatellitesChanged += SatellitesChanged; nmea.DateTimeChanged += TimeChanged; nmea.PositionChanged += PositionChanged; nmea.AltitudeChanged += ElevationChanged; nmea.Start(dev); t = new Thread(ThreadRun); t.Start(); }
public GPSHandler(ILog logpass, EventHandler <DeviceEventArgs> onConnect, EventHandler <DeviceEventArgs> onFix, EventHandler <DeviceEventArgs> onFixLost, EventHandler <PositionEventArgs> onPosition) { this.GPSName = string.Empty; Application.ThreadException += this.Application_ThreadException; AppDomain.CurrentDomain.UnhandledException += this.CurrentDomain_UnhandledException; Devices.DeviceDetectionAttempted += this.Devices_DeviceDetectionAttempted; Devices.DeviceDetectionAttemptFailed += this.Devices_DeviceDetectionAttemptFailed; Devices.DeviceDetectionStarted += this.Devices_DeviceDetectionStarted; Devices.DeviceDetectionCompleted += this.Devices_DeviceDetectionCompleted; Devices.DeviceDetectionCanceled += this.Devices_DeviceDetectionCanceled; Devices.DeviceDetected += this.Devices_DeviceDetected; Devices.DeviceDetected += onConnect; Devices.FixAcquired += new EventHandler <DeviceEventArgs>(Devices_FixAcquired); Devices.FixAcquired += onFix; Devices.FixLost += new EventHandler <DeviceEventArgs>(Devices_FixLost); Devices.FixLost += onFixLost; Devices.PositionChanged += new EventHandler <PositionEventArgs>(Devices_PositionChanged); this.nmeaInterpreter = new NmeaInterpreter(); this.nmeaInterpreter.IsFilterEnabled = false; this.nmeaInterpreter.Starting += new EventHandler <DeviceEventArgs>(this.nmeaInterpreter_Starting); this.nmeaInterpreter.Started += new EventHandler(this.nmeaInterpreter_Started); this.nmeaInterpreter.Stopping += new EventHandler(this.nmeaInterpreter_Stopping); this.nmeaInterpreter.Stopped += new EventHandler(this.nmeaInterpreter_Stopped); this.nmeaInterpreter.Paused += new EventHandler(this.nmeaInterpreter_Paused); this.nmeaInterpreter.Resumed += new EventHandler(this.nmeaInterpreter_Resumed); this.nmeaInterpreter.ConnectionLost += new EventHandler <ExceptionEventArgs>(nmeaInterpreter_ConnectionLost); this.nmeaInterpreter.FixAcquired += new EventHandler(nmeaInterpreter_FixAcquired); this.nmeaInterpreter.FixLost += new EventHandler(nmeaInterpreter_FixLost); this.nmeaInterpreter.PositionReceived += new EventHandler <PositionEventArgs>(this.nmeaInterpreter_PositionRecieved); this.nmeaInterpreter.PositionReceived += onPosition; //this.nmeaInterpreter.PositionChanged += new EventHandler<PositionEventArgs>(this.nmeaInterpreter_PositionChanged); Devices.AllowBluetoothConnections = false; this.detectTimer = new System.Timers.Timer(); this.detectTimer.Interval = 5000; this.detectTimer.Elapsed += new ElapsedEventHandler(this.detectTimer_Tick); this.detectTimer.Start(); //this.detectTimer.SynchronizingObject = this; log = logpass; log.Info("Handler initialized"); }
void DetectAndStartGPS() { try { if (Common.AppSettings.Instance.EnableGPS && !string.IsNullOrEmpty(Common.AppSettings.Instance.GPSPort) && Common.AppSettings.Instance.GPSPort.Length > 3) { string strComNum = Common.AppSettings.Instance.GPSPort.Substring(3); int iComNum = -1; if (!int.TryParse(strComNum, out iComNum)) { iComNum = -1; } Devices.DeviceDetectionAttemptFailed += (s, e) => { // }; Devices.DeviceDetectionCompleted += (s, e) => { try { foreach (Device dev in Devices.GpsDevices) { SerialDevice sd = dev as SerialDevice; if (sd != null && (sd.Port == Common.AppSettings.Instance.GPSPort || sd.PortNumber == iComNum)) { _curDevice = sd; break; } } if (_curDevice == null) { _curDevice = new SerialDevice(Common.AppSettings.Instance.GPSPort); Devices.Add(_curDevice); } } catch { _curDevice = null; } bool bGoodDevice = false; if (_curDevice != null) { try { _curDevice.Connected += (sd, ed) => { Common.DebugHelper.WriteLine("GPS Device Opened: {0}", Common.AppSettings.Instance.GPSPort); }; _curDevice.Disconnected += (sd, ed) => { Common.DebugHelper.WriteLine("GPS Device Closed: {0}", Common.AppSettings.Instance.GPSPort); }; if (!_curDevice.IsOpen) { _curDevice.Open(); } NmeaInterpreter nmea = new NmeaInterpreter(); nmea.PositionChanged += nmea_PositionChanged; nmea.Start(_curDevice); bGoodDevice = true; } catch (Exception ex) { Common.DebugHelper.WriteExceptionToLog("DetectAndStartGPS", ex, true, string.Format("Device found, but error setting up: {0}", Common.AppSettings.Instance.GPSPort)); bGoodDevice = false; } } if (!bGoodDevice) { ClearCurrentPosition(); } }; Devices.AllowBluetoothConnections = false; Devices.AllowExhaustiveSerialPortScanning = false; Devices.AllowSerialConnections = true; Devices.BeginDetection(); } } catch { _curDevice = null; } }