Frequency Response Analyzer with Bode Plots

Post discussions on applications you are writing
Post Reply
_Wim_
Advanced
Posts: 0
Joined: Sun Nov 12, 2017 11:31 am

Re: Frequency Response Analyzer with Bode Plots

Post by _Wim_ » Fri Apr 03, 2020 6:07 am

It is indeed always a challenge working cross languages, but typically all has been done before and google always has an answer... :D

Does your virtual interface already run in another thread to avoid that the application freezes while connection with the signal generator is made and also when sending commands back and forward? Or should the interace-dll make a separate thread for instrument communication?

I think as a first try it would be good to write a dll that just answers the requests from your application and writes these request to a log file, without actual communication to a signal generator. When this works ok, we know the interface in robust, and I can start communication to the signal generator.

Is your interface definition already available to have I look at?

hexamer
Advanced User
Advanced User
Posts: 0
Joined: Tue Aug 12, 2014 10:09 pm

Re: Frequency Response Analyzer with Bode Plots

Post by hexamer » Sat Apr 04, 2020 1:08 am

_Wim_ wrote:
Fri Apr 03, 2020 6:07 am
It is indeed always a challenge working cross languages, but typically all has been done before and google always has an answer... :D

Does your virtual interface already run in another thread to avoid that the application freezes while connection with the signal generator is made and also when sending commands back and forward? Or should the interace-dll make a separate thread for instrument communication?

I think as a first try it would be good to write a dll that just answers the requests from your application and writes these request to a log file, without actual communication to a signal generator. When this works ok, we know the interface in robust, and I can start communication to the signal generator.

Is your interface definition already available to have I look at?
Here is the interface file: ExtSigGen.h

The application does use a separate thread from the UI for carrying out the FRA activities, and another thread with timeout is used for the data collection. But there is no separate thread and timeout for signal generator calls. So, the application is relying on the plugin to not hang. In the plugin I made there are communication timeouts.

The plugin header I linked above has shows the methods which I think are are intuitively named, but the methods are documented in the plugin project which is here EME165-R2 Plugin

Finally, here is an initial release candidate for the app with external signal generator capability: FRA4PicoScope_0.7.0b_RC1.msi

Since there are new settings, it will delete your old settings. After you install, you should check in help->about that it says 0.7.0b RC1. To install a plugin, just place the new DLL in the same directory as FRA4PicoScope.exe

Let me know if something doesn't make sense.
Last edited by hexamer on Sat Apr 04, 2020 7:52 pm, edited 1 time in total.

sbabic44
User
User
Posts: 2
Joined: Thu Nov 30, 2017 10:17 pm

Re: Frequency Response Analyzer with Bode Plots

Post by sbabic44 » Sat Apr 04, 2020 10:01 am

Hello!
I have 3046D MSO and 4262 and Rigol DG1062Z and Siglent 6052X.
I do know C++ and C# but my programmer-fu is very weak(not really actively programming in many years) , but would be willing to test and maybe fix minor things..
If I may make a suggestion: SCPI is just string exchange protocol, and it is the same over serial, USB, and Ethernet.
I think, maybe direct telnet to instruments and just exchange strings. Nothing to enumerate or anything, Just IP, port and SCPI strings set for different instruments.
Best regards, and again, thanks Hexamer for all the effort!

hexamer
Advanced User
Advanced User
Posts: 0
Joined: Tue Aug 12, 2014 10:09 pm

Re: Frequency Response Analyzer with Bode Plots

Post by hexamer » Sat Apr 04, 2020 2:04 pm

