cmgaskins
Member
Offline
Posts: 27
|
 |
« on: December 24, 2009, 09:47:36 PM » |
|
I have a program written in VB6 that gets the weather data from the Weather link, I am trying to convert this to VB8 and everything seems to be working except the Wind Direction is showing an 8-digit number example - 65011806 is there anyone here that has seen this problem?
Using Davis supplied - weatherlink.dll
Public Class frmMain
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim rc As Integer
rc = OpenCommPort(1, 2400) If rc <> 1 Then MsgBox("Can't open com port") Me.Close() End If
Me.lblOutSideTemp.Text = CStr(GetOutsideTemp) Me.lblTodayHigh.Text = CStr(GetHiOutsideTemp) Me.lblTodayLow.Text = CStr(GetLowOutsideTemp) Me.lblInSideTemp.Text = CStr(GetInsideTemp)
Me.lblWindSpeed.Text = CStr(GetWindSpeed) Me.lblWindGust.Text = CStr(GetHiWindSpeed) Me.lblWindDir.Text = CStr(GetWindDirection)
End Sub
End Class
Module WeatherLink Public Const NOT_SET = -100 Public Const COM_ERROR = -101 Public Const MEMORY_ERROR = -102 Public Const COM_OPEN = -103
'Initialization Functions Declare Function OpenCommPort Lib "weatherlink.dll" (ByVal comPort As Integer, ByVal baudRate As Long) As Integer Declare Function OpenCommPortStr Lib "weatherlink.dll" (ByVal comPort As String, ByVal baudRate As Long) As Integer Declare Function CloseCommPort Lib "weatherlink.dll" () As Integer Declare Function SetupRainCollector Lib "weatherlink.dll" (ByVal RainClickInc As Single, ByVal NativeUnit As Integer, ByVal DisplayUnit As Integer) As Integer
'Low Level Calls Declare Function GetSerialChar Lib "weatherlink.dll" () As Integer Declare Function PutSerialChar Lib "weatherlink.dll" (ByVal s1 As Byte) As Integer Declare Function PutSerialStr Lib "weatherlink.dll" (ByVal s1 As String) As Integer
'General Functions Declare Function GetDllVersion Lib "weatherlink.dll" () As Single Declare Function GetOutsideTemp Lib "weatherlink.dll" () As Single Declare Function GetWindChill Lib "weatherlink.dll" () As Single Declare Function GetInsideTemp Lib "weatherlink.dll" () As Single Declare Function GetModelNo Lib "weatherlink.dll" () As Integer Declare Function GetTotalRain Lib "weatherlink.dll" () As Single Declare Function GetDailyRain Lib "weatherlink.dll" () As Single Declare Function GetYearlyRain Lib "weatherlink.dll" () As Single Declare Function SetCommTimeoutVal Lib "weatherlink.dll" (ByVal ReadTimeout As Integer, ByVal WriteTimeout As Integer) As Integer Declare Function SendSensorImages Lib "weatherlink.dll" (ByVal n As Integer) As Integer Declare Function StopSendingImages Lib "weatherlink.dll" () As Integer Declare Function PutBarometer Lib "weatherlink.dll" (ByVal Barom As Single) As Integer Declare Function GetWindSpeed Lib "weatherlink.dll" () As Single Declare Function GetWindDirection Lib "weatherlink.dll" () As Integer Declare Function GetStationTime Lib "weatherlink.dll" (ByVal DateTimeStation As DateTime) As Integer Declare Function SetStationTime Lib "weatherlink.dll" (ByVal DateTimeStation As DateTime) As Integer Declare Function SetArchiveInterval Lib "weatherlink.dll" (ByVal intervalCode As Integer) As Integer Declare Function GetArchiveInterval Lib "weatherlink.dll" () As Integer Declare Function PutTotalRain Lib "weatherlink.dll" (ByVal TotalRain As Single) As Integer
'Hi's Lows Declare Function GetHiLowTimesOutTemp Lib "weatherlink.dll" (ByVal DateTimeHiOutTemp As DateTime, ByVal DateTimeLowOutTemp As DateTime) As Integer Declare Function GetHiLowTimesInTemp Lib "weatherlink.dll" (ByVal DateTimeHiInTemp As DateTime, ByVal DateTimeLowInTemp As DateTime) As Integer Declare Function GetHiLowTimesOutHum Lib "weatherlink.dll" (ByVal DateTimeHiOutHum As DateTime, ByVal DateTimeLowOutHum As DateTime) As Integer Declare Function GetHiLowTimesInHum Lib "weatherlink.dll" (ByVal DateTimeHiInHum As DateTime, ByVal DateTimeLowInHum As DateTime) As Integer Declare Function GetHiLowTimesDewPt Lib "weatherlink.dll" (ByVal DateTimeHiDewPt As DateTime, ByVal DateTimeLowDewPt As DateTime) As Integer Declare Function GetHiInsideTemp Lib "weatherlink.dll" () As Single Declare Function GetLowInsideTemp Lib "weatherlink.dll" () As Single Declare Function GetHiOutsideTemp Lib "weatherlink.dll" () As Single Declare Function GetLowOutsideTemp Lib "weatherlink.dll" () As Single Declare Function GetHiInsideHum Lib "weatherlink.dll" () As Integer Declare Function GetLowInsideHum Lib "weatherlink.dll" () As Integer Declare Function GetHiOutsideHum Lib "weatherlink.dll" () As Integer Declare Function GetLowOutsideHum Lib "weatherlink.dll" () As Integer Declare Function GetHiDewPt Lib "weatherlink.dll" () As Single Declare Function GetLowDewPt Lib "weatherlink.dll" () As Single Declare Function GetLowTimesWindChill Lib "weatherlink.dll" (ByVal DateTimeLowWindChill As DateTime) As Integer Declare Function GetLowWindChill Lib "weatherlink.dll" () As Single Declare Function GetHiTimesWindSpeed Lib "weatherlink.dll" (ByVal DateTimeHiWindSpeed As DateTime) As Integer Declare Function GetHiWindSpeed Lib "weatherlink.dll" () As Single
End Module
|
|
|
|
|
Logged
|
|
|
|
|
jruys
|
 |
