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.

Simple API Program

David Rudow
David Rudow Member
edited March 2020 in New Ideas
Hello everyone,
I recently got the opportunity to work with the FlexRadio API and I just wanted to post what I did to help anyone else trying to use the API.

https://github.com/Duvey314/KM4SWU_FlexRadio_Demo

For this project I had about a week to learn C#, UDP/TCP protocols, Visual Studio, API interface, and the FlexRadio 6500 hardware. If I can do it anyone can.

The steps I took to learn everything and get me to a point where I could get to where I got were:

1. Hook up the radio and read the UDP information using wireshark to make sure you are connected.

2. Learn C# on Visual Studio (this is what FlexRadio uses and supports I believe) through youtube tutorials.

3.Learn the Forms Application on Visual Studio to be able to used a window instead of command line.

4. Download the API files and build each .dll library individually before building the main Flexlib.dll file.

5. Then you should be able to hook up the radio and run the program after adding the flexlib.dll reference to your project.

The project is a simple windows form to communicate to the radio and get information from the radio like serial number, version, and model. The ReadMe file on the GitHub has some of the resources I used and some steps I had to take to get it working. I'll try and answer questions if y'all have them. Hopefully this is helpful to some of y'all.

Also, I would like to add an image of the working program but I don't know how to add a picture, if you'd like to see it just let me know how to do it and I'll add it.

