Author Topic: Problems with Chartwithlogging  (Read 1916 times)

francis

  • Newbie
  • *
  • Posts: 15
    • View Profile
Problems with Chartwithlogging
« on: March 07, 2020, 12:22:15 AM »
I am using chartwithlogging on 3 forms for different items. The trends have stopped logging. How can I solve this?

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5272
    • View Profile
    • AdvancedHMI
Re: Problems with Chartwithlogging
« Reply #1 on: March 07, 2020, 08:18:38 AM »
Do you have the code behind the form that Disables driver subscriptions when the form is hidden?

francis

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Problems with Chartwithlogging
« Reply #2 on: March 07, 2020, 09:18:26 AM »
How do I access the code?

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5272
    • View Profile
    • AdvancedHMI
Re: Problems with Chartwithlogging
« Reply #3 on: March 07, 2020, 09:34:01 AM »
Right click form and select View Code. If you haven't accessed the code, then I'm guessing you do not have the code there to disable the subscriptions, unless you copied the MainForm

francis

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Problems with Chartwithlogging
« Reply #4 on: March 07, 2020, 09:59:13 AM »
I can't access the full code, just 8 lines

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5272
    • View Profile
    • AdvancedHMI
Re: Problems with Chartwithlogging
« Reply #5 on: March 07, 2020, 10:53:56 AM »
That is about all the default code there is to a form.

JohnnyTronic

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Problems with Chartwithlogging
« Reply #6 on: March 07, 2020, 01:22:41 PM »
So when we make another form we should make a copy of the main form and rename it? I made a three form trial application, i used the main form, page 2 and then I think I just used a windows form for the third page.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5272
    • View Profile
    • AdvancedHMI
Re: Problems with Chartwithlogging
« Reply #7 on: March 07, 2020, 03:22:20 PM »
So when we make another form we should make a copy of the main form and rename it? I made a three form trial application, i used the main form, page 2 and then I think I just used a windows form for the third page.
Copying a form is not as easy as creating a new form because you have to rename 2 classes. When making a new form, you should copy the default code that us behind the MainForm. This code minimizes communication overhead when a form is hidden.

Godra

  • Hero Member
  • *****
  • Posts: 1439
    • View Profile
Re: Problems with Chartwithlogging
« Reply #8 on: March 08, 2020, 09:08:05 PM »
Here is what a code could look like on all additional forms:

Code: [Select]
    '*******************************************************************************
    '* Stop polling when the form is not visible in order to reduce communications
    '* Copy this section of code to every new form created
    '*******************************************************************************
    Private NotFirstShow As Boolean

    Private Sub Form_VisibleChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.VisibleChanged
        '* Do not start comms on first show in case it was set to disable in design mode
        If NotFirstShow Then
            AdvancedHMIDrivers.Utilities.StopComsOnHidden(components, Me)
        Else
            NotFirstShow = True
        End If
    End Sub

    Private Sub FormClosing_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.FormClosing
        MainForm.Show()
        Me.Visible = False
    End Sub


Also, for each of your ChartWithlogging controls, you should set a different DataDirectory.

You could use FormChangeButton control to switch between forms.

« Last Edit: March 08, 2020, 09:12:23 PM by Godra »

JohnnyTronic

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Problems with Chartwithlogging
« Reply #9 on: March 11, 2020, 11:24:55 PM »
I added your code to my third form. So I have the main form, page 2 and the new form. I added buttons to the main form to go to the other forms and buttons to return. When i reopen the mainform from the new form it opens at about one fourth size and not in the upper left corner but at the bottom on the screeen. When I open the mainform from page2 it opens as the normal size and in the upper left of the screen.

I have reviewed the button and the form settings and dont see anything I can change to fix this.

Thanks for your help.

Godra

  • Hero Member
  • *****
  • Posts: 1439
    • View Profile
Re: Problems with Chartwithlogging
« Reply #10 on: March 11, 2020, 11:52:37 PM »
You need to familiarize yourself with different properties of the form as well as controls and components.

The form's StartPosition property determines the position of the form when it first appears and the WindowState property determines the initial visual state of the form.

If you change the value of any property, not only the ones mentioned above, then run the program to see how it was affected by that change.

You should as well Google these issues when they appear.

Godra

  • Hero Member
  • *****
  • Posts: 1439
    • View Profile
Re: Problems with Chartwithlogging
« Reply #11 on: March 12, 2020, 12:05:54 AM »
The code is already set to show the MainForm when the other forms are closed:

Code: [Select]
    Private Sub FormClosing_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.FormClosing
        MainForm.Show()
        Me.Visible = False
    End Sub

The "MainForm.Show()" line states to show the MainForm so you shouldn't have buttons to do that.


Godra

  • Hero Member
  • *****
  • Posts: 1439
    • View Profile
Re: Problems with Chartwithlogging
« Reply #12 on: March 12, 2020, 12:48:42 AM »
Since you are still learning, try to understand the code instead of just doing plain copy/paste.

The FormClosing event occurs when you click the "X" in the top right corner (with an intention to close the form).
The code posted in my previous post is telling the program to process those 2 lines of code during this event:
        MainForm.Show() <-- Show the MainForm
        Me.Visible = False  <-- Hide the current form instead of closing it

The FormChangeButton should be placed on the MainForm, one button for Page2 and one for Page3, and this button is already designed to hide the MainForm (or whatever form it is placed on) and to open/show the form you specify.

If you look at the code of the MainForm, it is processing its FormClosing event differently, with a comment that explains what it's doing:

Code: [Select]
    '***************************************************************
    '* .NET does not close hidden forms, so do it here
    '* to make sure forms are disposed and drivers close
    '***************************************************************
    Private Sub MainForm_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
        Dim index As Integer
        While index < My.Application.OpenForms.Count
            If My.Application.OpenForms(index) IsNot Me Then
                My.Application.OpenForms(index).Close()
            End If
            index += 1
        End While
    End Sub


« Last Edit: March 12, 2020, 12:58:18 AM by Godra »

JohnnyTronic

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Problems with Chartwithlogging
« Reply #13 on: March 12, 2020, 03:31:33 AM »
Great reply and support. Yes the code is hard to grasp at this point. I will try your solution tomorrow.

stevejobs27

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Problems with Chartwithlogging
« Reply #14 on: April 30, 2020, 02:37:49 PM »
Hello !
I have had some success with Chartwithlogging - I like it ! I was hoping to get a chart/trend which shows the date/time along the x-axis with the ability to pan and zoom - great !
I have a couple of questions please:
How and where is the data stored... I saw the property "data directory" with ./ in the box. Should I be entering a folder location and file name in there to store the relevant data ? I am currently logging 2 tags from the same PLC using the same driver in my "collection".
Oh what is the "File Header" property for ?
AND... is it possible to change the colour of the pens on the trend ?
I have been successful in using Datalogger2 and am storing 2 tags values on the PC in the log file - which I can then present in excel - it would be nice if there are charts in AHMI which can simply display the data from those log files (for historic trending).(or is that exactly what this can do !?)  :)
I'm not great with VB but seem to be getting by and understanding some of the basics - such as hiding the form when not in use, and the comments about closing the main form as discussed earlier - I think I got that now and have 5 forms which appear to work OK - I was worried that the chartwithlogging would STOP logging if it was not visible...
I think I had an issue whereby if I CLOSED the runtime, it would appear to have closed but the advancedHMI process would stay running in memory thus preventing me from being able to compile any more - I had to keep killing the process in task manager (I think that may have been due to not CLOSING the pages correctly as discussed earlier !)
Thanks,
Steve