private void AddDevice(Device device) { /* This method is called by the events DeviceDetectionAttempted and DeviceDiscovered. * A new item is added to the ListView. */ // Create a new item ListViewItem item = new ListViewItem(device.Name); item.ImageIndex = 0; /* Link the item to the Device it represents. We'll use this property later when * we have results on whether or not detection succeeded for this device. */ item.Tag = device; /* GPS.NET supports many kinds of devices. Classes such as BluetoothDevice and SerialDevice * inherit from the Device base class. Try casting the device as one of these other types * so we can get more information. */ BluetoothDevice bluetoothDevice = device as BluetoothDevice; SerialDevice serialDevice = device as SerialDevice; GpsIntermediateDriver gpsid = device as GpsIntermediateDriver; // Is this a Bluetooth device? if (bluetoothDevice != null) { // Yes. Show the device's address item.SubItems.Add("Bluetooth (" + bluetoothDevice.Address.ToString() + ")"); } // Is this the GPS Intermediate Driver (GPSID)? else if (gpsid != null) { // Yes. Show its "program port," the port which all applications should use item.SubItems.Add("Multiplexer (" + gpsid.Port + ")"); } // Is this a serial device? else if (serialDevice != null) { // Yes. Show the device's serial port item.SubItems.Add("Serial (" + serialDevice.Port + ")"); } // Add a status message for this device item.SubItems.Add("Testing..."); // Finally, add the item to the list view devicesListView.Items.Add(item); }
private void menuSendLog_Click(object sender, EventArgs e) { /* GeoFrameworks welcomes log files from all developers and end-users. This method will * transmit the contents of a log file to us via our web site. * * PRIVACY NOTICE: No log files contain any personally identifiable information. The information * is used strictly for troubleshooting GPS device issues and for building statistics * such as the most commonly-used GPS devices. */ if (MessageBox.Show("Sending this log file to GeoFrameworks helps us improve your GPS software. The information is anonymous and confidential. An internet connection is required. Would you like to continue?", "Send Log", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes) { try { // Show a wait cursor until we're finished Cursor.Current = Cursors.WaitCursor; Application.DoEvents(); // Make a new web request HttpWebRequest request = null; if (_Device != null) { // We're reporting a log file for a specific device request = (HttpWebRequest)WebRequest.Create("http://www.geoframeworks.com/GPSDeviceDiagnostics.aspx"); } else { // We're reporting a log file for the whole device detection process request = (HttpWebRequest)WebRequest.Create("http://www.geoframeworks.com/GPSDiagnostics.aspx"); } // Provide standard credentials for the web request request.ContentType = "application/x-www-form-urlencoded"; request.Credentials = CredentialCache.DefaultCredentials; request.UserAgent = "GPS Diagnostics"; request.Method = "POST"; string data = ""; // Is a specific device being logged? if (_Device != null) { // Yes. Include some information about the device GpsIntermediateDriver gpsid = _Device as GpsIntermediateDriver; SerialDevice serialDevice = _Device as SerialDevice; BluetoothDevice bluetoothDevice = _Device as BluetoothDevice; data = "Device=" + _Device.Name; data += "&IsGps=" + _Device.IsGpsDevice.ToString(); data += "&Reliability=" + _Device.Reliability.ToString(); if (gpsid != null) { data += "&Type=GPSID"; data += "&ProgramPort=" + gpsid.Port; if (gpsid.HardwarePort == null) { data += "&HardwarePort=None&HardwareBaud=0"; } else { data += "&HardwarePort=" + gpsid.HardwarePort.Port; data += "&HardwareBaud=" + gpsid.HardwarePort.BaudRate; } } else if (serialDevice != null) { data += "&Type=Serial"; data += "&Port=" + serialDevice.Port; data += "&BaudRate=" + serialDevice.BaudRate.ToString(); } else if (bluetoothDevice != null) { data += "&Type=Bluetooth"; data += "&Address=" + bluetoothDevice.Address.ToString(); BluetoothEndPoint endPoint = (BluetoothEndPoint)bluetoothDevice.EndPoint; data += "&Service=" + endPoint.Name; } } // Now append the log data += "&Log=" + _Body; // Get a byte array byte[] buffer = System.Text.UTF8Encoding.UTF8.GetBytes(data); // Transmit the request request.ContentLength = buffer.Length; // Get the request stream. Stream dataStream = request.GetRequestStream(); // Write the data to the request stream. dataStream.Write(buffer, 0, buffer.Length); // Close the Stream object. dataStream.Close(); // Get the response. WebResponse response = request.GetResponse(); // Display the status. string result = ((HttpWebResponse)response).StatusDescription; response.Close(); Cursor.Current = Cursors.Default; Application.DoEvents(); if (result == "OK") { // Disable the menu now that we've received the file. menuSendLog.Enabled = false; MessageBox.Show("We've received your log and will study it further. Thanks for taking the time to send it!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1); } else { // An error occurred while trying to transmit the log. MessageBox.Show("The diagnostics server may not be responding. Please check to see if you have an internet connection, then try again.", result, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); } } catch (WebException ex) { string resultVerbose = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd(); // Reset the cursor Cursor.Current = Cursors.Default; Application.DoEvents(); // Inform the user about the error. What exactly happened? MessageBox.Show("A log could not be sent. " + ex.Message, "Unable to Send", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); } } }
static void Devices_DeviceDetectionCompleted(object sender, EventArgs e) { // Calculate the elapsed time since detection started TimeSpan elapsedTime = DateTime.Now.Subtract(_DateStarted); Device _PreferredGpsDevice = null; SerialDevice _PreferredSerialGpsDevice = null; SerialDevice _PreferredVirtualSerialGpsDevice = null; // Was any device detected? if (Devices.GpsDevices.Count != 0) { // Is any device detected yet? If not, remember it if (_PreferredGpsDevice == null) { _PreferredGpsDevice = Devices.GpsDevices[0]; } // Examine all devices int count = Devices.GpsDevices.Count; for (int index = 0; index < count; index++) { // Get the current device Device device = Devices.GpsDevices[index]; // Is this a serial device? SerialDevice serialDevice = device as SerialDevice; if (serialDevice != null) { // Yes. If we don't have a serial device yet, remember it if (_PreferredSerialGpsDevice == null) { _PreferredSerialGpsDevice = serialDevice; } } // Is this a Bluetooth device? BluetoothDevice bluetoothDevice = device as BluetoothDevice; if (bluetoothDevice != null) { // Yes. Does it have a virtual serial port? SerialDevice virtualDevice = bluetoothDevice.VirtualSerialPort; if (virtualDevice != null) { // Yes. Do we have a preferred virtual port yet? if (_PreferredVirtualSerialGpsDevice == null) { _PreferredVirtualSerialGpsDevice = virtualDevice; } } } } } Log(" " + DateTime.Now.ToLongTimeString() + ": Detection completed in " + elapsedTime.TotalSeconds + " seconds."); Log(""); Log("C. SUMMARY"); Log(""); // Perform an analysis of the host machine if (Devices.GpsDevices.Count == 0) { Log("ERROR No GPS devices were detected!"); } else { if (Devices.GpsDevices.Count == 1) { Log(" " + Devices.GpsDevices.Count.ToString() + " GPS device is working properly."); } else { Log(" " + Devices.GpsDevices.Count.ToString() + " GPS device are working properly."); } // Notify of each properly functioning GPS device foreach (Device device in Devices.GpsDevices) { Log(" " + device.Name + " is working properly and is " + device.Reliability.ToString() + " reliable."); // Remember the first serial device we find (for later) SerialDevice serialDevice = device as SerialDevice; if (serialDevice != null) { _PreferredSerialGpsDevice = serialDevice; } } // Do we have a GPS device, but no *serial* devices? if (_PreferredSerialGpsDevice == null) { Log("WARNING GPS.NET 3.0 is working properly, but third-party applications not using GPS.NET may not function because no serial GPS device is present."); } } if (GpsIntermediateDriver.Current == null) { Log("WARNING The GPS Intermediate Driver is not supported on this device."); } else { Log(" The GPS Intermediate Driver (GPSID) is supported on this device."); // Is it enabled? if (GpsIntermediateDriver.Current.AllowConnections) { Log(" The GPS Intermediate Driver (GPSID) is enabled."); } else { Log("WARNING The GPS Intermediate Driver (GPSID) is turned off."); } // Did it get detected? if (GpsIntermediateDriver.Current.IsGpsDevice) { Log(" The GPS Intermediate Driver (GPSID) is properly configured on " + GpsIntermediateDriver.Current.Port + "."); } else { // The GPSID wasn't functioning. Does it look properly configured? if (GpsIntermediateDriver.Current.HardwarePort == null) { Log("WARNING The GPS Intermediate Driver (GPSID) has no hardware port or baud rate specified."); } else { // Does the port match? if (_PreferredSerialGpsDevice == null) { Log("WARNING No serial GPS devices are available for the GPS Intermediate Driver (GPSID) to use."); } else { Log("WARNING The GPS Intermediate Driver (GPSID) may be configured to use hardware port " + _PreferredSerialGpsDevice.Port + " at " + _PreferredSerialGpsDevice.BaudRate.ToString() + " baud."); } } } } // Show a list of alternative ports foreach (Device device in Devices.GpsDevices) { // Skip the GPSID, we want actual serial ports GpsIntermediateDriver gpsid = device as GpsIntermediateDriver; if (gpsid != null) { continue; } SerialDevice serialDevice = device as SerialDevice; if (serialDevice == null) { continue; } Log(" Programs can also be configured to use " + serialDevice.Port + " at " + serialDevice.BaudRate.ToString() + " baud."); } // Is Bluetooth supported? if (Devices.IsBluetoothSupported) { // Yes. Log(" The Microsoft® Bluetooth stack is installed."); // Is it turned on? if (Devices.IsBluetoothEnabled) { // Yes. Log(" Bluetooth is on and working properly."); } else { // No Log("WARNING Bluetooth is turned off."); } } else { // There's either no stack or a stack from another provider Log("WARNING The Microsoft® Bluetooth stack is not installed."); } Log(""); if (_Output != null) { _Output.Close(); #if Framework30 _Output.Dispose(); #endif } _IsStarted = false; }
static void Devices_DeviceDetectionStarted(object sender, EventArgs e) { Log(""); Log("GPS.NET 3.0 Diagnostics Copyright © 2009 GeoFrameworks, LLC"); switch (Environment.OSVersion.Version.Major) { case 4: // PocketPC 2003 Log("PocketPC 2003 version " + Environment.OSVersion.Version.ToString()); break; case 5: // Windows Mobile switch (Environment.OSVersion.Version.Minor) { case 0: case 1: Log("Windows Mobile 5 version " + Environment.OSVersion.Version.ToString()); break; case 2: Log("Windows Mobile 6 version " + Environment.OSVersion.Version.ToString()); break; case 3: Log("Windows Mobile 7 version " + Environment.OSVersion.Version.ToString()); break; } break; default: Log("(____?) version " + Environment.OSVersion.Version.ToString()); break; } Log(""); Log("A. DEVICES TO TEST"); int loggedDeviceCount = 0; GpsIntermediateDriver gpsid = GpsIntermediateDriver.Current; if (gpsid != null) { loggedDeviceCount++; Log(""); Log(" 1. GPS Intermediate Driver (GPSID)"); Log(" Type: GPS Device Multiplexer"); Log(" Program Port: " + gpsid.Port); if (gpsid.HardwarePort == null) { Log("WARNING Hardware Port: (None or built-in GPS)"); } else { Log(" Hardware Port: " + gpsid.HardwarePort.Port + " at " + gpsid.HardwarePort.BaudRate.ToString() + " baud"); } if (gpsid.AllowConnections) { Log(" Enabled? YES"); } else { Log("WARNING Enabled? NO"); } } foreach (SerialDevice device in SerialDevice.Cache) { loggedDeviceCount++; Log(""); Log(" " + loggedDeviceCount.ToString() + ". " + device.Name); Log(" Type: Serial Device"); Log(" Port: " + device.Port); Log(" Baud Rate: " + device.BaudRate.ToString()); Log(" Reliability: " + device.Reliability.ToString()); Log(" Successes: " + device.SuccessfulDetectionCount.ToString()); Log(" Failures: " + device.FailedDetectionCount.ToString()); } foreach (BluetoothDevice device in BluetoothDevice.Cache) { loggedDeviceCount++; Log(""); Log(" " + loggedDeviceCount.ToString() + ". " + device.Name); Log(" Type: Bluetooth Device"); Log(" Class: " + device.Class.ToString()); Log(" Address: " + device.Address.ToString()); Log(" Reliability: " + device.Reliability.ToString()); Log(" Successes: " + device.SuccessfulDetectionCount.ToString()); Log(" Failures: " + device.FailedDetectionCount.ToString()); } Log(""); Log("B. DEVICE DETECTION PROGRESS"); Log(""); Log(" " + DateTime.Now.ToLongTimeString() + ": Detection has started."); _DateStarted = DateTime.Now; }
public SummaryForm() { InitializeComponent(); // Add images to our image lists imageList1.Images.Add(Program.Gps); imageList1.Images.Add(Program.Error); imageList1.Images.Add(Program.Warning); imageList1.Images.Add(Program.Ok); imageList2.Images.Add(Program.Gps); // Was any device detected? if (Devices.IsDeviceDetected) { // Yes. Add all confirmed devices to a listview foreach (Device device in Devices.GpsDevices) { AddDevice(device); // Is this the GPS Intermediate Driver? We only want plain serial devices, so skip it GpsIntermediateDriver gpsidDevice = device as GpsIntermediateDriver; if (gpsidDevice != null) { continue; } // The "preferred" device is serial, but not the GPSID SerialDevice serialDevice = device as SerialDevice; if (serialDevice != null) { preferredSerialDevice = serialDevice; } } // If we have more than two GPS devices, use a smaller ListView view if (Devices.GpsDevices.Count > 2) { gpsListView.View = View.SmallIcon; } /* A GPS device was found. Most third-party applications * require a serial connection. Is one available for them? */ if (preferredSerialDevice == null && (gpsid == null || !gpsid.IsGpsDevice)) { /* No. GPS.NET can still work with Bluetooth, but for most end-users * this can still be a problem. They'll appreciate help with solving it. */ AddWarning("Third-party GPS programs may have trouble connecting.", "ConfigureGpsid"); } } else { // Show that no devices were found AddError("No GPS devices could be found.", "NoDevices"); } // Let's make a summary of good things and bad things. if (gpsid != null) { // Was the GPS Intermediate Driver detected? if (gpsid.IsGpsDevice) { // Make an item confirming the GPSID AddMessage("Use the port \"" + gpsid.Port + "\" whenever possible for GPS programs.", "UseGpsidPort"); } else { // The GPSID may need to be configured properly. Let's look at its settings if (gpsid.HardwarePort != null) { if (preferredSerialDevice != null && gpsid.HardwarePort.Port.Equals(preferredSerialDevice.Port)) { AddMessage("The GPS Intermediate Driver was reconfigured to use " + preferredSerialDevice.Name + " on " + preferredSerialDevice.Port + " at " + preferredSerialDevice.BaudRate.ToString() + " baud.", "GpsidReconfigured"); AddMessage("Use " + preferredSerialDevice.Port + " at " + preferredSerialDevice.BaudRate.ToString() + " baud for third-party GPS programs.", "ThirdPartyGpsPort"); } else { AddWarning("The GPS Intermediate Driver is not working on " + gpsid.HardwarePort.Port + " at " + gpsid.HardwarePort.BaudRate.ToString() + " baud.", "GpsidIncorrectPort"); // The current hardware port isn't working, so let's suggest a working device if (preferredSerialDevice != null) { AddWarning("Change the GPS Intermediate Driver to use " + preferredSerialDevice.Port + " at " + preferredSerialDevice.BaudRate.ToString() + " baud.", "GpsidFixHardwarePort"); } else { // Do we have a Bluetooth device with a virtual port? bool isVirtualPortFound = false; foreach (BluetoothDevice bluetooth in Devices.BluetoothDevices) { // Is this a Bluetooth GPS device? if (bluetooth.IsGpsDevice) { // Yes. Does it also have a virtual serial port bound to it? if (bluetooth.VirtualSerialPort != null) { // Yes. preferredVirtualSerialDevice = bluetooth.VirtualSerialPort; isVirtualPortFound = true; AddWarning("Change the GPS Intermediate Driver to use the " + bluetooth.Name + " GPS device on " + bluetooth.VirtualSerialPort.Port + " at " + bluetooth.VirtualSerialPort.BaudRate.ToString() + " baud.", "GpsidUseVirtualBluetoothPort"); break; } } } if (!isVirtualPortFound) { // Do we have a BT device we could pair with? bool isBluetoothPossible = false; foreach (BluetoothDevice device in Devices.BluetoothDevices) { if (device.IsGpsDevice) { isBluetoothPossible = true; AddWarning("Use the Bluetooth Manager to create a virtual serial port for the " + device.Name + ".", "BluetoothCreateVirtualPort"); } } if (!isBluetoothPossible) { AddError("No devices are available for the GPS Intermediate Driver.", "GpsidNoDevice"); } } } } } } } else { // The GPSID may need to be configured AddWarning("The GPS Intermediate Driver is not supported.", "GpsidNotSupported"); } // Is Bluetooth supported? if (!Devices.IsBluetoothSupported) { // Bluetooth is not supported AddWarning("Microsoft® Bluetooth is not supported on this device.", "BluetoothNotSupported"); } else { // Is Bluetooth on? if (Devices.IsBluetoothEnabled) { // Bluetooth is on AddMessage("Bluetooth is on and working properly.", "BluetoothOk"); } else { // Bluetooth is off AddWarning("Turn Bluetooth on.", "TurnBluetoothOn"); } } // Let's look for devices which were previously detected, but not this time if (Devices.IsBluetoothSupported && Devices.IsBluetoothEnabled) { foreach (BluetoothDevice device in Devices.BluetoothDevices) { if (device.SuccessfulDetectionCount != 0 && !device.IsGpsDevice) { // Here's a device which worked before, but not now AddWarning("Turn the " + device.Name + " off and back on again.", "TurnDeviceOn"); } } } // Do we have a serial GPS device to use? if (preferredSerialDevice != null) { // Yes. The port is different from the GPSID, so help the user know they have an alternative they can try. if (gpsid != null && gpsid.IsGpsDevice && !gpsid.Port.Equals(preferredSerialDevice.Port)) { AddMessage("Though less preferred, you can also use " + preferredSerialDevice.Port + " at " + preferredSerialDevice.BaudRate.ToString() + " baud for third-party GPS programs.", "AlternativeSerialPort"); } } // Were there any errors? if (errorCount > 0) { // Yes. How many devices were found? if (Devices.GpsDevices.Count == 0) { // None. titleLabel.Text = "Errors Were Found"; descriptionLabel.Text = "Some problems were found. Click on an error below to try and fix it."; } else { // A device was found, so they can at least use GPS titleLabel.Text = "Some Problems Were Found"; descriptionLabel.Text = "GPS is responding, but some problems were found, too. Check out the suggestions below."; } } // Were any warnings encountered? else if (warningCount > 0) { // Yes. titleLabel.Text = "Minor Problems Were Found"; descriptionLabel.Text = "GPS is responding, but some things could be improved. Check out the suggestions below."; } else { // No errors or warnings. That's great! titleLabel.Text = "You Are Awesome"; descriptionLabel.Text = "GPS is working properly and no problems were found."; } }