private SerialPortGpsConnection serialPortGpsConnection1 = new SerialPortGpsConnection();
private void openButton_Click(object sender, RoutedEventArgs e)
{
try
{
// Create an instance of MobileCache, and set StoragePath
MobileCache m_mobileCache = new MobileCache();
m_mobileCache.StoragePath = @"c:\temp\MapCache";
m_mobileCache.Open();
// Load layers from MobileCache to Map control
mapControl1.MapLayers.AddRange(m_mobileCache);
//Declare a generic GPS connection variable
GpsConnection GpsConn = null;
//Uncoment to Use SerialGPSConnection if you are reading GPS data from a device
serialPortGpsConnection1.PortName = "AUTO";
serialPortGpsConnection1.LoggingFile = @"c:\temp\logginggps.log";
serialPortGpsConnection1.Open();
Boolean port = serialPortGpsConnection1.IsOpen;
if (port) MessageBox.Show("open");
GpsConn = serialPortGpsConnection1;
gpsDisplayControl1.GpsConnection = GpsConn;
gpsDisplayControl1.Map = mapControl1;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Did you ever get this to work? I am trying to use a SerialPortGpsConnection with a GPS emulator. I know the SerialPortGpsConnection finds the gps connection and it writes successfully to the log file. And I assigned it to the GPSDisplay but it never updates the GPS location on the map.private SerialPortGpsConnection serialPortGpsConnection1 = new SerialPortGpsConnection(); private void openButton_Click(object sender, RoutedEventArgs e) { try { // Create an instance of MobileCache, and set StoragePath MobileCache m_mobileCache = new MobileCache(); m_mobileCache.StoragePath = @"c:\temp\MapCache"; m_mobileCache.Open(); // Load layers from MobileCache to Map control mapControl1.MapLayers.AddRange(m_mobileCache); //Declare a generic GPS connection variable GpsConnection GpsConn = null; //Uncoment to Use SerialGPSConnection if you are reading GPS data from a device serialPortGpsConnection1.PortName = "AUTO"; serialPortGpsConnection1.LoggingFile = @"c:\temp\logginggps.log"; serialPortGpsConnection1.Open(); Boolean port = serialPortGpsConnection1.IsOpen; if (port) MessageBox.Show("open"); GpsConn = serialPortGpsConnection1; gpsDisplayControl1.GpsConnection = GpsConn; gpsDisplayControl1.Map = mapControl1; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
if (signinExtension.UserID == "工�?人�??A")
{
fgc = new FileGpsConnection();
fgc.Enabled = true;
fgc.FileName = @"c:\fangchengdongli.txt";
fgc.Cycling = true;
fgc.ReadInterval = 1000;
MobileApplication.Current.GpsConnectionManager.GpsDisplay.GpsConnection = fgc;
fgc.Open();
}
_serialPortGpsConnection = new SerialPortGpsConnection();
gpsDisplayControl1 = new GpsDisplayControl();
_serialPortGpsConnection.PortName = "AUTO";
_serialPortGpsConnection.LoggingFile = @"c:\temp\logginggps.log";
_serialPortGpsConnection.Open();
if (!_serialPortGpsConnection.IsOpen)
{
System.Windows.MessageBox.Show("GPS Device could not be detected");
return;
}
Boolean port = _serialPortGpsConnection.IsOpen;
if (!port) System.Windows.MessageBox.Show("The serial port could not be detected");
GpsConn = _serialPortGpsConnection;
if (!GpsConn.IsOpen) System.Windows.MessageBox.Show("The GPS Connection could not be established");
gpsDisplayControl1.GpsConnection = GpsConn;
gpsDisplayControl1.Map = _map;
gpsDisplayControl1.AutoPan = true;
_map.MapGraphicLayers.Add(gpsDisplayControl1);
_buttonLabel = "GPS Off";
gpsOnOff = true;
if (!_serialPortGpsConnection.IsOpen)
{
System.Windows.MessageBox.Show("GPS Device could not be detected");
return;
}
Boolean port = _serialPortGpsConnection.IsOpen;
if (!port) System.Windows.MessageBox.Show("The serial port could not be detected");
GpsConn = _serialPortGpsConnection;
if (!GpsConn.IsOpen) System.Windows.MessageBox.Show("The GPS Connection could not be established");Hi, buddha, I haven't used the serialPortGpsConnection1, try to enable serialPortGpsConnection first and set
GpsConn = serialPortGpsConnection1;
gpsDisplayControl1.GpsConnection = GpsConn;
gpsDisplayControl1.Map = mapControl1;
before you open it.
About my problem, I finally figure it out by using the internal GPSDisplay and GPSConnection class within the ArcGIS Mobile App for Windows. the key code is:if (signinExtension.UserID == "工�?人�??A") { fgc = new FileGpsConnection(); fgc.Enabled = true; fgc.FileName = @"c:\fangchengdongli.txt"; fgc.Cycling = true; fgc.ReadInterval = 1000; MobileApplication.Current.GpsConnectionManager.GpsDisplay.GpsConnection = fgc; fgc.Open(); }
Did you ever get this to work? I am trying to use a SerialPortGpsConnection with a GPS emulator. I know the SerialPortGpsConnection finds the gps connection and it writes successfully to the log file. And I assigned it to the GPSDisplay but it never updates the GPS location on the map.private SerialPortGpsConnection serialPortGpsConnection1 = new SerialPortGpsConnection(); private void openButton_Click(object sender, RoutedEventArgs e) { try { // Create an instance of MobileCache, and set StoragePath MobileCache m_mobileCache = new MobileCache(); m_mobileCache.StoragePath = @"c:\temp\MapCache"; m_mobileCache.Open(); // Load layers from MobileCache to Map control mapControl1.MapLayers.AddRange(m_mobileCache); //Declare a generic GPS connection variable GpsConnection GpsConn = null; //Uncoment to Use SerialGPSConnection if you are reading GPS data from a device serialPortGpsConnection1.PortName = "AUTO"; serialPortGpsConnection1.LoggingFile = @"c:\temp\logginggps.log"; serialPortGpsConnection1.Open(); Boolean port = serialPortGpsConnection1.IsOpen; if (port) MessageBox.Show("open"); GpsConn = serialPortGpsConnection1; gpsDisplayControl1.GpsConnection = GpsConn; gpsDisplayControl1.Map = mapControl1; } catch (Exception ex) { MessageBox.Show(ex.Message); } }