Public Sub Main(ByVal Parms As Object)
Dim devValue As String = hs.DeviceVSP_GetStatus(Parms, hs.DeviceValueEx(Parms), ePairStatusControl.Status)
Dim devName As String = Nothing
Dim dev As Scheduler.Classes.DeviceClass
dev = hs.GetDeviceByRef(Parms)
devName = dev.Name(hs)
Dim devTime As DateTime
devTime = DateTime.Now
Dim devValue2 As String = devValue.Remove(devValue.Length - 3)
Dim devValueInt As Integer = Convert.ToInt32(devValue2)
'If devValue2.Length > 2 Then
hs.WriteLog("WriteToSql - Device# "+ Parms, devValue)
Dim myconnect As New System.Data.SqlClient.SqlConnection
myconnect.ConnectionString = "Data Source=tcp:server,49172;Initial Catalog=HomeSeer;Persist Security Info=True;User ID=HS;Password=xxxx"
Dim mycommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand()
mycommand.Connection = myconnect
mycommand.CommandText = "INSERT INTO dbo.devLog (devRef, devName, devValue, devTime, devValueInt) VALUES (@Parms, @devName, @devValue, GETUTCDATE(), @devValueInt)"
myconnect.Open()
Try
mycommand.Parameters.Add("@Parms", SqlDbType.Int).Value = Parms
mycommand.Parameters.Add("@devName", SqlDbType.NVarChar).Value = devName
mycommand.Parameters.Add("@devValue", SqlDbType.VarChar).Value = devValue.Remove(devValue.Length - 3)
mycommand.Parameters.Add("@devValueInt", SqlDbType.Int).Value = devValueInt
mycommand.Parameters.Add("@devTime", SqlDbType.VarChar).Value = devTime
mycommand.ExecuteNonQuery()
'MsgBox("Success")
Catch ex As System.Data.SqlClient.SqlException
'MsgBox(ex.Message)
End Try
myconnect.Close()
''
'End If
End Sub
Trigger denne hver gang jeg leser av forbruket via HAN porten