Results 1 to 15 of 15

Thread: Calling SignalHound dll

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2020
    Posts
    9

    Calling SignalHound dll

    Hi All,
    I'm trying to call the Signal Hound DLL (bb_api.dll) from Excel VBA to control a USB spectrum analyser.

    https://signalhound.com/software/sig...pment-kit-sdk/

    I have read many webpages but not matter what I try, VB always responds with "Bad DLL calling convension"

    The C header file looks like this:

    BB_API bbStatus bbOpenDevice(int *device);

    "bbStatus" is an enum. I've tried "ByRef device integer" and just about everyother cobination with no success :-(
    Private Declare PtrSafe Function bbOpenDevice Lib "bb_api" (ByVal handle As LongPtr) As Long

    If anyone can help it would be great to hear from you.

    Andrew

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Calling SignalHound dll

    is your excel 64bit or 32?

    i would think most of any example using matlab would work on excel, but 32 bit calling would be different to any 64bit code

    Use the device API for fast direct device control
    Includes programming examples for C/C++, C#, Python, and MATLABĀ®
    Includes programming manuals
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2020
    Posts
    9

    Re: Calling SignalHound dll

    Thank-you Pete,

    I'm using Windows10 64-bit.

    I looked at "signal_hound_sdk_11_02_20.zip : signal_hound_sdk\device_apis\bb_series\win\examples\matlab\bb_device\bbopendevice.m"

    I can't quite see how to use that code in Excel? Many of the functions used do not exist in VBA? Specifically "calllib()".

    Do I need to create a "pointer" before calling the dll?

    Have I missed the point?

    Regards
    Andr

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Calling SignalHound dll

    I'm using Windows10 64-bit.
    the question was is your excel 64 bit
    my windows is 64 bit, but i do not have 64bit office, and probably many years till i do

    Do I need to create a "pointer" before calling the dll?
    again probably depends on your excel version

    while if may be possible to use the signal hound from vba, from a search, it does not appear that it is supported at all
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5

    Thread Starter
    New Member
    Join Date
    Dec 2020
    Posts
    9

    Re: Calling SignalHound dll

    Hi Pete,

    I have 64-bit Office installed on my 64-bit Win10 machine.

    Yes I did a search and found nothing (which did make me worry a little), I naively thought that VBA could communicate with any dll?

    Andrew

  6. #6

    Thread Starter
    New Member
    Join Date
    Dec 2020
    Posts
    9

    Re: Calling SignalHound dll

    I can't add bb_api.dll as a reference in "Tools->References" so maybe it's not possible.
    Looks like I'll have to write some kind of C proxy to talk to the Analyser and communicate with VBA...
    Andrew

  7. #7
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Calling SignalHound dll

    maybe you should just download the current express version of c# (afaik free to download and use), code written there can be integrated to automate excel, not that i can help you much there
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  8. #8

    Thread Starter
    New Member
    Join Date
    Dec 2020
    Posts
    9

    Resolved Re: Calling SignalHound dll

    C# - another new language to learn :-)
    I will take a look, thank-yuo for your help.
    Andrew

  9. #9
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Calling SignalHound dll

    good oh, rather you than me
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  10. #10

    Thread Starter
    New Member
    Join Date
    Dec 2020
    Posts
    9

    Talking Re: Calling SignalHound dll

    Well the first bit was easy...

    I followed the website below to create C# dll that I could call from VBA,

    https://richnewman.wordpress.com/200...ry-from-excel/

    In the class for that dll I created a couple of methods to open the Analyser and read it temperature, voltage and current and it worked.

    What I really need to do is get back the spectrum analyser plot - how hard can that be :-)

  11. #11
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Calling SignalHound dll

    of course if you can make a c# dll, you can then call that from excel
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  12. #12

    Thread Starter
    New Member
    Join Date
    Dec 2020
    Posts
    9

    Re: Calling SignalHound dll

    Quote Originally Posted by westconn1 View Post
    of course if you can make a c# dll, you can then call that from excel
    Yep, that's exactly what I'm doing - as per the webpage :-)

  13. #13

    Thread Starter
    New Member
    Join Date
    Dec 2020
    Posts
    9

    Re: Calling SignalHound dll

    Doh this was going so well after the Pete's initial help :-)
    It all fell apart when I had to return and array from the C# dll back to VBA.

    I am pretty sure my dll is calling the SignalHound api correctly as the return code are '0'. I have included my C# dll in case it helps anyone else. VBA seems to call and return sccessfully once, but on the second attempt I get a VBA "Out of Memory" error?

    If anyone can shed any light on this I'd be glad to hear from you. Thank-you.

    My code is probably ugly, it's WIP....

    bb_api_classs.cs

    VBA calling code (snippet)

    Code:
    Function GetPoints(ByRef Points() As Double) As Long
        Dim NumPoints As Long
        Dim lclpoints() As Double
    
            NumPoints = GetNumPoints() - 1  'Get the number of points (normally 20480)
            ReDim lclpoints(0 To NumPoints) As Double
            GetPoints = bbClass.GetPoints(bbDevice, lclpoints())
            Points = lclpoints              'copy the newly retreived point to their final location
            Erase lclpoints                  'Tried to erase array just in case it helps
    End Function
    Andrew
    Last edited by rekabuk; Dec 16th, 2020 at 03:54 AM.

  14. #14

    Thread Starter
    New Member
    Join Date
    Dec 2020
    Posts
    9

    Re: Calling SignalHound dll

    I managed to get it working - by trial and error, so the code is not pretty :-(
    I'm not sure all of it is needed and there are probably better ways of doing it, but it works!!!

    Code:
    Function GetNumPoints() As Long
        Dim Points As Integer
        
        bbClass.GetNumPoints(bbDevice, Points)
        GetNumPoints = CLng(Points)
    
    End Function
    
    Function GetPoints(ByRef Points() As Double) As Long
        Dim NumPoints As Long
        Dim lclpoints() As Double
    
        NumPoints = GetNumPoints() - 1
        ReDim lclpoints(0 To NumPoints) As Double
        GetPoints = bbClass.GetPoints(bbDevice, lclpoints())
        
        ReDim Points(0 To NumPoints) As Double
        For n = 0 To NumPoints
            Points(n) = lclpoints(n)
        Next n
        Erase lclpoints
            
    End Function
    and here is the updated C#
    bb_api_classs.cs

    Andrew

  15. #15
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Calling SignalHound dll

    well done!!
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width