.NET/Python developer resources

Talk about anything else here.
tyler.montney
Posts: 4
Joined: Thu Feb 13, 2020 12:45 am

.NET/Python developer resources

Post by tyler.montney » Thu Feb 13, 2020 12:48 am

I bought https://www.amazon.com/gp/product/B011H ... UTF8&psc=1 in the hopes to pull RDS data from FM radio. I'm primarily proficient in .NET, but can get by with Python. I searched the site and the forum, didn't find much. Is there a sticky or a guide to reference?

https://github.com/martinmarinov/rtl_tcp_andro- This looks nice, seems to interface over TCP/IP. However, it's Android.
https://github.com/librtlsdr/SharpRTL Looking at this now, might be what I'm looking for.
https://rftap.github.io/ Not sure what this is, seems to only reference programs like Wireshark. Seems to make sense of the data, but unsure how to leverage in .NET/Python.
Plugin https://github.com/EarToEarOak/SDRSharp-Net-Remote seems good, but doesn't appear to grab the RDS data (just if it's playing something).

Edit: I looked into how the plug-in was working https://github.com/EarToEarOak/SDRSharp ... /Parser.cs. It references SDRSharp.Common.ISharpControl. This interface has a property RdsRadioText. Seems like what I'm after, but not sure yet.

rtlsdrblog
Site Admin
Posts: 2563
Joined: Mon Nov 19, 2012 11:54 pm

Re: .NET/Python developer resources

Post by rtlsdrblog » Thu Feb 13, 2020 3:16 am

Do you really need to program something? Why not use existing programs like RDSSpy?

tyler.montney
Posts: 4
Joined: Thu Feb 13, 2020 12:45 am

Re: .NET/Python developer resources

Post by tyler.montney » Fri Feb 14, 2020 4:10 am

Looks like it has a plug-in named Radiotext Logger, which would do what I'm looking for. Only issue was when browsing rdsspy.com, it was blocked by my AV for Trojans. That doesn't happen too often.

Honestly, I'm very close to making this work. I'm trying to write my own plug-in, but getting stuck on restarting to apply changes: SDRSharp.MyPlugin.Plugin.Close() null reference. This is all .NET, but I'm writing in VB rather than C# (not sure if that'd make a difference).

Edit: Never mind. It seems like SDR# likes to cache new plug-ins. I noticed I made a change to my magic line, and yet when adding a new copy it retained the old key name. I had to delete the DLL in C:\SDRSharp.

tyler.montney
Posts: 4
Joined: Thu Feb 13, 2020 12:45 am

Re: .NET/Python developer resources

Post by tyler.montney » Fri Feb 14, 2020 6:11 am

Is there any way to attach a debugger to a running instance of SDR#? I just can't figure it out. I sometimes get my plug-in to load, then it won't load and pulls that null reference when calling Close.

tyler.montney
Posts: 4
Joined: Thu Feb 13, 2020 12:45 am

Re: .NET/Python developer resources

Post by tyler.montney » Sat Feb 15, 2020 4:09 am

I think I figured it out. The plug-in manager, I realize, itself is a third-party plug-in. It does not cleanup well. I was wondering why I could get my plug-in to load initially, but not after a few runs (even after reinstalls). This is because despite removing the plug-in, the manager doesn't remove DLLs or the settings. Turns out, my plug-in broke when it would start the REST server at SDR launch (but wouldn't break if I launched it once everything was loaded). So when I reinstalled, the checkbox setting was still there and would try to launch my REST server. Wrote a couple PS scripts to cleanly add/remove plugins and helped a lot.

I've also noticed SDR# does not handle exceptions well. If a plug-in has a problem, it'll throw an unhandled exception. If a plug-in has a problem, SDR# should unload it. Unfortunately, if it doesn't initialize correctly, SDR# still tries to run the Close command as if it's working fine. There's no indication a plug-in is null at startup.

EddieMac74
Posts: 60
Joined: Wed Feb 07, 2018 8:00 am
Contact:

Re: .NET/Python developer resources

