none
Calculate magnetic field strength on Windows Phone 8

    Question

  • Hello,

    I am trying to write a simple Metal Detector app. I wanted to use the MagnetometerReading vector, but i noticed that the Vector is already normalized, which makes it impossible to calculate the magnetic field strength. During debugging i saw that there is a  vecMagRaw field and a vecMagCalibrated.  vecMagCalibrated is already normalized and is used for the MagnetometerReading vector, but i need the values of vecMagRaw, the non normalized one.  The field is non-public.

    Is there a way to access it ? Or any other way to solve my problem, some other way to calculate the magnetic field strength ?

    Thanks in advance

    Narek
    Thursday, September 19, 2013 11:23 AM

Answers

  • Hi Narek,
          That field isn't going to be obtainable.  I realized that reflection isn't going to work because Phone apps aren't run in full-trust mode, which is required to get the value of private fields. 
          I don't know enough about this area of development to tell you what to do in this case, but I think that it's reasonable to say that this isn't going to be feasible.  I hope I'm wrong.


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Monday, September 30, 2013 3:37 PM

All replies

  • Assuming that there's no public access for this, have you tried reflection to get the value?  I haven't tried myself.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Friday, September 20, 2013 12:57 PM
  • Yes i tried reflection, but I am getting a FieldAccessException thrown. 
    Monday, September 23, 2013 8:53 AM
  • Please post an app so I can investigate.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Tuesday, September 24, 2013 2:18 PM
  • I am posting a sample where i tried to get "mCurrentValue" through reflection. "mCurrentValue" contains "vecMagRaw" which i need.

    Compass comp = new Compass();
            // Constructor
            public MainPage()
            {
                InitializeComponent();
                comp.Start();
                comp.CurrentValueChanged += comp_CurrentValueChanged;
                // Sample code to localize the ApplicationBar
                //BuildLocalizedApplicationBar();
            }
    
            void comp_CurrentValueChanged(object sender, SensorReadingEventArgs<CompassReading> e)
            {
                var a = comp.GetType().GetField("mCurrentValue", BindingFlags.NonPublic | BindingFlags.Instance);
                var b = a.GetValue(comp);
            }

    Best Regards

    Narek

    Thursday, September 26, 2013 8:00 AM
  • Hi Narek,
          That field isn't going to be obtainable.  I realized that reflection isn't going to work because Phone apps aren't run in full-trust mode, which is required to get the value of private fields. 
          I don't know enough about this area of development to tell you what to do in this case, but I think that it's reasonable to say that this isn't going to be feasible.  I hope I'm wrong.


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Monday, September 30, 2013 3:37 PM
  • Hello,

    I am trying to write a simple Metal Detector app. I wanted to use the MagnetometerReading vector, but i noticed that the Vector is already normalized, which makes it impossible to calculate the magnetic field strength. During debugging i saw that there is a  vecMagRaw field and a vecMagCalibrated.  vecMagCalibrated is already normalized and is used for the MagnetometerReading vector, but i need the values of vecMagRaw, the non normalized one.  The field is non-public.

    Is there a way to access it ? Or any other way to solve my problem, some other way to calculate the magnetic field strength ?

    Thanks in advance

    Narek

    Interesting idea but will it act as a metal detector? Metal detectors rely on a change in inductance caused by the presence of a metal near an inductor (usually a sensing coil).

    That change in inductance the causes some electronic circuit to alter its behavior (e.g. a change in some audible tone's frequency).

    Just curious about what testing you've done that suggest this might work...

    Hugh


    Hugh Moran - http://www.morantex.com


    • Edited by Morantex Wednesday, October 02, 2013 1:49 AM
    Monday, September 30, 2013 3:57 PM