Welcome to the new FlexRadio Community! Please review the new Community Rules and other important new Community information on the Message Board.
If you are having a problem, please refer to the product documentation or check the Help Center for known solutions.
Need technical support from FlexRadio? It's as simple as Creating a HelpDesk ticket.

Changing bands

Options
Trucker
Trucker Member ✭✭✭

Several years ago, I put together a test program, to try and learn C# and the Flexlib api. At the time, version 2 of the api was in use. I had no problem changing bands. Now, after re-referencing the v3.5.8 api everything works, except changing bands.

 private void btn17_Click(object sender, EventArgs e)

       {

           _thisRadio.ActiveSlice.Panadapter.Band = "17";


       }


The above no longer works. I get a Null Reference in the Slice Property Changed event:


private void slice_PropertyChanged(object sender, PropertyChangedEventArgs e)

      {

           //     CODE TO DEAL WITH SLICE PROPERTY CHANGES     

         bool x = _thisRadio.ActiveSlice.Active;

              if (x == true)

          {



             int dummy = 0; dummy++;

              slicefreqTextbox.Text = _thisRadio.ActiveSlice.Freq.ToString() + " Mhz";

              slicemodeTextbox.Text = _thisRadio.ActiveSlice.DemodMode.ToString();

               // gets current Slice volume and sets the volume control on startup

              int volume = _thisRadio.ActiveSlice.AudioGain;

               tbarVolume.Value = volume;

               lblVolAmt.Text = tbarVolume.Value.ToString();

           }

       }


The very first line of code is where it breaks in Visual Studio. If I put a Breakpoint in the btn17 Click event at:

 _thisRadio.ActiveSlice.Panadapter.Band = "17";


and hover the mouse pointer over .Band the tooltip shows 20 meters as that was the current band setting ( the radio is sending the default band, frequency etc on startup till I change it.)

I am not sure what may have changed syntax wise since version 2 in the api that is causing this particular issue. I am pretty certain that I am missing the forest for the trees.

I figure that I am not setting the band properly anymore. But, my 72 year old brain is missing something that is probably very simple.

James

WD5GWY

Best Answers

  • Eric-KE5DTO
    Eric-KE5DTO Administrator, FlexRadio Employee admin
    edited August 2023 Answer ✓
    Options

    "_thisRadio.ActiveSlice.Panadapter.Band = "17";"

    It looks to me like you need to check the different levels here (_thisRadio, ActiveSlice, Panadapter) to ensure those references aren't null. One of them apparently is. When you figure out which one it is, you'll need to work backwards to understand why it is null (e.g. was _thisRadio never set to an object? Is there no ActiveSlice? etc).

    You can do a fair amount of this by setting a breakpoint and inspecting each of the variables when the breakpoint is hit. This likely won't explain the "why", but at least it will get you down the road on which part of the line is unexpectedly null.

  • KD0RC
    KD0RC Member, Super Elmer Moderator
    Answer ✓
    Options

    Hi James, that code works fine for me. I do handle the following at the beginning of my code. I'm not sure if you just need to establish something in one of these routines.

          radio.PropertyChanged += new PropertyChangedEventHandler(radio_PropertyChanged);
          radio.SliceAdded += new Radio.SliceAddedEventHandler(radio_SliceAdded);
          radio.SliceRemoved += new Radio.SliceRemovedEventHandler(radio_SliceRemoved);
          radio.PanadapterAdded += new Radio.PanadapterAddedEventHandler(radio_PanAdded);
          radio.SlicePanReferenceChange += new Radio.SlicePanReferenceChangeEventHandler(radio_PanRefChg);
          radio.VoltsDataReady += new Radio.MeterDataReadyEventHandler(_thisRadio_VoltsDataReady);
          radio.PATempDataReady += new Radio.MeterDataReadyEventHandler(_thisRadio_PATempDataReady);
          radio.GUIClientAdded += new Radio.GUIClientAddedEventHandler(_thisRadio_GUIClientAdded);
          radio.GUIClientUpdated += new Radio.GUIClientUpdatedEventHandler(_thisRadio_GUIClientUpdated);
          radio.GUIClientRemoved += new Radio.GUIClientRemovedEventHandler(_thisRadio_GUIClientRemoved);
          radio.MessageReceived += new Radio.MessageReceivedEventHandler(_thisRadio_MessageReceived);
    
          radio.Connect();
    

Answers

  • Trucker
    Trucker Member ✭✭✭
    edited August 2023
    Options

    Len,

    I commented out the code in my Slice property changed event and now the rest of my code is working again. I suspect the root of the problem is in what you posted. I haven't updated that section of code that you posted in quite a long time. Thanks for bringing this to my attention. I have several test programs that I wrote in years past including one that has a waterfall. I managed to mangle the waterfall during what I thought at the time, was cleaning up some unneeded code. That particular test program had code more like what you posted here. The spectrum display works ( as does the test program I managed to mess up now) . It looks like I will have to revisit several things along with trying to get up to speed with changes to the API.

    James

    WD5GWY

  • KD0RC
    KD0RC Member, Super Elmer Moderator
    Options

    Hi James, I'm glad that helped. I have an older version of my FlexLib sampler program out on GitHub. I will replace it with my new code that includes the band up and band down buttons. Hopefully, that will provide some insights.

  • KD0RC
    KD0RC Member, Super Elmer Moderator
    Options

    Hi James, I put the latest code out there. It is in Releases.


  • Trucker
    Trucker Member ✭✭✭
    Options

    Len,

    Thanks for sharing. I like the way you are handling different events. It will definitely give me some needed pointers.

    James

    WD5GWY

  • KD0RC
    KD0RC Member, Super Elmer Moderator
    Options

    Excellent! One tricky bit to note... in radio_SliceAdded(Slice slice), there are two new property changed event handlers, one for slice 0 and one for slice 1.

    It took me a while to figure this out as it was not intuitive to me (old Fortran, PL/I, COBOL programmer...).

  • Trucker
    Trucker Member ✭✭✭
    Options

    Len,

    I seem to have fixed the band change problem. And I also "borrowed " the way you format the frequency readout as well. Right now though, I only place the frequency reading in a Textbox. I think I can do something a little nicer than that. In my waterfall test program, it has a nicer display of the frequency. It might be time to borrow that code and incorporate it into this test program.

    James

    WD5GWY

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.