Post by EddieMac74 » Sat Feb 15, 2020 8:53 am

Hello, just though I would make some observations here...
The plug-in manager, I realize, itself is a third-party plug-in. It does not cleanup well.
I designed the Plugin Manager. It does exactly what it is supposed to do. It leaves behind the original DLL files because the plugin manager is designed for (by specific requests from) many users in the SDR# community who wanted the ability to have several different configs for their plugins and load / unload them at will. It is kind of hard to load a plugin if the DLL was deleted. The original beta featured the ability to delete the plugins, but some people ended up corrupting their installs by deleting critical dll files. Everything in the plugin was by purpose.
I've also noticed SDR# does not handle exceptions well

SDR# handles IT'S OWN exceptions properly. It does not, and was not designed to handle exceptions in third party plugins. That is the responsibility of the plugin maker. If you are using the interface properly and implementing your own exception handling in your code this should not be a problem.

You are correct in stating that SDR# will not load a plugin that throws exceptions. This was by design I believe as the interface is proxied (and for good reason).
SDRSharp.MyPlugin.Plugin.Close()
You can not "Close" your plugin. This call (void) from SDR# through the interface is simply to inform you that SDR# ITSELF is closing and allows you to do finalization and preform unmanaged code clean up. (Release resources....blah blah blah.)

Again, .NET does NOT allow unloading of dynamically loaded assemblies. Therefore if you want to change something in your plugin and view the results you either have to properly configure your debugger and debug it during design time OR you can use your own code to restart the app thereby unloading the assemblies, but remember, someone may have multiple running instances of SDR# so you need to know which instance to close or else your going to end up shutting them all down.

SDR# does not contain any interfaces that contain any void that allow you to restart it. (That I am aware of anyway).

Also, you NEED to program your plugins in C# NOT VB or you will not be able to do anything of more use than tuning the radio and adjusting the bandwidth or preforming simple GUI tasks. Any use of DSP or data processing of the IQ, Audio or RDS streams and the like requires the UNSAFE directive in your compiler which VB WILL NOT allow (See UNMANAGED MEMORY)

THERE IS NO USER REFERENCE for the API for SDR# there are many reasons for this which you can learn through research on this forum and on the Airspy.io forums.

The libraries and interfaces in the API are very self explanatory.

OK, so I will give you a bit of a run down on plugin programming here:

1) Use C#

2) Use C#

3) In your designer, use XCpy to copy your .dll files and .pdb files into the SDR# root directory post build.

4) Configure your build action to launch SDR#.exe after successful compile and the debug session will start with your plugin code once the app starts loading your dll. Then you can step through your own code and see what's up.

5) There is an error log in the SDR# root directory (usually) when SDR# happens to crash with the dirty low down on wwhat caused the crash.

6) The "MagicLine" as it is so called in the "plugin.xml" file is there to point SDR# to the root namespace and entry point of your plugins dll. In order for SDR# to even see it you MUST precede your namespace with SDRSharp. or nothing will work. The "plugin name" attribute is arbitrary but my plugin manager just uses the entry point name of the plugin.

7) Don't forget to code in C#

8)Three dlls are key to designing your own basic plugins for SDR#

They are:

SDRSharp.Common - The ISharpPlugin interface to structure your plugin & the ISharpControl interface to allow to to recieve and send commands and events from / to SDR# for tuning the detectors, changing detectors etc,etc,etc.

SDRSharp.Radio - has many many many interfaces to work with DSP, including demodulators, buffers of all types, the base type for Complex numbers, filters, converters, FTT etc, etc. AND a Utils library used for conversion of types used in SDR# and a common place for all users to store their plugin settings (ie: the SDR# config file). It make your coding much more standard and easier to use.

SDRSharp.PanView - holds the definitions, objects and interfaces for using and creating the Spectrum Analyzers, the Waterfalls and the definitions for the custom events they use.

Just about anything you need to make a plugin for SDR# has been provided for you by the author.

