Someone Willing To Share Sample Code?

  • 2
  • Question
  • Updated 2 years ago
  • Answered
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
Photo of K1FR

K1FR

  • 106 Posts
  • 9 Reply Likes

Posted 3 years ago

  • 2
Photo of James Whiteway

James Whiteway

  • 831 Posts
  • 181 Reply Likes
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
Photo of James Whiteway

James Whiteway

  • 831 Posts
  • 181 Reply Likes
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
Photo of Roger Sjölin

Roger Sjölin

  • 14 Posts
  • 2 Reply Likes
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
Photo of K1FR

K1FR

  • 106 Posts
  • 9 Reply Likes
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
Photo of Walter Jonat

Walter Jonat

  • 1 Post
  • 0 Reply Likes
Dear James,
it would be nice if you can send me the .zip file too.
73, Walter (DK1ZA)

walter.jonat@uksh.de
Photo of James Whiteway

James Whiteway

  • 831 Posts
  • 181 Reply Likes
Here is a link to some sample code :
https://www.dropbox.com/s/ran9z0mjk3t...
Photo of James Whiteway

James Whiteway

  • 831 Posts
  • 181 Reply Likes
I forgot to mention, you will need to Un-reference all the references to the Flexlib api's because this sample uses an older version of Flexlib.api. After removing the references to the old api's just add reference to the latest version of the api. There are several examples including a video by Mark, WS7M, that explain what to do.
James
WD5GWY
Photo of Peter K1PGV

Peter K1PGV, Elmer

  • 541 Posts
  • 314 Reply Likes
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.
Photo of K1FR

K1FR

  • 106 Posts
  • 9 Reply Likes
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
Photo of James Whiteway

James Whiteway

  • 831 Posts
  • 181 Reply Likes
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
 
Photo of James Whiteway

James Whiteway

  • 831 Posts
  • 181 Reply Likes
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
Photo of James Whiteway

James Whiteway

  • 831 Posts
  • 181 Reply Likes
Ok, Roger, I have resent the zip file to the new email address you sent me. Hope you get it this time.
james
WD5GWY
Photo of Roger Sjölin

Roger Sjölin

  • 14 Posts
  • 2 Reply Likes
Thanks James.
Your example will be a good help for me to understand the c# programming of the radio.
Roger SA0AND
Photo of Phil m0vse

Phil m0vse

  • 204 Posts
  • 38 Reply Likes
James, I would love a copy of this as I am looking where to start with Flex development! If you are OK to send it to me, my address is phil@m6esv.uk
73 Phil
Photo of James Whiteway

James Whiteway

  • 831 Posts
  • 181 Reply Likes
Hi Phil, I am out on the road right now(I drive a truck) but when I get home Friday evening, I will send you a copy of the test program. It's not up to date as far as where I am in my main app. But, it should give you some of the basics. It started with a sample posted by K1PGV , Peter, and has some things I have added. Post questions in the API Forum. (or email me if you need to) Someone will help you as you run into snags.
James
WD5GWY
(Edited)
Photo of Roger Sjölin

Roger Sjölin

  • 14 Posts
  • 2 Reply Likes
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
 
Photo of Paul Masters

Paul Masters

  • 1 Post
  • 0 Reply Likes

Hi Roger,

I just got my 6300 last week and have been able to get a c# example to connect to the radio. But have had no luck with a VB version. Do you have any code I could look at?

Paul KB3ZYB

Photo of James Whiteway

James Whiteway

  • 831 Posts
  • 181 Reply Likes
Do a search in the API Forum for Visual Basic. You should find a post there from another member with a link to a download for a test app similar that should help you with the syntax etc to use with VB to subscribe to events etc. Be sure to Import the latest version of the different Flexlib dll's. If you don't, your app will not see the radio on the network. I tried for a while to keep both a C# and a VB version of all my test programs for working with the Flexlib. But, I found that too cumbersome and it made relearning C# even harder. So, I abandoned that idea and have stuck with C#. I find that I really like C# the more I use it. I do plan to learn Java at some point for Android development. But, that won't happen till I have got a smooth working waterfall in my current project.
James
WD5GWY
Photo of Roger Sjölin

Roger Sjölin

  • 17 Posts
  • 2 Reply Likes
Hi Paul,
If You email me i can send You a code example.
rogersjolin@gmail.com

/Roger SA0AND
Photo of James Whiteway

James Whiteway

  • 831 Posts
  • 181 Reply Likes
Roger,
I forgot that you were using VB!
James
WD5GWY
Photo of James Whiteway

James Whiteway

  • 831 Posts
  • 181 Reply Likes
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
Photo of James Whiteway

James Whiteway

  • 831 Posts
  • 181 Reply Likes
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
Photo of James Whiteway

James Whiteway

  • 831 Posts
  • 181 Reply Likes
Roger, C # does support SendKeys! Hope it does what you need.
James
WD5GWY
Photo of James Whiteway

James Whiteway

  • 831 Posts
  • 181 Reply Likes
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
Photo of Roger Sjölin

Roger Sjölin

  • 1 Post
  • 0 Reply Likes
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 Files\FlexRadio Systems\SmartSDR v1.4.16\smartsdr.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
Photo of James Whiteway

James Whiteway

  • 831 Posts
  • 181 Reply Likes
Roger, glad it worked. Thanks for sharing
James