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 check the Help Center for known solutions.
Need technical support from FlexRadio? It's as simple as Creating a HelpDesk ticket.
Need technical support from FlexRadio? It's as simple as Creating a HelpDesk ticket.
Need the latest SmartSDR and Power Genius Software?
SmartSDR v3.1.12 and the SmartSDR v3.1.12 Release Notes. | SmartSDR v2.6.2 and the SmartSDR v2.6.2 Release Notes.
SmartSDR v1.12.1 and the SmartSDR v1.12.1 Release Notes. | Power Genius XL Firmware v3.4.16. | Power Genius XL Utility v2.2.10.
SmartSDR v3.1.12 and the SmartSDR v3.1.12 Release Notes. | SmartSDR v2.6.2 and the SmartSDR v2.6.2 Release Notes.
SmartSDR v1.12.1 and the SmartSDR v1.12.1 Release Notes. | Power Genius XL Firmware v3.4.16. | Power Genius XL Utility v2.2.10.
If You Haven't Tried the API Yet...
Leave a Comment
Categories
- 69 Community Topics
- 1.9K New Ideas
- 120 The Flea Market
- 5.4K Software
- 4.9K SmartSDR for Windows
- 35 SmartSDR for Maestro and M models
- 86 SmartSDR for Mac
- 143 SmartSDR for iOS
- 149 SmartSDR CAT
- 67 DAX
- 278 SmartSDR API
- 7.1K Radios and Accessories
- 5.8K FLEX-6000 Signature Series
- 554 Maestro
- 14 FlexControl
- 722 FLEX Series (Legacy) Radios
- 149 Power Genius Products
- 117 Power Genius XL Amplifier
- 10 Power Genius Utility
- 22 Tuner Genius
- 41 Shack Infrastructure
- 22 Networking
- 89 Remote Operation (SmartLink)
- 50 Contesting
- 127 Peripherals & Station Integration
- 62 Amateur Radio Interests
- 404 Third-Party Software
Comments
These steps worked for me using Widows 8.1 and Visual Studio 2013 but I think it would work also with VS 2012 - very unsure about earlier versions of VS.
Vern - you have been mentioning VITA but I'm going to keep this example simple and just explain how to create a new solution in Visual Studio and add the FlexLib and write a simple sample app that watches for the radio property changes and prints them out. My nest post will describe how I utilized the UDP data from the radio - this just covers the radio state date:
As Peter mentions - don't pick and choose cs files from the FlexLib - take the entire lot (Cat, FlexLib, TestFlexApi, UiWpfFramework/Util/Vita) and add all of these projects to a new solution along with your new project. You then choose what parts of FlexLib you use by referencing those classes, calling methods, and subscribing to events.
Download the FlexLib_API.zip
-Create a folder to hold the contents of the zip file and unzip it there.
-Start Visual Studio (I'm using VS 2013 but these instructions should be ok for 2012 and possibly earlier versions)
-Click File/New Project
-Select Other Project Types/Visual Studio Solution
-Once the new solution is opened, go to the Solution Explorer (Right side of IDE), right click and click Add/Existing Project
-Navigate to the first folder within the folder where you unziped the Flex Lib and select the .csproj file
-Repeat this step for each of the folders adding each .csproj to your solution
Note: There is a solution file (.sln file) in the Cat folder however it references a couple of projects that are not included in the zip -
the flexVSPInstaller - not sure why the cat project has the SLN so I'm suggesting you create a new solution for your work and add the Flexp
projects - mainly because it is easier to debug into the FlexLib source that way and they're handy to browse when there in the same
solution. You could build them in a seperate project and then just reference the binaries but when you're learning I'd go this route. I'm
sure someone will correct me
One you've added all the projects you can right click on the solution (root of the tree in the Solution Explorer pane in Visual Studio. It will
not build and you will get a complain that it can't find the Cat.ico file. For some reason the Cat.csproj is looking for a copy of Cat.ico in the root of the Cat folder and also under the Cat/Cfg/Lib
just find this Cat.ico reference in the Cat project root using the Solution Explorer and right click/delete and recompile the solution again and it should compile. Anyone else have this issue - I downloaded the FlexLib zip only a couple of days ago.
Create a new project for your code - right click on the solution explorer root - top most node in the explorer and select Add/New Project
Depending on what you want to accomplish choose an appropriate project type - if you want a GUI then select Visual C#/WPF Application, if you have some experience with the older
Windows Forms Application (Like the old VB style) then select that. These projects also exist in the Visual Basic language too and you can use it as well.
Now that you have your new project, navigate to it in the solution explorer (Right hand side of IDE), right click on the Referenecs node and select Add Reference. A dialog box will open.
Select the Solution/Project folder and check a box next to FlexLib and UiWpfFamework (even if your project doesn't use WPF, FlexLib has a class in this project that is used elsewhere so you'll
need to add a reference to it anyway).
Once you have your new project created, open the .cs file in your new project - if it is a WPF app, open MainWindow.xaml.cs, if it is a console application, open the Program.cs, if it is a
Windows Forms Application, open the Form1.cs.
To keep things simple I'm going to explain how to add the code to a .Net console application.
Open Program.cs in your new Windows Console Appliation project
At the top of Program.cs, add the line "using Flex.Smoothlake.FlexLib;" This will make the classes in the FlexLib available to your .cs file.
Now, go to the body (between the curly braces) of the Main function in your Program.cs file and start coding - below is the complete contents of my Program.cs file that waits for a radio to be
discovered, conects to the radio and watches all of the property changes. You can watch the console window while you play with the radio in SmartSDR to see the values
change.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Flex.Smoothlake.FlexLib;
using System.Reflection;
namespace TestFlexApi
{
class Program
{
static void Main(string[] args)
{
API.RadioAdded += new API.RadioAddedEventHandler(API_RadioAdded);
API.ProgramName = "My Program";
API.Init();
Console.WriteLine("Hit return to quit");
Console.ReadLine();
}
private static void API_RadioAdded(Radio radio)
{
Console.WriteLine("Found radio: {0}", radio.Model);
radio.PropertyChanged += radio_PropertyChanged;
radio.Connect();
}
static void radio_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
var radio = sender as Radio;
if (radio != null)
{
var val = typeof(Radio).GetProperty(e.PropertyName,
BindingFlags.Public
| BindingFlags.Instance
| BindingFlags.IgnoreCase).GetValue(radio, null);
Console.WriteLine("Property: {0}, Value: {1}", e.PropertyName, val);
}
}
}
}
My oh my, gents? I'm working.....
Vern
Our goal, Vern, is to keep you busy. And if not busy, at least confused!!
:-)
Peter K1PGV
I am using Microsoft Visual Studio Express (Free version) 2013. My only experience in programming is Delphi 6 & 7 with Windows 7. About 35 yrs of programming but never formally trained. Not an excuse!
Should be a piece of cake to keep me confused....
Vern
using System;using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Flex.Smoothlake.FlexLib;
using System.Reflection;
using System.Windows;
namespace TestFlexApi
{
class Program
{
static Radio rig;
static Slice sl;
static void Main(string[] args)
{
API.RadioAdded += new API.RadioAddedEventHandler(API_RadioAdded);
API.ProgramName = "My Program";
API.Init();
Console.WriteLine("Hit return to quit");
Console.ReadLine();
}
private static void API_RadioAdded(Radio radio)
{
if (rig == null)
{
rig = radio;
Console.WriteLine("Found radio: {0}", rig.Model);
rig.PropertyChanged += radio_PropertyChanged;
rig.SliceAdded += radio_SliceAdded;
}
}
static void radio_SliceAdded(Slice slice)
{
if (sl == slice)
{
slice.DAXChannel = 1;
var audioStream = rig.CreateAudioStream(slice.DAXChannel);
audioStream.RXDataReady += audioStream_RXDataReady;
audioStream.RequestAudioStreamFromRadio();
}
}
static void audioStream_RXDataReady(AudioStream audio_stream, float[] rx_data)
{
Console.WriteLine("DAX Channel {0}, Data: {1}", audio_stream.DAXChannel,
rx_data.Aggregate(string.Empty, (s, i) => s + "
" + i.ToString()));
}
static void radio_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
var radio = sender as Radio;
if (radio != null)
{
var val = typeof(Radio).GetProperty(e.PropertyName,
BindingFlags.Public
| BindingFlags.Instance
| BindingFlags.IgnoreCase).GetValue(radio, null);
if (val != null)
{
Console.WriteLine("Property: {0}, Value: {1}", e.PropertyName, val);
if (e.PropertyName == "Status" && val.ToString().StartsWith("Available"))
{
radio.Connect();
}
if (e.PropertyName.Equals("SlicesRemaining"))
{
if (rig.SlicesRemaining > 0 && sl == null)
{
sl = rig.CreateSlice(14.2, "ANT1", "USB");
sl.RequestSliceFromRadio();
}
}
}
}
}
}
}
I recommend looking at the Radio.cs file in the FlexLib to get a feel for how it works.
-Larry
The red lines, underlining some words, shown below, in the pgm listing below, are not part of my C# program. Has something to do with the reflector behavior - I think.
Tomorrow I will concentrate on your suggestions. Closing in on bed time. I didn't need to say that!
myConsoleProgram:
using System;using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; //ERROR: -----------------------------------------------
using Flex.Smoothlake.FlexLib; //ERROR: 'Flex' has a blue squiggly line under it.
// ERROR: land is the only error?
//ERROR: ------------------------------------------
using System.Reflection;
using Peter_Larry;
namespace TestFlexApi
{
class Program
{
static void Main(string[] args)
{
API.RadioAdded += new API.RadioAddedEventHandler(API_RadioAdded);
API.ProgramName = "My Program";
API.Init();
Console.WriteLine("Hit return to quit");
Console.ReadLine();
}
private static void API_RadioAdded(Radio radio)
{
Console.WriteLine("Found radio: {0}", radio.Model);
radio.PropertyChanged += radio_PropertyChanged;
radio.Connect();
}
static void radio_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
var radio = sender as Radio;
if (radio != null)
{
var val = typeof(Radio).GetProperty(e.PropertyName,
BindingFlags.Public
| BindingFlags.Instance
| BindingFlags.IgnoreCase).GetValue(radio, null);
Console.WriteLine("Property: {0}, Value: {1}", e.PropertyName, val);
}
}
}
}
You talked about a solution file named .sln in the Cat folder. I do not have that! Therefore I did not do any of the suggestions in that paragraph. Good or bad on my part? And I have seen no correction on your good suggestion, hi.
Compiled the .csproj files and it was not happy. It was looking for a CAT item but not the the Cat.ico. I deleted, one by one, any ref to Cat.ico in 3 or 4 files of the CAAT folder with no success. The result of the solution build was:
"Error 1 Metadatafile 'C:UsersVernDesktopFLEXLib2CatAsyncSocketsV2inDebugAsyncSocketsV2.dll' could not be found".
I will next create a new project for my code while i await your comments(s).
TU Vern
I thought I may be in between a rock and a hard place with the advice coming from a couple of sources. So don't be offended - your not forgotten. After things settle with Larry's effort I will be back.
TU Vern
Clear as mud?
Vern
Is this what you had in mind? All associated projects, etc, are handy for review.
Vern
Vern
My thanks to you, Larry and ALSO James who is on the road again. James showed me the way to making and loading the necessary .dll's.
Vern
Many thanks for posting the above code! With the above and help of my twin (Mr. Windows UI) we (he in actuallity) was able to get it working.
There was one exception thrown due to an illegal cross threading. The following line of code:
CheckForIllegalCrossThreadCalls = false;
was copied from:
Form1_Load()
to:
API_RadioAdded()
and then no exception occurred. Running on Visual Studio 2015, C#. As it looks like Form1_Load is not called does anyone know is this due to change in WPF or something else?
_..--
k3Tim
I have run Peter's code (and used it as a base to start my own program) and it does work. I have run it in VS 2010 and VS 2015. It could be an issue with WPF, if you are using this in a WPF program instead of a WinForms app.
If you are using Winforms, Form load has to load in order for your program to work.
james
WD5GWY
I'll check that out. The top level installer / project file did not work since VS 2015 was several editions removed from the project version used for the Flex API.
Than ks
Tim
Dan --- KC4GO
Cheers
Vern