Select to view content in your preferred language

how to simulate file gps connection in ArcGIS Mobile Application(wpf)?

4052
8
08-06-2010 01:53 AM
wangzhifang
Frequent Contributor
I found a demo in this vedio(http://proceedings.esri.com/library/userconf/devsummit10/tech/tech_04.html), which shows a viewfieldcrew task by simulating a file gps connection. That is when login as a field crew, the map display a gps track in active.
Now I'm trying to repeat this demo by a GpsDisplay and a FileGpsConnection, but can't manage to that.
Could anyone give me some piece of advice? Thanks~
0 Kudos
8 Replies
MelindaFrost
Frequent Contributor
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);
            }

        }
0 Kudos
wangzhifang
Frequent Contributor
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);
            }

        }


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();
             }
0 Kudos
MelindaFrost
Frequent Contributor
I did get the serial port to work by after setting the gpsdisplaycontrol to the mapcontrol I had to add the gpsdisplaycontrol as a graphic to the map. The gpsdisplaycontrol is basically a graphic layer to the map.

 _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;
0 Kudos
MaximilianGlas
Esri Contributor
You want to be pretty sure, that the port is 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");

3 times the same, but on a different way.:D
0 Kudos
YinghongLi
Frequent Contributor
Hello,

Could you share your gps log file?  I want to do the same thing but could find a log file sample.

Thanks.
0 Kudos
YinghongLi
Frequent Contributor
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();
             }


Hello,

Could you share your fangchengdongli.txt?  I want to do the same thing but have hard time to get this file.

Thanks
0 Kudos
DeniseKing
Esri Regular Contributor
Hi all,

There is a related topic on ArcGIS Ideas, http://ideas.arcgis.com/ideaView?id=08730000000blVoAAI. Please visit the newly revamped ArcGIS Ideas site and vote on this and other ideas.

Cheers,
Denise
0 Kudos
EzequiasRodrigues_da_Rocha
Regular Contributor
Hi

I am getting a NaN (not a number) when trying to use your code like this:

                MessageBox.Show("X: " + GpsConn.Longitude + "\n" + "Y: " + GpsConn.Latitude + "\nA: " + GpsConn.Altitude);
                MessageBox.Show("X: " + serialPortGpsConnection1.Longitude + "\n" + "Y: " + serialPortGpsConnection1.Latitude + "\nA: " + serialPortGpsConnection1.Altitude);               

Do you have any clue of what could happening? I get the "pen" message as you code it for.

Regards
Ezequias Rocha


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);
            }

        }
0 Kudos