sbabic44 wrote:
Sat Apr 04, 2020 10:01 am
Hello!
I have 3046D MSO and 4262 and Rigol DG1062Z and Siglent 6052X.
I do know C++ and C# but my programmer-fu is very weak(not really actively programming in many years) , but would be willing to test and maybe fix minor things..
If I may make a suggestion: SCPI is just string exchange protocol, and it is the same over serial, USB, and Ethernet.
I think, maybe direct telnet to instruments and just exchange strings. Nothing to enumerate or anything, Just IP, port and SCPI strings set for different instruments.
Best regards, and again, thanks Hexamer for all the effort!
Very good point about SCPI. I see lots of examples that boil down to that. As of now I'm still learning the alphabet soup of standardized instrument programming!

Your comment about enumeration makes me realize there is something I should explain. While the plugin interface shows enumeration and instrument ID capabilities, they are optional. In the example plugin project, they are not supported.

Another related topic is the Initialization function and the string parameters it can be passed. In the example plugin project, I use it as sort of an id/address in leiu of enumeration: it's just the COM port id for the Arduino in my signal generator.

sbabic44
User
User
Posts: 2
Joined: Thu Nov 30, 2017 10:17 pm

Re: Frequency Response Analyzer with Bode Plots

Post by sbabic44 » Sun Apr 05, 2020 3:20 pm

hexamer wrote:
Sat Apr 04, 2020 2:04 pm
sbabic44 wrote:
Sat Apr 04, 2020 10:01 am
Hello!
I have 3046D MSO and 4262 and Rigol DG1062Z and Siglent 6052X.
I do know C++ and C# but my programmer-fu is very weak(not really actively programming in many years) , but would be willing to test and maybe fix minor things..
If I may make a suggestion: SCPI is just string exchange protocol, and it is the same over serial, USB, and Ethernet.
I think, maybe direct telnet to instruments and just exchange strings. Nothing to enumerate or anything, Just IP, port and SCPI strings set for different instruments.
Best regards, and again, thanks Hexamer for all the effort!
Very good point about SCPI. I see lots of examples that boil down to that. As of now I'm still learning the alphabet soup of standardized instrument programming!

Your comment about enumeration makes me realize there is something I should explain. While the plugin interface shows enumeration and instrument ID capabilities, they are optional. In the example plugin project, they are not supported.

Another related topic is the Initialization function and the string parameters it can be passed. In the example plugin project, I use it as sort of an id/address in leiu of enumeration: it's just the COM port id for the Arduino in my signal generator.
That sounds OK to me. That kind of architecture (a sort of a gateway function that converts macro functions like start, stop, frequency, amplitude being sent from FRA to module, and module does the proper thing for the generator in question) is what I had in mind...

As I said, I can't work on this full time, but be happy to help as much as I can. Having two instruments that are very common is a good thing for testing. I'm not sure about Rigol, but Siglent siggens literally share programmers manual. It is a good chance that with those two I have we could cover most of the development for both Rigol and Siglent, apart from some difference in models capabilities.....

Drop me PM if you need something, and I'll try to do my best.
That's the least I could do...

Regards,
Sinisa

_Wim_
Advanced
Posts: 0
Joined: Sun Nov 12, 2017 11:31 am

Re: Frequency Response Analyzer with Bode Plots

Post by _Wim_ » Wed Apr 08, 2020 6:45 am

hexamer wrote:
Sat Apr 04, 2020 1:08 am
Here is the interface file: ExtSigGen.h

The application does use a separate thread from the UI for carrying out the FRA activities, and another thread with timeout is used for the data collection. But there is no separate thread and timeout for signal generator calls. So, the application is relying on the plugin to not hang. In the plugin I made there are communication timeouts.

The plugin header I linked above has shows the methods which I think are are intuitively named, but the methods are documented in the plugin project which is here EME165-R2 Plugin

Finally, here is an initial release candidate for the app with external signal generator capability: FRA4PicoScope_0.7.0b_RC1.msi

Since there are new settings, it will delete your old settings. After you install, you should check in help->about that it says 0.7.0b RC1. To install a plugin, just place the new DLL in the same directory as FRA4PicoScope.exe

