Author Topic: Using vantagepro.dll with VBA in Excel  (Read 3558 times)

0 Members and 1 Guest are viewing this topic.

Offline Knekse

  • Member
  • *
  • Posts: 3
Using vantagepro.dll with VBA in Excel
« on: May 05, 2014, 02:51:36 AM »
Hi

I am trying to use VBA in Excel 2013 to access data directly on my Vantage pro 2 weather station, connected via serial/weatherlink. For that purpose, I would like to use vantagepro.dll, but I have problems getting it up and running. Here is my current code:

Code: [Select]
Private Declare Function OpenDefaultCommPort_V Lib "VantagePro.dll" Alias "_OpenDefaultCommPort_V@0" () As Integer
Private Declare Function OpenCommPort_V Lib "VantagePro.dll" Alias "_OpenCommPort_V@0" (ByVal comPort As Integer, ByVal baudrate As Integer) As Integer
Private Declare Function InitStation_V Lib "VantagePro.dll" Alias "_InitStation_V@0" () As Integer
Private Declare Function LoadCurrentVantageData_V Lib "VantagePro.dll" Alias "_LoadCurrentVantageData_V@0" () As Integer
Private Declare Function GetWindSpeed_V Lib "VantagePro.dll" Alias "_GetWindSpeed_V@0" () As Integer
Private Declare Function GetWindDir_V Lib "VantagePro.dll" Alias "_GetWindDir_V@0" () As Integer
Private Declare Function GetBarometer_V Lib "VantagePro.dll" Alias "_GetBarometer_V@0" () As Double
Private Declare Function GetOutsideHumidity_V Lib "VantagePro.dll" Alias "_GetOutsideHumidity_V@0" () As Integer
Private Declare Function GetOutsideTemp_V Lib "VantagePro.dll" Alias "_GetOutsideTemp_V@0" () As Integer
Private Declare Function CloseCommPort_V Lib "VantagePro.dll" Alias "_CloseCommPort_V@0" () As Integer


Dim barometer As Double
Dim speed As Integer
Dim dir As Integer
Dim tempOut As Integer
Dim humOut As Integer

Sub Command1_Click()
    Call GetData
End Sub

Public Function GetData()

    Dim br As Integer
    Dim comPort As Integer
    br = 19200
    comPort = 4
   

    'OpenDefaultCommPort_V (When not commented out, this runs, but my station is not connected on port 1, but port 4)
    Call OpenCommPort_V(comPort, br)
    TEST = InitStation_V
    LoadCurrentVantageData_V

speed = GetWindSpeed_V
dir = GetWindDir_V
tempOut = GetOutsideTemp_V

humOut = GetOutsideHumidity_V

MsgBox tempOut
MsgBox dir

CloseCommPort_V

End Function

I get the following error code when running the code: "Run time error '453': Can't find dll entry point _OpenCommPort_V@0 in VantagePro.dll"

Does anyone her know what I am doing wrong or missing? Or has anyone tried using Excel VBA to fetch data from Vantage Pro 2, with success? :)

Best regards
Knekse

Offline pfletch101

  • Forecaster
  • *****
  • Posts: 329
    • Personal Website