KEY NOTE HERE: There is a unwritten social contract that when you use SDR# and it's associated libraries, one of which is - DO NOT try to circumvent the proxie by using reflection or other nefarious tricks. This is a big 'No No'. ( Among other things.)

AirSpy.io has a lot of great programmers on there that will also help you out if you have a new question just as they do here. Search through all the previous posts. your questions might have already been answered.

By the way, my name is Eddie from SDRPlugins.com. I wrote a lot of plugins for SDR#. With NO knowledge from the start. If you need any direction I can offer my knowledge (as it is - still alot I don't know) to help you out where possible.

No one really helped me and I had to learn everything FROM SCRATCH. Which of course is the most rewarding way ;)

If you review some of my previous posts on here, you will see references to other plugin coders websites with lots of helpful tips. Also, if you look in the downloads section of the AirSpy website, there is a package towards the bottom with 3 plugins in it that - if you open them in your desginer will teach you very quickly how things are done in SDR#. There is an IF Spectrum analyzer (Zoom FFT), The Band Plan plugin and the Noise blanker? (I think).

PM ME IF YOU NEED HELP.

Have fun.

DMD
Posts: 3
Joined: Tue Feb 18, 2020 6:06 am

Re: .NET/Python developer resources

Post by DMD » Tue Feb 18, 2020 6:15 am

Hi Eddie,
Thanks for the detailed explanation.
I'm trying to compile the ZoomFFT example in "sdrsharp_plugin_examples". I'm using VS2017.
I see that there are references to SDRSharp.Common, SDRSharp.PanView, and SDRSharp.Radio in the project.
These reference are not resolved. I see the corresponding DLLs in my SDR# installation directory. But, how do I actually setup the VS project to resolve these references?
Thanks!

EddieMac74
Posts: 60
Joined: Wed Feb 07, 2018 8:00 am
Contact:

Re: .NET/Python developer resources

Post by EddieMac74 » Wed Feb 19, 2020 9:52 pm

Hi Ryan,

Your solution will not compile because as you mention, the dll files referenced can not be resolved.

This means: Visual Studio can not find those those referenced dll files. This is because the person who wrote the ZoomFFT plugin has those files on their own machine, probably in a differently named SDR# root folder as well.

Here are the steps to rectify this:

1) In your visual studio designer, go to the "Solution Explorer"

2) Locate the entry which reads "References".

3) Expand that entry (if it is not already).

4) The sub-entries (references) which have YELLOW WARNING ICONS are the unresolved references.

5) On each (there are 5 total) reference entry with the warning icon, RIGHT-CLICK and select "Delete" (see below)
delete.jpg
delete.jpg (58.58 KiB) Viewed 2547 times
6) Now that you have removed those unresolved references, we need to re-reference the dll files properly...

7)Right click on "References" entry and click on the "Add Reference..." (see below)
ref.jpg
ref.jpg (54.9 KiB) Viewed 2547 times
8) Now the "Reference Manager" will open.

9) In the reference manager, click on the BUTTON at the BOTTOM of the window which reads "Browse..." (see below)
refman.jpg
refman.jpg (28.9 KiB) Viewed 2547 times
10) In the browse dialog that opens, browse to your SDR# root folder.

11) Press CONTROL to multi select the SDRSharp.PanView.dll, SDRSharp.Common.dll, and the SDRSharp.Radio.dll files.

12) Once you have all three selected, hit the "ADD" button.

13) After the browse file dialog closes, ensure that all three dll file names appear in the Reference Manager and are CHECKED and click OK.

14) The proper references are now in the solution BUT we have a few more steps before it will compile.

15) The latest version of SDR# (Version 1732) includes the new Telerik themed controls. Unless you have your own paid license key file for Telerik we need to delete the original authors licence key file reference or else it will not compile.

16) going back to the "Solution Explorer" again, locate the entry which reads "Properties"

17) Under the 'Properties entry you will see a sub entry reference which reads "license.licx" with a yellow icon on it.

18) Right click on the entry and click "Delete"

19) SAVE THE SOLUTION

20) Compile the solution

