Page 1 of 2

Code examples .Net and C#?

Posted: Tue Mar 22, 2016 12:53 pm
by Toontje
Hi coders!

I want to make a start with understanding how to write an app for the SDRplay using Visual Studio and C#.
Do we have any code examples i can start off with?

Thanks,

Ton.

Re: Code examples .Net and C#?

Posted: Tue Mar 22, 2016 11:23 pm
by Sasan
Hi
I wrote a simple console app which saves I/Q streams to a file (which can later be opened in apps like Gqrx or SDRSharp)
It's very basic and does not get command line arguments (all values are hard-coded)
The code is attached.

Note that I'm not a C# programmer and I don't even use Windows a lot, so it's just a proof-of-concept to show how to call the API from C#.
I compiled the code on .NET 3.5 and executed it on Windows 10 to make sure it works.
It calls the mir_sdr_api.dll, found in :
C:\Program Files\MiricsSDR\API\x86 and C:\Program Files\MiricsSDR\API\x64
Does this help you?

P.S: take a look at SDRPlay's sample codes (in C): https://github.com/SDRplay/
and API specification: http://www.sdrplay.com/docs/Mirics_SDR_ ... cation.pdf

Re: Code examples .Net and C#?

Posted: Wed Mar 23, 2016 7:22 am
by Toontje
Yes, this helps me a lot!

Thanks!

Re: Code examples .Net and C#?

Posted: Wed Apr 26, 2017 7:13 pm
by ronkpa
Thank you Sasan Program.cs was very helpful. I am creating a C# wrapper based on your work.
The latest API release is 2.10 (11/Apr/2017).
The latest API Specification is 2.09 (22 Dec 2016) says there is only one SetParam command 101=change 1st LO freq.
In your program you use commands 201 and 202. Do you have a later API specification, or did you use another reference?
Thanks again.

Re: Code examples .Net and C#?

Posted: Thu Apr 27, 2017 8:17 am
by Sasan
ronkpa wrote:Thank you Sasan Program.cs was very helpful. I am creating a C# wrapper based on your work.
The latest API release is 2.10 (11/Apr/2017).
The latest API Specification is 2.09 (22 Dec 2016) says there is only one SetParam command 101=change 1st LO freq.
In your program you use commands 201 and 202. Do you have a later API specification, or did you use another reference?
Thanks again.
I don't remember which version I'd used, but the latest API specification says the "mir_sdr_SetParam" function is deprecated and will be removed in future.
(Section 3.2 on http://www.sdrplay.com/docs/Mirics_SDR_ ... cation.pdf
OR section 3.3 on http://www.sdrplay.com/docs/SDRplay_SDR ... cation.pdf)

So I think you can ignore the values I'd used (and the function as well)

Re: Code examples .Net and C#?

Posted: Sat May 13, 2017 6:40 pm
by sdrplay
If you have the c# communication to the API sorted, then you can follow the flow in the play_sdr example we updated on github (http://www.github.com/SDRplay/examples)

Best regards,

SDRplay Support

Re: Code examples .Net and C#?

Posted: Thu Nov 16, 2017 3:33 pm
by chris11
Hello,

Sasan thank you very much for the code examples. Did anyone manage to create Pinvoke statements which work in Visual Studio C# for the latest dll or can give me some hints.

Re: Code examples .Net and C#?

Posted: Sun Nov 19, 2017 7:01 am
by SteveAndrew
Hi everyone

I've just uploaded a zip file to the Playground (SdrScan.zip)

It's a simple C# program that shows how to get data from the API using the streaming function. It was written using Visual Studio 2010, .Net Framework 4 for 64 bit systems. It should compile and run in later editions of Visual Studio (in theory) but as with most things Microsoft, in theory, theory and practice are the same thing, in practice they are not :-)

The code is based on the original work done by Sasan... Many thanks for getting the ball rolling.

Hope this helps...

Re: Code examples .Net and C#?

Posted: Wed Dec 20, 2017 11:57 pm
by n2ic
"I've just uploaded a zip file to the Playground (SdrScan.zip)"

Can someone point me to the "Playground" ?

Thanks

Re: Code examples .Net and C#?

Posted: Thu Dec 21, 2017 1:00 am
by SteveAndrew
Hi N2NIC

That code has a bug in it. It wont run when used in 32-bit mode. Andy in tech support finally traced the problem for - an absolute hero ! In the meantime, I'll redo a simple demo and post the source code here for you.

Playground link is: http://www.sdrplay.com/playground/ but it does require different login credentials. I should not have posted it there in the first place.