Click here to Skip to main content
15,886,661 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am developing a Windows Phone 8 application, where i want to change the frequency of FMRadio. If i try to change the frequency with var or double directly, it works good. But if i modify the varible value it gives an error (Value does not fall within the expected range).
I just want to know that why is it gives error even both techniques return same value.
================================================================================
Microsoft.Devices.Radio.FMRadio FMRadio = Microsoft.Devices.Radio.FMRadio.Instance;
      public static Microsoft.Devices.Radio.RadioRegion CurrentRegion = Microsoft.Devices.Radio.RadioRegion.UnitedStates;

private void ChangeRadio_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var MainFreq = FMRadio.Frequency;
              
               
                if (MainFreq >= 87.5 && MainFreq <= 108)
                {
                    if (MainFreq < 108)
                    {
                        FMRadio.CurrentRegion = CurrentRegion;
                       
                        double ch = 95.1 + 0.1; //generates error
                       // double ch = 95.6; // works good
                        
                        FMRadio.Frequency = ch;
                       
                    }
                    else
                    {
                        FMRadio.CurrentRegion = CurrentRegion;
                        FMRadio.Frequency = 87.5;
                    }
                  
                }
                else
                {
                    MessageBox.Show("Radio is OFF");
                }
            }
            
            catch (ArgumentException ex)
            {
                MessageBox.Show(ex.Message.ToString() + "\n" + ex.HResult);
                
            }
            
            
        }
Posted
Updated 21-Feb-15 4:09am
v2

1 solution

Maybe the problem is due to FM frequency definition in USA as stated in Section 73.201 of the FCC's Rules (see).
In your case it seems that the tuner accepts the base channel frequency, that is odd while the center channel is even. In this case the float sum may lead to a value that is not correct. Try encoding directly 95.2 to check if the problem is the value itself, or try adding a slighty higher value (i.e. 95.1+0.101) ur using integers then casted to floats.
BTW for USA radio region limits should be 88-108MHz (not 87.5-108MHz).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900