« Reply #1 on: December 26, 2009, 11:06:33 AM » |
|
That is odd that it is giving you that high 8 digit number. I was looking at the documentation and it looks like the return type on GetWindDirection should be a short not an int. That shouldn't really have really mattered, but who knows, it is worth a shot trying to change it.
|
|
|
|
|
Logged
|
|
|
|
cmgaskins
Member
Offline
Posts: 27
|
 |
« Reply #2 on: December 26, 2009, 01:03:45 PM » |
|
Thanks jruys!!!!  That fixed it; it is always the simple things that are over looked.
|
|
|
|
|
Logged
|
|
|
|
|
jruys
|
 |
« Reply #3 on: December 26, 2009, 06:59:03 PM » |
|
Great, I am glad that it worked. There must be some marshalling problems when you ask for an int instead of a short.
|
|
|
|
|
Logged
|
|
|
|
cmgaskins
Member
Offline
Posts: 27
|
 |
« Reply #4 on: December 27, 2009, 07:46:18 PM » |
|
Has anyone ever setup the Weatherlink to download to a database? I know Davis offers this in Excel; what I have now is that it gets the current data every minute then saves it every hour to a database by Visual Basics. The only thing is if for some reason the computer goes down I have lost data. If it were setup to download the data instead of what is current at that hour would be best that way if the computer was to go down it would catch the missed data when the computer was rest. I’m not that good with Visual Basics any help would be appreciated, I know how to call it to download but I don’t know how to put it to a database.
|
|
|
|
|
Logged
|
|
|
|
|
jruys
|
 |