Let me know if something doesn't make sense.
I have downloaded all files to a local source tree folder, currently having a first look how to implement a dll in C# that can be called by your C++ interface. The interface definition is indeed self explanatory.

_Wim_
Advanced
Posts: 0
Joined: Sun Nov 12, 2017 11:31 am

Re: Frequency Response Analyzer with Bode Plots

Post by _Wim_ » Wed Apr 08, 2020 7:55 am

_Wim_ wrote:
Wed Apr 08, 2020 6:45 am
I have downloaded all files to a local source tree folder, currently having a first look how to implement a dll in C# that can be called by your C++ interface. The interface definition is indeed self explanatory.
Hello Aaron,

Can you have a brief look at the section "C++/C# Interoperability" at the bottom of this page:
https://en.wikipedia.org/wiki/C%2B%2B/CLI

By using the "using" statement it should be possible to directly use a managed dll without any modifications on the C# side.

Is this something that would be possible in your application to implement? Other common solutions seems to be by exposing a com interface used on both sides, but this already seems quite a bit more complex than the solution above.

_Wim_
Advanced
Posts: 0
Joined: Sun Nov 12, 2017 11:31 am

Re: Frequency Response Analyzer with Bode Plots

Post by _Wim_ » Wed Apr 08, 2020 8:11 am

sbabic44 wrote:
Sat Apr 04, 2020 10:01 am
Hello!
I have 3046D MSO and 4262 and Rigol DG1062Z and Siglent 6052X.
I do know C++ and C# but my programmer-fu is very weak(not really actively programming in many years) , but would be willing to test and maybe fix minor things..
If I may make a suggestion: SCPI is just string exchange protocol, and it is the same over serial, USB, and Ethernet.
I think, maybe direct telnet to instruments and just exchange strings. Nothing to enumerate or anything, Just IP, port and SCPI strings set for different instruments.
Best regards, and again, thanks Hexamer for all the effort!
This would indeed be a possibility. I have a working C# application that uses SCPI via Telnet for a power analyzer I use.

Works perfectly for my rigol signal generator also (on port 5555, not port 23).
Attachments
Rigol Telnet.JPG

hexamer
Advanced User
Advanced User
Posts: 0
Joined: Tue Aug 12, 2014 10:09 pm

Re: Frequency Response Analyzer with Bode Plots

Post by hexamer » Thu Apr 09, 2020 1:41 am

_Wim_ wrote:
Wed Apr 08, 2020 7:55 am
_Wim_ wrote:
Wed Apr 08, 2020 6:45 am
I have downloaded all files to a local source tree folder, currently having a first look how to implement a dll in C# that can be called by your C++ interface. The interface definition is indeed self explanatory.
Hello Aaron,

Can you have a brief look at the section "C++/C# Interoperability" at the bottom of this page:
https://en.wikipedia.org/wiki/C%2B%2B/CLI

By using the "using" statement it should be possible to directly use a managed dll without any modifications on the C# side.

Is this something that would be possible in your application to implement? Other common solutions seems to be by exposing a com interface used on both sides, but this already seems quite a bit more complex than the solution above.
Wim,

From what I can tell it seems this sort of C++/CLI support for accessing a managed DLL (though the most modern way) is limited to supporting access to static methods in C#. The interface I made is based on a C++ class interface where an object is instantiated (like a factory pattern). I also tried to turn on the /clr flag to see how far I could get but I kept running into other incompatible flags (e.g. EHsc, MTd) that I don't think I could easily undo.

It does seem that COM (also factory like) would be another more flexible way, but definitely more complex.

But in all the searching, I see a few ideas based on what you mention above that would work like this:

Native C++ (FRA4PicoScope) -> C++/CLI DLL -> C# DLL.

In this model, since the calls to C# would still be static mehods, if you wanted to handle multiple instruments and enumeration, you'd probably have to use a handle as a parameter to these functions (like the Pico SDK).

