1
Application Showcase / Re: Custom Trending with SQLite
« on: May 27, 2021, 07:12:54 AM »
I have not tried MS Power BI. I have tried to stick with an open source stack.
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Would the base tag be like a prefix to the other tags? For example you would pass a base tag of "Motor1" and the tags to be check would be "Motor1Amps", "Motor1Speed", etc
Private Sub DataSubscriber21_DataReturned(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber21.DataReturned
Dim tstamp As String = DateAndTime.Now
Dim hrnow As Integer = DateAndTime.Now.TimeOfDay.Hours
Dim p1speed As Integer
Dim p1amps As Integer
Dim p1temp As Integer
If Not System.IO.File.Exists(fullname) Then
Dim ct As String = "CREATE TABLE Trends (tstamp Datetime,p1speed Integer,p1amps Integer, p1temp Integer);"
Using sqlconn As New SQLite.SQLiteConnection(cs)
Dim cmd As New SQLiteCommand(ct, sqlconn)
sqlconn.Open()
cmd.ExecuteNonQuery()
End Using
End If
If e.PlcAddress = "400201" Then
p1speed = e.Values(0)
End If
If e.PlcAddress = "400202" Then
p1amps = e.Values(0)
End If
If e.PlcAddress = "400103" Then
p1temp = CInt(e.Values(0))
End If
Dim myconnection As New SQLiteConnection(cs)
myconnection.Open()
Dim cmdd As New SQLiteCommand
cmdd.Connection = myconnection
cmdd.Parameters.AddWithValue("@tstamp", tstamp)
cmdd.Parameters.AddWithValue("@p1speed", p1speed)
cmdd.Parameters.AddWithValue("@p1amps", p1amps)
cmdd.Parameters.AddWithValue("@p1temp", p1temp)
cmdd.CommandText = "Insert into Trends (tstamp,p1speed,p1amps,p1temp) VALUES(@tstamp,@p1speed,@p1amps,@p1temp)"
cmdd.ExecuteNonQuery()
myconnection.Close()
End Sub
End Class
Dim tstamp As String = DateAndTime.Now
Dim hrnow As Integer = DateAndTime.Now.TimeOfDay.Hours
Dim p1speed As String
Dim p1amps As Integer
Dim p1temp As Integer
If Not System.IO.File.Exists(fullname) Then
Dim ct As String = "CREATE TABLE Trends (tstamp Text,p1speed Integer,p1amps Integer, p1temp Integer);"
Using sqlconn As New SQLite.SQLiteConnection(cs)
Dim cmd As New SQLiteCommand(ct, sqlconn)
sqlconn.Open()
cmd.ExecuteNonQuery()
End Using
End If
If e.PlcAddress = "400201" Then
p1speed = e.Values(0)
End If
If e.PlcAddress = "400202" Then
p1amps = e.Values(0)
End If
If e.PlcAddress = "400103" Then
p1temp = CInt(e.Values(0))
End If
Dim myconnection As New SQLiteConnection(cs)
myconnection.Open()
Dim cmdd As New SQLiteCommand
cmdd.Connection = myconnection
cmdd.CommandText = "Insert into Trends (tstamp,p1speed,p1amps,p1temp) VALUES(@tstamp,@p1speed,@p1amps,@p1temp)"
cmdd.Parameters.AddWithValue("@tstamp", tstamp)
cmdd.Parameters.AddWithValue("@p1speed", p1speed)
cmdd.Parameters.AddWithValue("@p1amps", p1amps)
cmdd.Parameters.AddWithValue("@p1temp", p1temp)
cmdd.ExecuteNonQuery()
myconnection.Close()
Dim myconnection As New SQLiteConnection("Data Source=C:\test.db")
myconnection.Open()
Dim cmd As New SQLiteCommand
cmd.Connection = myconnection
cmd.CommandText = "Select * from test01"
Dim rdr As SQLiteDataReader = cmd.ExecuteReader()
Dim dt As New DataTable
dt.Load(rdr)
rdr.Close()
Dim dat As Integer
dt.Rows.Item(0)("date") = CInt(Dat)
Dim inte As Integer
dt.Rows.Item(0)("int") = CInt(inte)
Chart1.Series(0).XValueMember = Dat
Chart1.Series(0).YValueMembers = inte
Chart1.ChartAreas(0).AxisX.Minimum = 1
Chart1.ChartAreas(0).AxisX.Maximum = 52
Chart1.DataSource = dt