« Reply #5 on: December 27, 2009, 11:04:09 PM » |
|
First you are going to need to create a couple of Types (structs): (I have not tried this and I am more of a c# guy, but here is my shot at VB code)
Declare Function Download Lib "weatherlink.dll" (DnloadOptions As Options, ByVal DnloadFileName As String) As Integer Declare Function GetArchiveRecord Lib "weatherlink.dll" (arcRecord As WeatherRecord, ByVal RecNo As Integer) As Integer
Type Options UseDialogBox As Byte ClearArchive As Byte WriteToFile As Byte AppendToFile As Byte End Type
Type WeatherRecord month As Integer day As Integer hour As Integer min As Integer hiOutsideTemp As Single lowOutsideTemp As Single insideTemp As Single outsideTemp As Single barometer As Single insideHum As Integer outsideHum As Integer dewPoint As Single rain As Single windSpeed As Single hiWindSpeed As Single windChill As Single windDirection As Integer End Type
Sub DownloadData Dim opts As Options Dim numRecs As Integer Dim fileName As String = "filename.txt" 'If you want to download to a file Dim i As Integer = 0 Dim wRec As WeatherRecord opts.UseDialogBox = 0 'Don't use Dialog opts.ClearArchive = 1 'Clear the archive (You can do this so you do not have to check what your last record in the database was and then search through the downloaded records) opts.WriteToFile = 0 'Don't write to a file opts.AppendToFile = 0 'Don't append to a file
numRecs = Download(opts, ByVal fileName)
'Loop through the records Do While i < numRecs Loop GetArchiveRecord(wRec, ByVal i) 'Fills the wRec structure 'Add database code here End Loop End Sub
I hope that helps, just remember that I have not used VB for quite a while, so there maybe some syntax errors, but I think it is pretty close.
|
|
|
|
|
Logged
|
|
|
|
cmgaskins
Member
Offline
Posts: 27
|
 |
« Reply #6 on: December 28, 2009, 06:36:37 PM » |
|
Thanks again jruys!
Works Great.
Option Explicit Option Private Module
Dim adoconn As New ADODB.Connection Dim rs As New ADODB.Recordset
Public Function DoUpdate(verbose As Boolean) As Integer Dim openResult As Integer Dim updateResult As Integer Dim clearAfterUpdate As Boolean Dim str As String Set adoconn = Nothing adoconn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Weather.mdb;Persist Security Info=False" str = "select * from Weather" rs.Open str, adoconn, adOpenDynamic, adLockPessimistic If openResult < 0 Then If verbose Then MsgBox prompt:="Unable to open station.", Title:="Error" End If CloseCommPort DoUpdate = openResult Exit Function End If updateResult = UpdateMonWizPerc(clearAfterUpdate, verbose) End Function
Private Function UpdateMonWizPerc(clearAfterUp As Boolean, verbose As Boolean) As Integer Dim result As Integer Dim sI As SensorImage, wR As WeatherRecord Dim numRecs As Integer, lastRec As Integer Dim newRecCount As Integer Dim opt1 As Options opt1.AppendToFile = 0 opt1.UseDialogBox = 0 opt1.WriteToFile = 0 opt1.ClearArchive = 1 lastRec = Download(opt1, "") lastRec = lastRec - 1 newRecCount = 0 Dim recordDate As Date Dim r As Integer Dim today As Date
today = Date
For r = 0 To lastRec ' Load wR with the r'th record result = GetArchiveRecord(wR, r)
If month(today) < wR.month Then recordDate = CDate(Format(wR.month) + "/" + Format(wR.day) + "/" + _ Format(Year(today) - 1) + str(wR.hour) + ":" + Format(wR.min)) Else recordDate = CDate(Format(wR.month) + "/" + Format(wR.day) + "/" + _ Format(Year(today)) + str(wR.hour) + ":" + Format(wR.min)) End If
' If recordDate > lastDateInDb Then ' add to the database ' update the new record counter newRecCount = newRecCount + 1 ' transfer the data to the Database rs.AddNew rs("Date_Time") = recordDate rs("OutSideTemp") = GetOutsideTemp rs("HighOutSideTemp") = GetHiOutsideTemp rs("LowOutSideTemp") = GetLowOutsideTemp rs("WindSpeed") = GetWindSpeed rs("HiWindSpeed") = GetHiWindSpeed rs("WindDirection") = GetWindDirection rs("DailyRain") = GetDailyRain * 0.1 rs.Update Next r adoconn.Close End Function
|
|
|
|
|
Logged
|
|
|
|
|
jruys
|
 |
« Reply #7 on: December 29, 2009, 09:42:36 AM » |
|
Hi cmgaskins, It appears that you are still using the current data to populate your database, not the WeatherRecord struct near the bottom of your code. Not sure if that was intentional or not. I would have thought you would have did something like: rs("OutSideTemp") = wR.outsideTemp . The way your code is written you would still have the problem of missing data if your computer was off.
|
|
|
|
|
Logged
|
|
|
|
cmgaskins
Member
Offline
Posts: 27
|
 |
« Reply #8 on: December 29, 2009, 10:30:57 AM » |
|
Jruys, you are correct. Guess that’s why I need help from the pros, I'm learning just slow........ 
|
|
|
|
|
Logged
|
|
|
|
|