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.

Someone Willing To Share Sample Code?

K1FR
K1FR Member ✭✭
edited June 2020 in SmartSDR API
Apologies for repeated post - meant to post this in the SmartSDR API catagory:

Afraid this old, amateur C++ programmer is suffering from a way too steep learning curve trying my hand at getting the FlexLib API up and running!  Using VS 2013.  Would greatly appreciate anyone willing to send along any sample code - just the first steps of getting the library loaded, compiled along with a some code that does something very basic like connect to radio and read a value or something.  Just looking for those first steps right now.  My background with C++ and Microsoft Foundation Classes is of little help as I try to learn C#, .NET and the API.

Have done my best to find this in the forum.  Apologies in advance if overlooked something obvious.  The really good paper from Bob on the CAT program offered some help, but was too advanced for my poor old mind.

Many thanks for any help at all.

73, Tom K1FR
«1

Answers

  • James Whiteway
    edited September 2015

    First thing you need to do is to compile the Flexlib into a dll. Download Flexlib and load the project as you would any project. After you unzip Flexlib, open Visual Studio and navigate to the folder where you unzipped the Flexlib source code. Load the file named: Flexlib.proj. After the project loads, select "Build" from the main menu at the top of Visual Studio. From the drop down menu, select "Build Flexlib". One you do that, you can use the code located in this link:
     https://community.flexradio.com/flexradio/topics/if-you-havent-tried-the-api-yet

    And build a basic interface to read your radio's properties. The code sample posted by K1PGV
    works and really has helped me get a start. I still have issues, but, those are more "pilot error" and anything else. I'm still relearning C# and slowly making progress. With your background in C++, you should be able to come up to speed fairly quickly.
    Have fun and keep posting here as it helps everyone trying to do the same thing.
    james
    WD5GWY

  • James Whiteway
    edited February 2017
    Tom, sent you a zip file containing a project I put together using K1PGV's example code posted in the link above. If you run it, without SmartSDR running it will only show basic info, like Radio Model , Name, Callsign, Radio Serial Number, IP address of the radio and the radio's serial number. If you run it with SmartSDR running, you will see a flag show on the bottom right of your screen in Windows showing the IP address of a Client program connecting to the radio along with SmartSDR.
    Then, the program will display the current Slice Frequency, Mode, RF power output.
    Maybe, that will help you get going. A BIG thanks to Peter, K1PGV for the code sample he posted.
    james
    WD5GWY

  • K1FR
    K1FR Member ✭✭
    edited December 2014
    James:  Thanks <very> much for the help!  Looking forward to giving this a try when I get home today.   Have to admit I think I once saw the post you referenced above but must have somehow lost track of it as things progressed. Had found myself going in circles of increasing confusion.  :)   Will let you know how it goes.

    For some reason, the zip file did not make it.  Please resend if you get a chance - you can try my email at  K1FR@arrl.net or tm.stuff@verizon.net.

    Thanks again, 73, Tom K1FR

  • James Whiteway
    edited December 2014
    Ok Tom, just resent the file to your verizon email address. Maybe, the ARRL does not allow attachments.
    james
    WD5GWY
  • K1FR
    K1FR Member ✭✭
    edited December 2014
    James:  Thank you!  Got the .zip and have successfully compiled and run your code.  You have me back on the learning curve. Looking forward to the process.  

    73, Tom K1FR
  • James Whiteway
    edited December 2014
    Glad to hear that Tom. I find learning about the Flexlib and relearning C# to be a bit of a challenge, but, what fun would it be otherwise?
    Keep posting and let everyone know your progress.
    james
    WD5GWY

  • Roger Sjölin
    Roger Sjölin Member
    edited July 2015
    Hi James
    I am trying to figure out to use Flexlib together with Visual basic and Visual c#.
    I have now an application which connect correctly to the radio and
    present the radios version, serial number and model.
    I now want to read the slice frequency etc but I cant get it to function.
    I would be very happy if You will share Your example mentioned above to me.
    Regards
    Roger Sjölin SA0AND
    rogersjolin@gmail.com
  • K1FR
    K1FR Member ✭✭
    edited July 2015
    Roger:  Sure thing!  When I get back to my computer with the C# stuff on it later today I will send you a .ZIP with my program.  There are far better experts than I on this list.  I am pretty much a beginner, but hope you will get something out of my sample.  Good luck and let me know if you have questions.

    73, Tom
    K1FR
  • Peter K1PGV
    Peter K1PGV Member ✭✭✭
    edited June 2020
    There are actually several "starter" samples posted in the API Section, but they're kind of hard to locate.  You can find at least one here, from several months back.
  • K1FR
    K1FR Member ✭✭
    edited February 2017
    Roger:  And you just heard from one of the real experts - Peter!  I just sent you a direct email with my sample utility code.  Good luck.

    73, Tom
    K1FR
  • James Whiteway
    edited July 2015
    Roger, I have emailed you the same test project that I mentioned in the earlier post. Hopefully, you won't have any trouble receiving it. It is not the latest version of my test project, but, it should help you with the things you mentioned. It is a C# only version. I have fallen behind on keeping the Visual Basic version up to date. Mostly because I have spent what time I have available, (weekends mostly when not doing "honey do's") attempting to get a working panafall going. (haven't been too successful with that endeavor just yet!) Good luck and post your questions here. And as I stated in my email to you, you are welcome to email me anytime you wish. But, it will be on the weekend when I can answer most of the time.
    james
    WD5GWY
     
  • James Whiteway
    edited July 2015
    Roger, just got back home and your email address bounced just like Tom's did when I emailed him to his gmail account. It appears gmail does not allow attachments with any sort of executable code in them. If you have another email address that will accept an attachment with code in it, drop me a message : jjames700@earthlink.net
    james
    WD5GWY

  • James Whiteway
    edited September 2016
    Ok, Roger, I have resent the zip file to the new email address you sent me. Hope you get it this time.
    james
    WD5GWY

  • Roger Sjölin
    Roger Sjölin Member
    edited July 2015
    Thanks James.
    Your example will be a good help for me to understand the c# programming of the radio.
    Roger SA0AND

  • Roger Sjölin
    Roger Sjölin Member
    edited April 2017
    Ok Now I have managed to run K1PGV example and I have also managed to
    get my own application (similar to K1PGV) to run without problems in visual basic express 2013.
    But both examples need that SSDR is started before I can get for instance freq, power, meter info.

    Is there a way to start SSDR from inside my code? I know that it is a workaround so I dont need to
    create my own panadapter/waterfall which I think is a little to complicated for me.
    I have tried the process.start command but I then have to connect the radio through the startup
    form of SSDR. Can it be done automatically?.
    /Roger SA0AND
     


  • James Whiteway
    edited June 2020
    Roger, At the top of the program code where it says: API.Program Name = "K1PGV's test program"; Add the following: API.isGUI = true; That will tell Flexlib to send all events, including Panadapter and Waterfall events, to your program. With the above you won't need SSDR running to receive all events and to control the radio. James WD5GWY
  • Roger Sjölin
    Roger Sjölin Member
    edited August 2015
    Ok I have tried that but nothing happens. If I start SSDR first and then run my code all is fine. I got all data from SSDR and I can manipulate SSDR with new slice, remove slice, change freq etc.

    But I want to start SSDR from inside my code and get the same presentation as if I started SSDR first and then run my code.

    Hope my question make sense to You.
    /Roger SA0AND
  • James Whiteway
    edited August 2015
    Roger, the info I posted should have worked. Here is a link to a bare bones example that works. You need a form and two buttons. You will have to copy and paste the code into a new project to use it. All it will do is print "Event X fired" (X being the name of the event) It is very basic with no other functions. https://community.flexradio.com/flexradio/topics/start-radio-without-ssdr Let me know if that helps. James WD5GWY
  • James Whiteway
    edited August 2015
    One other thing, the API. isGUI = true; is case sensitive. James
  • Roger Sjölin
    Roger Sjölin Member
    edited August 2015
    Yes thats ok. But what I want is a display like this
    image
    My code can then manipulate this display with new slice , freq etc.
    And therefore I want to start SSDR normal display from inside my code.
    Do You understand what I am trying to do? I am not trying to solve the same
    issue as I understand that You are dealing with, to make a complete new panadapter/waterfall display or have I misunderstood that?
    I am very grateful for Your help.
    /Roger SA0AND


  • James Whiteway
    edited August 2015
    Flexlib gives you the data to create a Panafall. It does not create one on the screen for you. You have to take the data from the radio and create your own. James WD5GWY
  • Roger Sjölin
    Roger Sjölin Member
    edited August 2015
    Yes I understand that but
    my question is how I can start SSDR the normal way with c# or visual basic code.
    As I mentioned before I have tried "process.start" and it works and I get the normal startup form and I have to press connect. I hope there will be a way with code
    to start SSDR without that startup form.
    /Roger SA0AND
  • Peter K1PGV
    Peter K1PGV Member ✭✭✭
    edited December 2016
    Put another way (for the Flex Developers): Is there a command-line argument to SSDR that'll allow one to select the radio to which to connect when SSDR is started, thus avoiding the Connect dialog box?
  • James Whiteway
    edited August 2015
    Ok Roger. That makes sense to me now. @ Peter, I think the reason for the selection Dialog box is to support more than one radio on the network during the Radio Descovery phase. Flex could make an option in Settings, for single or multiple radios. And if only going to be one available, SSDR could bypass the Selection Box on startup. Only problem I could see, even on a home network, is a delay in finding the radio and possibly not making the connection. I have seen a momentary delay in my radio showing up in the dialog box, at times. But, by the time it registers with me, the radio shows available. I think too, that the Dialog box display showing, gives the radio and SSDR more time to sync up together for a solid connection. James WD5GWY
  • James Whiteway
    edited August 2015
    Roger, I apologize for not understanding what you wanted to do. Like you found out, Proccess.Start is probably the only way to do what you want. But, until FRS does something like I suggested, (a checkbox for auto connect on startup in the Settings Menu) I think you are stuck doing what you are doing. Again, my apologies for not understanding what you wanted to do. James WD5GWY
  • Roger Sjölin
    Roger Sjölin Member
    edited August 2015
    No problems.
    Can sometimes be difficult to explain things in a different language.
    So many thanks to K1PGV.
    James, I hope you succeed in your project to create your own panadapter / waterfall and that You continue to share your experiences. For those interested, my code will also be available.
    /Roger SA0AND
  • James Whiteway
    edited August 2015
    Roger, I just remembered a Visual Basic command called, SendKeys, that you "might" be able to use with Proccess.Start , to send a Mouse Click (or Tab +Enter key to move Focus to the needed entries in the Connect popup box) and start SSDR from your app. I looked on MSDN and it appears that VB still supports it. I don't know if C Sharp has a similar function. Also, you may need to get the Windows Handle for SSDR's connect popup box as well. I think it can be done. But as Peter said some time ago, "it will be pure hackery" and not a real clean solution as it would be is SSDR supported an Auto Connect feature out of the box for single radios on a LAN. Just a couple of ideas that you might be able to try. James WD5GWY
  • James Whiteway
    edited August 2015
    Roger, C # does support SendKeys! Hope it does what you need. James WD5GWY
  • James Whiteway
    edited August 2015
    Roger, here's an idea on how to go about doing what you want( no code as I'm on the road and away from my computer) First thing I would do is to start SSDR ( normally without Visual Studio or your app running). When the Connection popup box appears, using your keyboard(not your mouse) look forst at the popup box and see where the Focus is, (should be around the box itself,,,,but possibly elsewhere on the form,,, a control maybe) Then using the TAB key on your keyboard and TAB from one control to the next. That will give you the Tab Order from the time the popup box appears.(and hopefully repeats the same each time SSDR is started) Once you know the Tab order from startup, you can Tab to the Radio List box on the left side of the form, and pause your code long enough for the radio to show Available. Then while Focus is on your radio , hit enter. TAB to the Connect button ,pause and hit Enter. If SSDR starts like normal, you are in business. You can do all the above in code from your app(at Form Load might be best) using Proccess.Start to start SSDR, then pause (using a short timer) then using the Sendkeys command(see MSDN for command sequence and command list) send TAB(as many times as needed to move Focus to your radio in the list) pause again for a moment with a timer to allow your radio to become Available, then Sendkeys the ENTER command. Repeat the above to get to the Connect button. Then pause a bit (timer again) to allow SSDR to fully load and display. Then, in your code let your app finish loading. (be sure isGUI is set to false in your app.) And you should be all set to use your program to control SSDR. Several steps to get what ypu want. But, once done in code(you'll have to experiment with the timer settings to get it right) it won't take hardly any time to start SSDR and your app. Hope all this helps. James WD5GWY
  • Roger Sjölin
    Roger Sjölin Member
    edited August 2015
    James,

    Yes I have managed to get it to work.
    Here is the code:

     Private Declare Function BringWindowToTop Lib "user32" (ByVal hwnd As Long) As Long

    Private Sub start_SmartSDR()

            Dim ProcID As Process
            ProcID = Process.Start("C:Program FilesFlexRadio SystemsSmartSDR v1.4.16smartsdr.exe", AppWinStyle.NormalFocus)

            Threading.Thread.Sleep(1000)
            Dim iret As Long
            iret = BringWindowToTop(ProcID.Id)

            SendKeys.SendWait("{TAB}")
            SendKeys.SendWait("{TAB}")
            SendKeys.SendWait("{TAB}")
            SendKeys.SendWait("{TAB}")
            SendKeys.SendWait("{TAB}")
            SendKeys.SendWait("{PgDn}")
            SendKeys.SendWait("{TAB}")
            SendKeys.SendWait("{TAB}")
            SendKeys.SendWait("{TAB}")
            SendKeys.SendWait("{ENTER}")

        End Sub

    Many thanks
    /Roger SA0AND


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.