Author Topic: Dynamically loading Com driver and BasicDataLog.  (Read 2022 times)

vitico bon

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
Dynamically loading Com driver and BasicDataLog.
« on: December 03, 2016, 11:57:16 AM »
Sorry I have to return to this topic once more. but I have the code shown below loading a communication driver and two basic loggers for each system connected to the PC, everything appears to work  find, data is going to the two files each 20 seconds as expected. But this morning adding a asynchronous read when started to implement the DataReceived event I found out that the first logger (the one reading "F428675") is firing reads every second, the other one dose it timely every 20 seconds. Any suggestion?

           ' Set the name of the files.
            Dim today1 As Date = Date.Today   
            Dim dayDiff1 As Integer = today1.DayOfWeek - DayOfWeek.Sunday
            Dim Sunday1 As Date = today1.AddDays(-dayDiff1)
            LevelFileName = Format$(Sunday1, "MMM-dd-yyyy") & "-L.dlog"
            PressFileName = Format$(Sunday1, "MMM-dd-yyyy") & "-P.dlog"
        For i = 1 To NumberOfSystems

            If (Not System.IO.Directory.Exists(Path.GetDirectoryName(Application.ExecutablePath) & "\DATA\" & Bubbles(i).Bsystem)) Then
                System.IO.Directory.CreateDirectory(Path.GetDirectoryName(Application.ExecutablePath) & "\DATA\" & Bubbles(i).Bsystem)
            End If

            Port(i) = New AdvancedHMIDrivers.ModbusRTUCom
            Port(i).PortName = "COM1"
            Port(i).BaudRate = 19200
            Port(i).Parity = Ports.Parity.Odd
            Port(i).DataBits = 8
            Port(i).PollRateOverride = 1000
            Port(i).StationAddress = Bubbles(i).MBStation
            Port(i).StopBits = Ports.StopBits.One
            Port(i).SwapBytes = True
            Port(i).SwapWords = False
            Port(i).TimeOut = 3000
            Port(i).MyTag = i

            AddHandler Port(i).DataReceived, AddressOf AllDataReceived

            ' Now load two data logger for Level and Pressure.
            l = i * 2
            Logger(l) = New AdvancedHMIControls.BasicDataLogger

            Logger(l).BeginInit()
            Logger(l).ComComponent = Port(i)
            Logger(l).FileFolder = Path.GetDirectoryName(Application.ExecutablePath) & "\DATA\" & Bubbles(i).Bsystem
            Logger(l).FileName = LevelFileName
            Logger(l).LogInterval = 20000
            Logger(l).LogTriggerType = AdvancedHMIControls.BasicDataLogger.TriggerType.TimeInterval
            Logger(l).PLCAddressValue = New MfgControl.AdvancedHMI.Drivers.PLCAddressItem("F428675")
            Logger(l).TimeStampFormat = "MMM-dd-yyyy hh:mm:ss tt"
            Logger(l).EndInit()

            p = (i * 2) - 1

            Logger(p) = New AdvancedHMIControls.BasicDataLogger

            Logger(p).BeginInit()
            Logger(p).ComComponent = Port(i)
            Logger(p).FileFolder = Path.GetDirectoryName(Application.ExecutablePath) & "\DATA\" & Bubbles(i).Bsystem
            Logger(p).FileName = PressFileName
            Logger(p).LogInterval = 20000
            Logger(p).LogTriggerType = AdvancedHMIControls.BasicDataLogger.TriggerType.TimeInterval
            Logger(p).PLCAddressValue = New MfgControl.AdvancedHMI.Drivers.PLCAddressItem("F428679")
            Logger(p).TimeStampFormat = "MMM-dd-yyyy hh:mm:ss tt"
            Logger(p).EndInit()
        Next


Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Dynamically loading Com driver and BasicDataLog.
« Reply #1 on: December 03, 2016, 01:43:22 PM »
I just tried your code, with the exception of "Port(i).MyTag = I" because there is no MyTag property, and then I also added a button to my form with the click handler code with this:

Port(1).BeginRead("F428677")

I ran the application and clicked the button several times, but both files are still collecting at 20 second intervals in my test.
Code: [Select]
Dec-03-2016 01:36:58 PM,890
Dec-03-2016 01:37:18 PM,890
Dec-03-2016 01:37:38 PM,890
Dec-03-2016 01:37:58 PM,890
Dec-03-2016 01:38:18 PM,890
Dec-03-2016 01:38:38 PM,890
Dec-03-2016 01:38:58 PM,890
Dec-03-2016 01:39:18 PM,890
Code: [Select]
Dec-03-2016 01:36:58 PM,345
Dec-03-2016 01:37:18 PM,345
Dec-03-2016 01:37:38 PM,345
Dec-03-2016 01:37:58 PM,345
Dec-03-2016 01:38:18 PM,345
Dec-03-2016 01:38:38 PM,345
Dec-03-2016 01:38:58 PM,345
Dec-03-2016 01:39:18 PM,345

Is there something more you are doing that I am missing?

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Dynamically loading Com driver and BasicDataLog.
« Reply #2 on: December 03, 2016, 01:54:46 PM »
I think I initially misunderstood what you were explaining. I think you meant the DataReceived fires every second, not the values stored in the file.

If that is the case, this is what you are seeing:

A BasicDataLogger works off subscriptions. Subscription updates are based on the PollRateOverride. You have you PollRate override set to 1000ms, therefore the driver reads the data every 1 second. You may only be looking at e.Values(0), but if you look at e.Values(2) you will then see the value returned for your other register is also returned at the same time.

Subscriptions optimize their reads by grouping values. It is more efficient to read 3 values in a single packet that it is to read the 2 values each with their own packet.

vitico bon

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
Re: Dynamically loading Com driver and BasicDataLog.
« Reply #3 on: December 03, 2016, 03:33:09 PM »
Yes that is exactly right, I was collecting at the correct rate, but pulling every 1 sec, now if that is the way the cookie crumbles, it is fine with me, and the optimization that you detail make sense and is common practice in communication application.   My only worry was that I was doing something grown.

Once more, thanks for the fast response.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Dynamically loading Com driver and BasicDataLog.
« Reply #4 on: December 03, 2016, 03:51:13 PM »
You can always increase the PollRateOverride since the subscriptions for that instance seem to be dedicated to your DataLoggers. But keep in mind your logged data could be as old as your value. For instance, if you set 10000 PollRateOverride, the sample stored to the file could be as old as 10 seconds.

A better option is probably to skip the data logger all together. Set the PollRateOverride to 20000, create a subscription to your data, then use the DataReceived event to write the values to a file.

vitico bon

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
Re: Dynamically loading Com driver and BasicDataLog.
« Reply #5 on: December 03, 2016, 06:48:55 PM »
Yes, at the end I decide to get rid of the Data logger, after all it was only saving me a few lines of code, so I went with a BegeinRead in a 20 second timer and send the result to two separated files in the DataReceived event. I worked out great.

I already had something similar with an alarm logger that run each second looking for alarms event to be send to an alarm file.

Thanks for your help. 

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Dynamically loading Com driver and BasicDataLog.
« Reply #6 on: December 03, 2016, 08:55:57 PM »
Using a subscription would be even simpler because you would not have to create a timer. A subscription would also be more repeatable because it does not use a timer, but instead a background thread throttled to the PollRateOverride.