Re: Using vantagepro.dll with VBA in Excel
« Reply #1 on: May 05, 2014, 09:48:44 AM »
See my recent post in another thread here (http://www.wxforum.net/index.php?topic=12517.msg215803#msg215803). The context is VB.NET rather than VBA, but the errors in the include file (which you may be using as the model for your DLL code declarations) will also cause problems if translated directly into VBA. I don't use third party DLLs from VBA much (though I do sometimes use Windows DLLs), but your Declare Function calls don't look right to me. The Alias parameter is normally the name of the function in the DLL (when it is different there from what it is in your code) - you are using Alias parameters with additional leading underscores and trailing '@0's on each function name, and I don't understand why. Finally, even if you do everything right, you may have problems interfacing with the Vantage DLL functions which return strings or structure (you aren't using any of these in your sample code), because if you want to access such functions from VBA, the DLL code has to obey some rules which I am sure the Davis guys did not consider when they wrote it.
Vantage Pro 2+ connected to Raspberry Pi running weewx by means of Meteo-Pi - data incorporated in domestic energy production (PV) and use monitoring system.

Offline Knekse

  • Member
  • *
  • Posts: 3
Re: Using vantagepro.dll with VBA in Excel
« Reply #2 on: May 13, 2014, 05:16:15 AM »
Hi Pfletch

Thank you for your answer. I tried cleaning up the code as you described, and using your dll, but still no luck. I must admit I am new to using dll's. My main question would now be: How do I access data directly (preferably through excel), so that I can bypass/avoid Weatherlink? Do you have any ideas or a direction I should be looking in?

Best regards
Knekse

Offline pfletch101

  • Forecaster
  • *****
  • Posts: 329
    • Personal Website
Re: Using vantagepro.dll with VBA in Excel
« Reply #3 on: May 13, 2014, 08:58:33 AM »
Hi Pfletch

My main question would now be: How do I access data directly (preferably through excel), so that I can bypass/avoid Weatherlink? Do you have any ideas or a direction I should be looking in?

Best regards
Knekse

I'm sorry to have to be negative, but the reason why Davis supply the Vantage DLL is that directly interfacing to the datalogger without it is very complex, and would require you to have a much higher level of programming knowledge and ability than is required for use of the DLL. I don't think that it can be done at all in VBA from Excel.  You are almost certainly going to be better off using the Weatherlink software (or other compatible commercial software)  to download your data and then using Excel to process it.
Vantage Pro 2+ connected to Raspberry Pi running weewx by means of Meteo-Pi - data incorporated in domestic energy production (PV) and use monitoring system.

Offline Knekse

  • Member
  • *
  • Posts: 3
Re: Using vantagepro.dll with VBA in Excel
« Reply #4 on: May 13, 2014, 09:16:40 AM »
No need to be sorry... I was afraid that was what you were going to say.

I have tried using weatherlink, but it doesn't really suit my needs. I would like to read the current values, along with having an archive that contains hourly values. I tried having weatherlink export values every minute and then extracting the hourly values (ie. 12:00, 01:00 etc.) using excel, but that has been giving me more headaches. So my wish was to "cut out the annoying middel man" :)

Offline SLOweather

  • Global Moderator
  • Forecaster
  • *****
  • Posts: 3456
    • Weatherelement Moline IL
Re: Using vantagepro.dll with VBA in Excel
« Reply #5 on: May 13, 2014, 12:21:49 PM »
Depending on your programming abilities, you may find the Vantage Pro
Vantage Pro2 and Vantage Vue Serial Communication Reference Manual
useful. It lists all of the commands the console will respond to. For instance, you can get the current data string by sending the LOOP command to the console. The data comes back as binary, so it will need some converting.

Offline pfletch101

  • Forecaster
  • *****
  • Posts: 329
    • Personal Website
Re: Using vantagepro.dll with VBA in Excel
« Reply #6 on: May 13, 2014, 01:39:01 PM »
Depending on your programming abilities, you may find the Vantage Pro
Vantage Pro2 and Vantage Vue Serial Communication Reference Manual
useful. It lists all of the commands the console will respond to. For instance, you can get the current data string by sending the LOOP command to the console. The data comes back as binary, so it will need some converting.

I may be doing the OP an injustice, but if he is unable to get the Vantage DLL routines to work from VBA in Excel, I would not give much for his chances of getting the much lower level interface documented in the Communication Ref Manual to do so). I have a great deal of VBA programming experience (it's what I do  :-)), and it would not occur to me to attempt the latter approach.
Vantage Pro 2+ connected to Raspberry Pi running weewx by means of Meteo-Pi - data incorporated in domestic energy production (PV) and use monitoring system.

Offline Josiah

  • Add-InWx Software Author
  • Forecaster
  • *****
  • Posts: 449
    • Add-InWx
Re: Using vantagepro.dll with VBA in Excel
« Reply #7 on: September 29, 2014, 10:08:41 AM »
I know this is an older thread but,

Knekse, You might be interested in what I'm doing here: http://www.wxforum.net/index.php?topic=22605.0
It's still a work in progress but Its coming along rather nicely if i say so myself.
With the Plugin support I'm planning on adding it wouldn't be hard for you to create a Plugin that would do what ever it is that your after without having to interface to the station directly.

Its programed in VB.Net so plugins could be created in VB.Net C# or C++.

Also as a thought, I don't know if you know this but, Microsoft does have free versions of their programming IDE (Visual Studio). You can find them here: http://www.visualstudio.com/downloads/download-visual-studio-vs
Look at the Express Editions.