AdvancedHMI Software

General Category => Support Questions => Topic started by: Derek on August 22, 2017, 07:10:39 PM

Title: BasicDataLogger2 sql database
Post by: Derek 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!
Title: Re: DataSubscriber2 sql database
Post by: Archie 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
Title: Re: BasicDataLogger2 sql database
Post by: Derek 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.
Title: Re: BasicDataLogger2 sql database
Post by: PLCTech 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
Title: Re: BasicDataLogger2 sql database
Post by: Phrog30 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.
Title: Re: BasicDataLogger2 sql database
Post by: Archie 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?
Title: Re: BasicDataLogger2 sql database
Post by: PLCTech 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!
Title: Re: BasicDataLogger2 sql database
Post by: Archie 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
Title: Re: BasicDataLogger2 sql database
Post by: Archie 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.
Title: Re: BasicDataLogger2 sql database
Post by: PLCTech 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?
Title: Re: BasicDataLogger2 sql database
Post by: Archie 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.
Title: Re: BasicDataLogger2 sql database
Post by: PLCTech 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.
Title: Re: BasicDataLogger2 sql database
Post by: Archie 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?
Title: Re: BasicDataLogger2 sql database
Post by: PLCTech 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.
Title: Re: BasicDataLogger2 sql database
Post by: Archie 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?
Title: Re: BasicDataLogger2 sql database
Post by: PLCTech on January 29, 2019, 12:58:48 PM
Ideally yes, I would like to capture everything once they have all changed. Only other issue is the downtime reason may stay a zero, depending on how the logic captures the event. So it may not really matter that there are multiple lines. We may be able to code around that on the other end of what we are trying to do.
Title: Re: BasicDataLogger2 sql database
Post by: Archie on January 29, 2019, 01:00:36 PM
Ideally yes, I would like to capture everything once they have all changed. Only other issue is the downtime reason may stay a zero, depending on how the logic captures the event. So it may not really matter that there are multiple lines. We may be able to code around that on the other end of what we are trying to do.
So you only want to log a record when all 4 values have changed?
Title: Re: BasicDataLogger2 sql database
Post by: PLCTech on January 29, 2019, 01:11:34 PM
Yes, ideally that is what I would like. But would all of the values have to change, or can some of them remain unchanged. And example would be:

When the Machine Running bit goes TRUE, then the downtime reason value should go to zero. When the Machine Running bit goes FALSE, the downtime reason may remain a zero, depending on whether or not the logic in the PLC has enough coding to recognize all stops. If it doesn't then the downtime reason would remain a zero. Will this mess up the Advanced HMI coding? Perhaps I should just leave well enough alone and let the programmer on the other end of this project sort out the various lines in the .log file.
Title: Re: BasicDataLogger2 sql database
Post by: Archie on January 29, 2019, 01:59:22 PM
Yes, ideally that is what I would like. But would all of the values have to change, or can some of them remain unchanged. And example would be:

When the Machine Running bit goes TRUE, then the downtime reason value should go to zero. When the Machine Running bit goes FALSE, the downtime reason may remain a zero, depending on whether or not the logic in the PLC has enough coding to recognize all stops. If it doesn't then the downtime reason would remain a zero. Will this mess up the Advanced HMI coding? Perhaps I should just leave well enough alone and let the programmer on the other end of this project sort out the various lines in the .log file.
It sounds like you want to log any time the Machine Running changes value irrelevant of whether the other values change or not.
Title: Re: BasicDataLogger2 sql database
Post by: PLCTech on January 29, 2019, 02:35:01 PM
I really want to capture the machine running bit and the downtime reason. The Machine ID does not change since I read each machine separately into their own files. I think I will leave the code as is and get the programmer to figure out something on his end,

Thanks.