I was briefly thinking about creating a standardized version of the middle DLL with an initialization parameter identifying the rightmost DLL. Unfortunately, since the #using technique points to a specific DLL, that wouldn't work.

Aaron.
Last edited by hexamer on Thu Apr 09, 2020 1:46 am, edited 1 time in total.

hexamer
Advanced User
Advanced User
Posts: 0
Joined: Tue Aug 12, 2014 10:09 pm

Re: Frequency Response Analyzer with Bode Plots

Post by hexamer » Thu Apr 09, 2020 1:45 am

_Wim_ wrote:
Wed Apr 08, 2020 8:11 am
sbabic44 wrote:
Sat Apr 04, 2020 10:01 am
Hello!
I have 3046D MSO and 4262 and Rigol DG1062Z and Siglent 6052X.
I do know C++ and C# but my programmer-fu is very weak(not really actively programming in many years) , but would be willing to test and maybe fix minor things..
If I may make a suggestion: SCPI is just string exchange protocol, and it is the same over serial, USB, and Ethernet.
I think, maybe direct telnet to instruments and just exchange strings. Nothing to enumerate or anything, Just IP, port and SCPI strings set for different instruments.
Best regards, and again, thanks Hexamer for all the effort!
This would indeed be a possibility. I have a working C# application that uses SCPI via Telnet for a power analyzer I use.

Works perfectly for my rigol signal generator also (on port 5555, not port 23).
Very nice!

_Wim_
Advanced
Posts: 0
Joined: Sun Nov 12, 2017 11:31 am

Re: Frequency Response Analyzer with Bode Plots

Post by _Wim_ » Thu Apr 09, 2020 6:44 am

hexamer wrote:
Thu Apr 09, 2020 1:41 am
In this model, since the calls to C# would still be static mehods, if you wanted to handle multiple instruments and enumeration, you'd probably have to use a handle as a parameter to these functions (like the Pico SDK).

I was briefly thinking about creating a standardized version of the middle DLL with an initialization parameter identifying the rightmost DLL. Unfortunately, since the #using technique points to a specific DLL, that wouldn't work.

Aaron.
What if we would use socket communication instead of DLL/Interface/Com? This way we are only tied to a specific port, but not any specific dll any longer.

Your app would then have to do two things:
- look if an instance of this new exe (socket server) is already running, and if not, start it (for example signalgenerator.exe in the installation folder of FRA)
- communicate with this socket server via 127.0.0.1 and port XXX

Communication could be SCPI like. I would write this socket server which translates the "FRA-SCPI" commands to "Signal Generator X" commands. In other words, from the FRA side it seems like it is communicating to a generic/virtual signal generator, which in his turns translates this to actual signal generator commands.

The implementation of another signal generator could be fairly easy, as only minor modifications to this socket server will be necessary (just translation from and to different SCPI commands).

marcov
Newbie
Posts: 0
Joined: Mon Apr 20, 2020 7:13 am

Possible bug

Post by marcov » Mon Apr 20, 2020 7:23 am

I've built last version and running in within VS in debug caused message box 'Could not read or initialize device settings file.' (line 354 of PicoScopeFraApp.cpp)
It seems like the settings subdirectory C:\Users\\AppData\Roaming\FRA4PicoScope was never created by code. When I manually created it, application started correctly. Pico 4227 here.
Thanks for your nice software.

Akram
Newbie
Posts: 0
Joined: Wed May 06, 2020 9:57 am

Re: Frequency Response Analyzer with Bode Plots

Post by Akram » Wed May 06, 2020 10:11 am

Dear hexamer,

I have a question (I precise I am a newbie), i want to add in the interface some button and box, and those buttons and boxes will be used to make some new mathematical calculation according to the measurement of the signal get it.

I am using VS 2019, I downond all the files, but i do not well understand how can I add extra button and boxes to the interface, please could you give some explanation, indication, links, document or any thing else that may help me.

Thank you for your help in advance.
Best regards.
Akram

Post Reply