21) Now, in your solution folder, you should find the "SDRSharp.ZoomFFT.dll" in your "ZoomFFT\obj\Debug" folder (if your debugging) or in the "ZoomFFT\obj\Release" folder if your building a release version.

if you need any further help please let me know.

PLEASE ALSO NOTE: to have your plugin work correctly in SDR# you must also target your framework to ".NET 4.6", target the x86 processor and make sure the "Allow Unsafe Code" directive is checked.

However; this should already be the case for the ZoomFFT example you are using.

DMD
Posts: 3
Joined: Tue Feb 18, 2020 6:06 am

Re: .NET/Python developer resources

Post by DMD » Thu Feb 20, 2020 3:30 am

Hi Eddie,
Thanks very much for your help.
It's close to working now. There is one compiler error now:

Error CS0535 'ZoomFFTPlugin' does not implement interface member 'ISharpPlugin.Gui' C:\Projects\SDR\SDRsharp_PluginSource\ZoomFFT\ZoomFFTPlugin.cs

As an experiment, I added the following in ZoomFFTPlugin.cs:

public UserControl Gui => throw new NotImplementedException();

With this change, the project compiles. In SDR# the plugin loads and the plots show up (because the original plugin was previously setup to display them, I believe). But, the user GUI with the check boxes does not show up.

Any idea what I'm doing wrong?
Thanks!
-Dave

EddieMac74
Posts: 60
Joined: Wed Feb 07, 2018 8:00 am
Contact:

Re: .NET/Python developer resources

Post by EddieMac74 » Fri Feb 21, 2020 7:14 am

Hello Ryan,
Error CS0535 'ZoomFFTPlugin' does not implement interface member 'ISharpPlugin.Gui'
This is normal behavior for the code you inserted. You literally told the code to throw that error.
public UserControl Gui => throw new NotImplementedException();
The Gui that SDR# is looking for, as you have noticed, is the UserControl for the plugin control panel

In order for it to work you need to tell the Get => directive to return the actual UserControl. In this case that is the ZoomPanel user control.

Replace your code:
public UserControl Gui => throw new NotImplementedException();
With this:

public UserControl Gui => _controlPanel;

this will return the _controlPanel which is the UserControl ZoomPanel which holds all the controls for the plugin.

Let me explain briefly how to implement the plugin interface with some C# pseudo code:

using SDRSharp.Common; Reference required for ISharpPlugin interface and ISharpControl interface
using System.Windows.Forms; Reference required for UserControl object definition

namespace SDRSharp.YourPluginNameSpace your plugins root namespace preceeded with SDRSharp namespacce
{
public class MyPlugin: ISharpPlugin the plugin entry point implementing the ISharpPlugin interface
{
private const string _displayName = "Ryan's Plugin"; The variable to hold the name of your plugin

private UserControl _yourPluginsControlPanel;Variable to hold your plugins control panel which is a user control
private ISharpControl _sharpControl;variable to hold the reference to the ISharpControl of SDR# to allow receiving of events and to control radio

public string DisplayName The read only property for the plugin name that returns the variable assigned above
{
get { return _displayName; }
}

public UserControl Gui The UserControl that is your control panel
{
get { return _yourPluginsControlPanel; }
}

public void Initialize(ISharpControl control)The initialization routine when your plugin first loads
{
_sharpControl = control;Assign the referenced ISharpControl to your own variable to use this interface later...

_yourPluginsControlPanel = new UserControl myPluginsControlPanel;Instancing and setting a new copy of your control panel UserControl
}

public void Close()Insert any extra code here to preform when SDR# is closing
{

}
}
}

If you need any further help, let me know I will code you a simple 'Hello World" plugin to demonstate the proper way to make a plugin.

Also, if your not strong in C# I would google for a simple video or article comparing the variables, data types and function call types from a language you know like Phython or VB to C# to get a feel for it, it is a bit different than VB but similar enough to catch on fast.

Also, it is a lot more powerful than VB in what you can do with unmanaged code.

I switched from VB to C# and will never look back. ;)

Post Reply