Comments

  • James Del Principe
    James Del Principe Member ✭✭✭
    edited February 2020
    David, you have put a great deal of research time and effort into this project. Obviously, you are light years ahead of me in software. But I must ask you if this information is not already displayed in: Settings / Radio setup / Radio (first tab) gives radio SN, HW version, radio identification: Model (Flex 6500 in my case) and 'nickname'.
    In the second tab "Network" is the IP address and mask information. Am I missing something?

    OTOH, a program that "automatically tunes to the ISS station when it is overhead" would be awesome!!! 
    Thanks for your contributions.    73, Jim
  • David Rudow
    David Rudow Member
    edited February 2020
    Hey James,

    You make a good point. I was focused on getting something working in the week I had the hardware so that is as far into the project I was able to get. It is meant to mostly be a starting point for others looking to try out the API.

    If I ever get my hands on the 6700 series I would love to write the ISS tracking program. That was the original plan when I started but I had a lot of background work that I had to do to get to where it is. But hey, shoot for the moon and land on the ISS right?
  • James Del Principe
    James Del Principe Member ✭✭✭
    edited February 2020
    David, my hat is off to you for your ability to write this code. Why does it need to be a 6700?    Does it need two SCU's to work the ISS?    Maybe one for tracking and one for communications?      Jim
  • David Rudow
    David Rudow Member
    edited February 2020
    The transmit frequency of the ISS is 144.8 MHz and it's my understanding that the 6500 can't receive that frequency. -David
  • James Del Principe
    James Del Principe Member ✭✭✭
    edited February 2020
    True enough, David. You would need a transverter which are popular, common and mostly, not expensive.    But, to my knowledge, the 6700 also does not cover 2 meters.    Jim
  • James Whiteway
    edited February 2020
    The 6700 does cover 2 meters. But, with very low output. An amplifier would be needed for any serious use. James WD5GWY
  • James Del Principe
    James Del Principe Member ✭✭✭
    edited February 2020
    Thank you, James. We learn something every day.
  • John - K3MA
    John - K3MA Member ✭✭
    edited February 2020
    There is a third party program that works to tune in the Sats including ISS.  Do a search on the forum or google for FlexSatPC.
  • John - W3JFK
    John - W3JFK Member
    edited March 2020
    David,  thanks for the the sample application.  I was able to build the solution and get a running application.  I don't see any radios on appearing, but is that because I'm remotely connecting to my Flex?  I notice that a lot of samples use:

    static void Flex.Smoothlake.FlexLib.API.Init()
    Creates a UDP socket, listens for new radios on the network, and adds them to the RadioList
    I'm assuming this method will only work when the radio is on the LAN.  Is this correct?

    John
  • James Whiteway
    edited March 2020
    John, If you're on a LAN, either wired or over wifi, David's program should work fine, as long as your radio is on the same LAN. Remotely finding the radio is a bit more complicated. James WD5GWY
  • John - W3JFK
    John - W3JFK Member
    edited March 2020
    I'm remotely controlling the radio, it's not on my local area network.
  • James Whiteway
    edited March 2020
    That will make a difference. Hopefully, Mark will still have the code from his sample on github. James WD5GWY
  • Jason NR0X
    Jason NR0X Member
    edited March 2020
    Seriously Cool, man!!   I don't know jack about making a windows app, but I've been doing a lot of similar tinkering with Arduino IDE and ESP32 microcontrollers.  Keep it up!!
  • David Rudow
    David Rudow Member
    edited March 2020
    Hey Jason, Glad you like it. With all this time at home I've pulled out an arduino and started working on a small art project. It's fun stuff!
  • Jason NR0X
    Jason NR0X Member
    edited March 2020
    It's worth your time to check out the ESP32 modules. They're cheap and they have onboarding WiFi/bluetooth, not to mention a much faster processor and more memory.
  • David Rudow
    David Rudow Member
    edited March 2020
    Thanks for the suggestion, seems like a great fit for the project I'm working on now!
  • KD0RC
    KD0RC Member, Super Elmer Moderator

    I managed to get it working!

    (Sort of...)

    What I haven't figured out is how to subscribe to Slice, Panadapter, etc etc. In the following code snippet, I can see how to get radio and therefore _thisRadio. I don't know what to do to get slice (I didn't see anything like API.RadioAdded, except for slice info). The commented lines at the bottom are some of the things that I have tried based on a post from Eric. Anyone able to help? I included the source at the bottom of this post so that you can see the whole thing.

      public partial class frmMain : Form

      {

        private Radio _thisRadio;

        private Slice _thisSlice;

        public string NL = Environment.NewLine;

        public frmMain()

        {

          InitializeComponent();


          API.RadioAdded += API_RadioAdded;

          API.RadioRemoved += API_RadioRemoved;

          //API.ProgramName = "K1PGV's test Program";

          API.ProgramName = "KD0RC test Program";

          API.Init();

        }


        private void frmMain_Load(object sender, EventArgs e)

        {

          CheckForIllegalCrossThreadCalls = false;

        }


        private void API_RadioAdded(Radio radio)

        {

          _thisRadio = radio;


          modelTextBox.Text = radio.Model;

          serialTextBox.Text += radio.Serial.Substring(0, radio.Serial.Length - 4) + "****";

          radioIPAddress.Text += radio.IP;


          // The properties, such as Nickname and Callsign, can't be read

          // successfully until you've received a PropertyChanged event

          // for that property... this is done after connect.

          //

          radio.PropertyChanged += radio_PropertyChanged;


          _thisRadio.Connect();


          //_thisSlice = radio.TransmitSlice;


          //radio.SliceAdded += new Radio.SliceAddedEventHandler(radio_SliceAdded);

          //slice.PropertyChanged += new PropertyChangedEventHandler(slice_PropertyChanged);

        }



  • Alan
    Alan Member ✭✭✭✭

    Len

    It looks like you are seeing the Flex Discovery Packet.

    The command to subscribe to a slice is: C<xx>|sub slice all

    where <xx> is a command number you assign so you can associate the response to the command.

    Alan. WA9WUD

  • KD0RC
    KD0RC Member, Super Elmer Moderator

    Hi Alan, Yep, that is what I did in C++ in my TeensyMaestro, and it works great. In this case, I am trying to use C# with FlexLib and am struggling with understanding both (I grew up on PL/I, Fortran and COBOL, so C constructs don't come easily).

    Do you know how I would do the subscriptions in C# using FlexLib?

    I think that if I can get the Slice event handler established and working, I will be all set, but maybe there is more to it than that... To that end, I don't understand how to define a slice variable that isn't always null.

  • Alan
    Alan Member ✭✭✭✭

    Lets see, I had Fortran 101 in 1971......Then 40 years of linear controls. Now I am strictly Node-Red and a little Javascript.

    Stephen has made a great set of Node-Red nodes for talking to, commanding, and getting information from the Flex. You need to take another look.

    Alan

  • KD0RC
    KD0RC Member, Super Elmer Moderator

    OK, I finally got it... I found another GitHub example that I was able to get a (partial) understanding of, so now I can get slice info.

    I am at the "get it to work now, understand why later" stage of C# and the FlexLib.

    Being used to the API text commands, this is taking some getting used to... In any event, I think I am now able to experiment with what I have working at this point. The large textbox on the right is a debug window to make it easier to see radio data real-time, instead of going to the console window after the fact.

    I can only imagine the rookie C# mistakes I am making at this point, but it is fun to see it up and running.

  • KD0RC
    KD0RC Member, Super Elmer Moderator

    OK, I think I am getting the hang of FlexLib...

    Obviously not ready for prime-time, but here is an interesting (at least to me...) use case:

    In multiFlex mode, I can see both stations and who is on each frequency. In a multi-op contest using one radio, this might be useful to see where your fellow op is running. I only have a 6400, so I quick-n-dirty coded it for just two slices. It seems that to make something like this truly useful to the contesting community, it would need to accommodate 8 slices, and dynamically adjust the screen based on the number of available slices (and have a ton more features...).

    Note that I give each op the chance to totally mess up his operating partner with the A>B and A<B buttons, so this feature would have to have a way to be disabled. I also need to label the buttons based on the actual slice lettering.

  • allanmryan
    allanmryan Member
    Len, is the source code available for either of your sample programs that get slice information?

    73 Al, WW1RF
  • KD0RC
    KD0RC Member, Super Elmer Moderator

    Hi Al, I can't remember if I put the source out on GitHub. If I didn't, I will put it out there this evening and post the link here.

  • KD0RC
    KD0RC Member, Super Elmer Moderator

    Hi Al, here is a link to the sampler:

    Use the version with today's date.

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.