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.

WinForms test app.

James Whiteway
edited June 2020 in New Ideas
Here is a link to a basic test program that I wrote a few months ago that I have shared with several people off forum. It was written in C# with Visual Studio 2010. Bu, it should work with
later versions of Visual Studio as well. You will need to un-reference the Flexlib dll's and re-reference to the latest version(s) you may or may not have on your system. It does not include a panadapter or waterfall. But, it gives enough info, that hopefully, it will help others wanting to try to write their own programs for the 6000 Series radios.
The title on the app's main form, (it's only form) says K1PGV's test program. That is because the original beginning of this program came from code generously shared by Peter. BUT, all of the sloppy coding is my doing and not Peter's! I hope this helps others as I have been helped.
 james
 WD5GWY

https://www.dropbox.com/s/ran9z0mjk3t0jpo/WorkingCSharpFlexExample.zip?dl=0



0 votes

Open for Comments · Last Updated

«1

Comments

  • rfoust
    rfoust Member ✭✭
    edited March 2017
    Very nice!  It compiled with no problems.  Loaded the app, and it actually crashed when I clicked "connect", although it detected my flex serial number.  Haven't spent any time trying to debug it yet but I probably will soon.  Been wanting to do a little more in C# so this is a great excuse to get me into it.
  • James Whiteway
    edited March 2017
    Be sure you ReReference all of the dll's in Flexlib. This particular version was built with an earlier version of Flexlib, so that could cause the program to crash. James WD5GWY
  • rfoust
    rfoust Member ✭✭
    edited December 2016
    Just tried re-adding them.  Looks like the crash actually happens right after the connection succeeds.  The debug error is:

    An unhandled exception of type 'System.NullReferenceException' occurred in WorkingCSharpFlexExample.exe
    Additional information: Object reference not set to an instance of an object.

    I'll keep playing around with it but it might be tomorrow before I can spend more debugging/testing time on it.
  • James Whiteway
    edited December 2015
    Windows Firewall will cause the same problem. I don't have my Flex hooked up right now, But, I have had that issue in the past. Debugging is half the fun!
    james
    WD5GWY

  • Dan -- KC4GO
    Dan -- KC4GO Member
    edited March 2018
    Thanks for the kick start on my C# education --- Lots of code for me to trace thru...

    73's
    Dan --- KC4GO
  • rfoust
    rfoust Member ✭✭
    edited December 2016
    Ok, ran it again with the debug stuff enabled.  The crash is coming from:
    private void radio_SliceAdded(Slice slice)         {                          slice.PropertyChanged += new PropertyChangedEventHandler(slice_PropertyChanged);// makes freqtxtbx show freq from SSDR              slicefreqTextbox.Text = slice.Freq.ToString();   //display freq on new slice             slicemodeTextbox.Text = _thisRadio.ActiveSlice.DemodMode.ToString();    //display mode on new slice 
    ^^ that last line.  I assume that DemodMode.tostring() isn't there when it is called, but not entirely sure why yet.  Timing issue?


  • rfoust
    rfoust Member ✭✭
    edited December 2016
    Oh, it works when SSDR isn't running.  I'm gonna go read more of the code to get a better understanding of how it works. :-)
  • rfoust
    rfoust Member ✭✭
    edited December 2016
    Ok, got it working.  I just added a check for null around the relevant code to prevent the null reference.
    private void radio_SliceAdded(Slice slice)         {                          slice.PropertyChanged += new PropertyChangedEventHandler(slice_PropertyChanged);// makes freqtxtbx show freq from SSDR              slicefreqTextbox.Text = slice.Freq.ToString();   //display freq on new slice             if (_thisRadio.ActiveSlice != null)             {                 slicemodeTextbox.Text = _thisRadio.ActiveSlice.DemodMode.ToString();    //display mode on new slice                 textRFpower.Text = _thisRadio.RFPower.ToString() + " Watts";                 _thisSlice = slice;                 // Below allows reading S Meter data                 _thisSlice.SMeterDataReady += OnSMeterDataReady;                 // below gets current slice's band info                 string bandinfo = slice.Panadapter.Band;                 lblBand.Text = bandinfo + " Meters";                 // Slice bandwidth                 txtBW.Text = _thisRadio.ActiveSlice.FilterHigh.ToString() + " High " +                     _thisRadio.ActiveSlice.FilterLow.ToString() + "Low";             }                     }
  • James Whiteway
    edited January 2016
    Nice fix! Cannot wait to get back to coding. My 6300 is on it's way to Flex land to be traded in for a 6500! (Merry Christmas, Happy Birthday etc. etc. to me!) Until the new one arrives next week and I get back, next Friday, (I drive a truck from Arkansas to Arizona during the week) I cannot play with coding for the Flex.
        As for the program only working with SSDR offline, it should work if you already have SSDR running before you start the test program. In fact, it should work (as it did) without SSDR running as well. The only time you may run into issues is if you are trying to have a panadapter/waterfall as well. Then,  at the top of the program listings where is shows  API.*** = xyz;  If you are trying to do a panadapter and a waterfall, then you need to add this line:
    API.IsGUI = true;

    That way, the radio knows to send the panadapter and waterfall data to your client.
    But, it won't send it to SSDR at the same time. In fact, if you are using IsGUI = true:
    SSDR will not run, you will get a popup box from SSDR saying that the radio is busy.
    Hopefully, one of these days, Flex will make it where more than one client can access the GUI data (panadapter and waterfall) at the same time. I suspect they will in the not so distant future so that users of the upcoming Maestro controller can run it and SSDR at the same time if they want to.
    james
    WD5GWY


  • James Whiteway
    edited January 2016
    @ Robbie. Another reason the program "might" trip up at demodMode is likely an issue with getting data back from the Persistance database in the radio. I have had that happen in the past on a couple of things. I may have fixed it in a later version of the program. I will check and see if I have next weekend. James WD5GWY
  • Vern
    Vern Member
    edited March 2017
    What methods did you add the 'if (_thisRadio.ActiveSlice != null)' too? Thought I might have had the same problem. However the first button I am clicking after boot up is 'Connect'. It fails!  I added your if statement [if (_thisRadio.Connect() ]!= null)) but no luck.
    Thank you,
    Vern    w9HLY
  • James Whiteway
    edited January 2016
    As far as I can see, Robbie added it to the : radio_sliceAdded event in the code he posted above. What error message are you getting ? And, are you running the code with SSDR running first? Try it without SSDR running. It should run either way. But, it would not for Robbie with SSDR running. James WD5GWY
  • rfoust
    rfoust Member ✭✭
    edited December 2016
    When you clicked connect, did the app crash? If so, enable "debug" (instead of "Release") in visual studio, then hit F5 to compile/run the app.  When it crashes, visual studio will take you to the exact place in the code that caused the crash.
  • Vern
    Vern Member
    edited June 2020
    Yes the program stopped and came up with the attached error message. James, I have run it both with and without the FLEX-6500 running. The results are the same.

    Tks for listening.

    Vimageern
  • James Whiteway
    edited January 2016
    Vern, when the program first starts does it find your radio? There should be some of the boxes to the right of the connect button that get populated (serial number and model). Try running the program from Visual Studio, as the above message box looks like the one from Windows itself. That way, the error message(s) will be more detailed. And if you are running it from within Visual Studio, when the program breaks, you should get a highlighted line in the code itself showing where the break in the code that generated the error is located.
    That will help locate the problem.
    james
    WD5GWY

  • Vern
    Vern Member
    edited January 2016
    James,  Difficult to run the pgm from Visual Studio because Visual Studio is on one computer and SSDR is on another. I compile a new version and move the .exe to the other. You pointed out something I didn't realize, the error message I attached certainly must come from my Windows 10. 

    Attached is the error message I get when clicking the "Connect" button. The same mesage appears when other buttons are clicked.image
  • N7BCP
    N7BCP Member ✭✭
    edited November 2016
    As long as the PC with visual studio is on the same network as your flex, it should be able to connect. The error you see is from your test app, usually caused by setting or getting a property on an object that has not been assigned a value.
  • Vern
    Vern Member
    edited January 2016

    I am posting the error message from clicking Connect. One thing, what do you mean in your comment above when you use the word 'Release'? Hope the error msg answers the question.

    Vern


    image
  • James Whiteway
    edited January 2016
    Vern, in Visual Studio:
    image

    This is Visual Studio 2010, but the screen above is similar to 2015 Community Edition. At the top of the page there is a dropdown selection box. In this snapshot I have selected "Debug" that helps when you click the Run button (left pointing green arrow) the program will popup as normal and  you should be able to see some info about your radio in the boxes to the right of the "Connect and Exit" buttons in the program. If you don't see that info either your radio is off or not connected to the same network that the computer that is running Visual Studio and the test app. Or your Firewall is blocking the program from accessing the local network and connecting to the Flex.
      Finally, if you have not Rebuilt the application, (after rereferencing the Flixlib dll's) it is a good possibility that the problem is an incompatibility between dll versions.
    But, I would be certain that the computer that you are developing the program on can see your Flex radio. Otherwise, you won't be able to properly debug the program.
    james
    WD5GWY
  • James Whiteway
    edited January 2016
    Oh, one other thing, if you are simply copying the exe file to another computer and running it, the program will throw an error as the Flexlib dll's need to be included with the install. In order to use the program on another computer, you will have to create a Setup program in the Build Menu. Then, once you do that, you can copy the newly created setup and all it's associated files to the computer you wish to install on and it should run after installation. You will have to tell Windows Firewall to allow it to run with the first instance (first running) of the program.
    james

  • Vern
    Vern Member
    edited January 2016
    Hi Larry, been a while. My computers can see one another on the network. I move files back and forth on the network regularly. Is that telling me that my app on one computer should be seeing the device (6500) on the other computer RIGHT now  -  if things are implemented correctly??
  • Vern
    Vern Member
    edited January 2016

    Yes Charles all my computers (5) on my network are in communication. I pass files/folders back and forth frequently. Is my network ready for the kind of task I am asking; i.e. run my 6500 on another computer in the network.

    I thought that DLLs were imbedded - always. Well! The firewall ask it's question, I say OK and your app pops up but never displays any activity, all 'boxes' void of info. Also Charles, with your app present and the FlexLib DLLs present (in the same folder as you app??) and nothing happening to populate the boxes, I bring up SmartSDR and it grabs the 6500 and performs normally. The network in not setup I can only guess.

    TU Vern

  • Peter K1PGV
    Peter K1PGV Member ✭✭✭
    edited December 2016
    If your system with VS is on the same network as your radio... Yes. That's the point of the program: You're connecting to the radio over the network. It doesn't matter where SSDR is running no. It also connects to the radio via the network. If you have a NULL reference exception, you need to debug it. Set a breakpoint and single step through the code and see where the NULL reference occurs. Hope that helps, Peter K1PGV
  • James Whiteway
    edited January 2016
    Ok, Vern, it's a real head scratcher!  Dll files are not embedded. But, in an install setup, the Setup Program created by Visual Studio, includes the dll files in either sub-folders or in the same folder that the program will be installed in for Windows.
    And at the same time, the installer sets the Path to those files so that the program and Windows, knows where to find the dll's to use them when the  program runs.
      And you have cleared the question about Windows Firewall being the problem. It's not. I'm guessing you can run SSDR on any of the 5 computers on your network and each one (not all running at the same time) can see and operate your Flex 6500. If that's the case, and you get no info in the boxes before clicking Connect, then something else is blocking the test program from seeing your Flex 6500.
    Not too sure what it could be. Have you tried using the example program posted by Peter in this thread:
      https://community.flexradio.com/flexradio/topics/if-you-havent-tried-the-api-yet?topic-reply-list[se...

    If that works for you, then the test program should work as well. But, who knows? It's 2016, might be hexed!
    JAMES
    WD5GWY


  • Vern
    Vern Member
    edited January 2016

    All 9 buttons, when clicked, show that the '_thisRadio is null' & _thisRadio.xxxxxxx = '_thisRadio.ActiveSlice' threw an exception of type 'System.NullReferenceException'. I set a break point but it ends there - I am weak using the IDE. If there is a setup that permits additional info I am not aware of it.

    Yes, I discovered that the data that is generated by the 6500 is available on the LAN. I have two computers listen to the 6500 but the quantity of data they capture over the same time period is not the same. Is that the UDP effect? A wag.

    This message shows up in the mix; Additional information: Object reference not set to an instance of an object..

    Is my compiler in need of tweaking?

    TU Vern

  • James Whiteway
    edited January 2016
    Vern it means the program cannot see your radio on your network. I'm about certain it is because the wrong version of Flexlib dll's (older version) are being used by the program. As I said at the beginning, the program I posted the link to, was built with an older version of Flexlib. You have to remove all references to the old version and re-reference to the latest version(v 1.5.11) of Flexlib dll's. And then, after referencing the new version, rebuild the program.
    Without doing that, the program will not work.
    James
    WD5GWY
  • Vern
    Vern Member
    edited January 2016

    OK James! I think I have but will check and make sure. I will remove anything I have on my computer that deals with FLEXLIB and start over.

    Thank you Vern

  • James Whiteway
    edited February 2016
    Vern, when I say remove all references to older version of Flexlib, I mean doing so in Visual Studio after you have loaded the program. On the Right upper side in the section called SOLUTION EXPLORER there is a folder called REFERENCES. Expand it by clicking the little White arrow beside the REFERENCES folder.
    You'll get a list of all dll files being used by the program. Select ONLY those for FLEXLIB and it's associated files (dll's) . If you are not sure which ones to delete, look in the folder on your hard drive where you have downloaded (and unzipped) the latest version of Flexlib api, from Flex Radio's Downloads page.
    That way, you will have the correct names for the dll's you need to delete from the project in Visual Studio.
    The go back to Solution Explorer and select a dll and Right Click on it and select DELETE from the drop down menu. Do that for each dll that you need to remove. Then, if you have the latest version of the dll's on your computer, go to the top menu bar in Visual Studio and select PROJECT, ADD REFERENCE.
    From the box that pops up, select the tab that say's Explorer, navigate to the folder where you have the latest version of the Flexlib dll's and start adding each of the dll's you removed back to the project. (You'll have to do it one at a time till you have them all)
    After you're done with that, go to the BUILD menu and select rebuild. If all goes well, you will not see any build errors in the Immediate window.
    Then you can run the program from Visual Studio and it "should" find your radio (if it's on) and clicking Connect should populate the rest of the boxes in the program.
    Frequency changes are done by entering the freq in the box below the TUNE button ( 7.200 for example) and then clicking Tune.
    Hope this helps. I'm on the road and doing this from memory.
    James
    WD5GWY
  • Vern
    Vern Member
    edited January 2016
    James or whoever:    Iconic.ZIP?  Where do I find it? Using FLEXLIB Version 1.6.17,  added 'csproj' files to my project and ZIP file cannot be found. Visual Studio 2012. Believe everything else compiling.
  • Vern
    Vern Member
    edited January 2016
    Found one, installed same and now all is compiling. TU

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.