Author Topic: BasicDataLogger2 sql database  (Read 6349 times)

Derek

  • Newbie
  • *
  • Posts: 2
    • View Profile
BasicDataLogger2 sql database
« on: August 22, 2017, 07:10:39 PM »
Using BasicDataLogger2 I'm inserting a row in MySql. I wish each PLC value that's in the PLCAddressValueItems would be inserted into one row. The issue is that each row contains one PLC value that alternates between the three values.

Can I make BasicDataLogger2 insert multiple columns into sql?

The three PLC value's are (Value1, Value2, and Value3) and the three MySql columns are (c1, c2, and c3).

Here is the code I'm using:

    Private Sub BasicDataLogger21_DataReturned(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles BasicDataLogger21.DataReturned
        Using t As New DataSet.logDataTable
            t.AddlogRow(t.NewRow)
            t(0).c1 = e.Values(0)
            Using ta As New DataSetTableAdapters.logTableAdapter
                ta.Update(t)
            End Using
        End Using
    End Sub

I'm using Windows 10 Pro, Visual Studio 15.3.2, and AdvancedHMI v399x.

Thanks!
« Last Edit: August 23, 2017, 06:30:55 AM by Derek »

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: DataSubscriber2 sql database
« Reply #1 on: August 22, 2017, 07:26:14 PM »
The DataReturned is going to fire separately for each tag value. You are going to have to save the value in a class scope variable, then when the last is returned, store to the DB.

 Private Value1, Value2 as string
 Private Sub BasicDataLogger21_DataReturned(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles BasicDataLogger21.DataReturned
        if e.PLCAddress=DataSubscriber2.PLCAddressValueItems(0).PLCAddress Then
                 Value1=e.Values(0)
        ElseIf e.PLCAddress=DataSubscriber2.PLCAddressValueItems(1).PLCAddress Then
                  Value2=e.Values(0)
        Else
           Using t As New sasDataSet.nwpresslogDataTable, ta As New sasDataSetTableAdapters.nwpresslogTableAdapter
               t.AddnwpresslogRow(t.NewRow)
               t(0).c1 = Value1
               t(0).c2 = Value2
               t(0).c3 = e.Values(0)
               ta.Update(t)
           End Using
       End If
 End Sub
« Last Edit: August 22, 2017, 07:28:11 PM by Archie »

Derek

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: BasicDataLogger2 sql database
« Reply #2 on: August 23, 2017, 06:26:50 AM »
Quote
Private Value1, Value2 as string
 Private Sub BasicDataLogger21_DataReturned(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles BasicDataLogger21.DataReturned
        if e.PLCAddress=BasicDataLogger21.PLCAddressValueItems(0).PLCAddress Then
                 Value1=e.Values(0)
        ElseIf e.PLCAddress=BasicDataLogger21.PLCAddressValueItems(1).PLCAddress Then
                  Value2=e.Values(0)
        Else
           Using t As New DataSet.logDataTable, ta As New DataSetTableAdapters.logTableAdapter
               t.AddlogRow(t.NewRow)
               t(0).c1 = Value1
               t(0).c2 = Value2
               t(0).c3 = e.Values(0)
               ta.Update(t)
           End Using
       End If
 End Sub

Thanks Archie!

This worked great.
« Last Edit: August 23, 2017, 06:32:02 AM by Derek »

PLCTech

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: BasicDataLogger2 sql database
« Reply #3 on: January 29, 2019, 07:46:31 AM »
I know this is an old post, but I am trying to use it so that I get all of the data at once from the DataLogger2 rather than as each piece of information is fired. However I don't understand where this code needs to be set up as it fails when I build the application:

Using t As New sasDataSet.nwpresslogDataTable, ta As New sasDataSetTableAdapters.nwpresslogTableAdapter

All of the other code I can modify (it seems to build OK, except for this section). I am not really a VB programmer, ladder logic is my forte!

Thanks

Phrog30

  • Guest
Re: BasicDataLogger2 sql database
« Reply #4 on: January 29, 2019, 08:53:28 AM »
If you don't know what it does, just comment it out and hope for the best.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: BasicDataLogger2 sql database
« Reply #5 on: January 29, 2019, 09:55:51 AM »
I don't understand where this code needs to be set up as it fails when I build the application:

Using t As New sasDataSet.nwpresslogDataTable, ta As New sasDataSetTableAdapters.nwpresslogTableAdapter

Did you use the Data Sources tool to create a Data Source?

PLCTech

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: BasicDataLogger2 sql database
« Reply #6 on: January 29, 2019, 10:45:25 AM »
That is what I was thinking I would have to do, but I am lost when it comes to that!

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: BasicDataLogger2 sql database
« Reply #7 on: January 29, 2019, 10:56:03 AM »
It is fairly straight forward because there are wizards to walk you through the process. Start by going to Project->Add New Data Source

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: BasicDataLogger2 sql database
« Reply #8 on: January 29, 2019, 11:13:33 AM »
Once you select Add New Data Source, select the Database option
The next window will give you a button to add a new connection
Select that and enter the information about your database
After that, select the table you want to store the data in

The original thread used a BasicDataLogger2 which is kind of redundant if you want to store to a database. The BasicDataLogger stores to a text file. If you do not need the text file, a DataSubcriber2 is more fitting.

PLCTech

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: BasicDataLogger2 sql database
« Reply #9 on: January 29, 2019, 12:08:03 PM »
I would like to save it to a text file (.log). Do you still have to create a Data Source?

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: BasicDataLogger2 sql database
« Reply #10 on: January 29, 2019, 12:34:53 PM »
I would like to save it to a text file (.log). Do you still have to create a Data Source?
In that case, none of this stuff really applies. Simply add the BasicDataLogger2 to your form and use PLCAddressItems to list the addresses you want to log.

PLCTech

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: BasicDataLogger2 sql database
« Reply #11 on: January 29, 2019, 12:38:11 PM »
That is what I am currently doing. I am also using the script that I found on here that makes a new file for each day. The issue is I get multiple entries in the .log file each time one of the datapoints I am monitoring changes state. I am guessing that it is due to their location in the PLC and the scan time of the PLC. They do not all update at once.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: BasicDataLogger2 sql database
« Reply #12 on: January 29, 2019, 12:39:53 PM »
The issue is I get multiple entries in the .log file each time one of the datapoints I am monitoring changes state. I am guessing that it is due to their location in the PLC and the scan time of the PLC. They do not all update at once.
Multiple lines or a comma separated list of all the values?

PLCTech

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: BasicDataLogger2 sql database
« Reply #13 on: January 29, 2019, 12:46:47 PM »
Multiple lines. Each line has a different value for the comma separated values and a different time stamp.

Jan-29-19 12:45:48:175,,44,72
Jan-29-19 12:45:48:284,False,44,72

In the first line the first comma separated value was not read, then in the second line it was. I am reading three separate points in a PLC. The False indicates that the machine is not running, the 44 is the Machine ID number and the 72 is the downtime reason.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: BasicDataLogger2 sql database
« Reply #14 on: January 29, 2019, 12:50:26 PM »
Typically your will have a few lines with no values until it had a chance to read them all. So if you have 5 values to log, you may see up to 4 lines initially with missing values. Is this what you want to eliminate?