Author Topic: ModbusRTU driver not closing?  (Read 2826 times)

needhmi

  • Newbie
  • *
  • Posts: 27
    • View Profile
ModbusRTU driver not closing?
« on: June 01, 2017, 05:09:20 PM »
My solution has two forms, and both need the ModbusRTU driver.  I put the BasicDataLogger21 on page 2 and for some reason the pollrate seems much slower.  It seems that the slowness is caused from the mainform's driver remaining active.  When I go back to the main form, there is no normal delay for the driver to connect. 

I'm using a FormChangeButton to change forms.  Is there a different button I need to use or a setting I possibly have missed to close the mainform when I open page 2?

Thanks! 

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: ModbusRTU driver not closing?
« Reply #1 on: June 01, 2017, 05:19:21 PM »
Do you have the following code behind both 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

Phrog30

  • Guest
Re: ModbusRTU driver not closing?
« Reply #2 on: June 01, 2017, 05:44:49 PM »
Archie, off topic, but how do you safe your code snippets?

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: ModbusRTU driver not closing?
« Reply #3 on: June 01, 2017, 05:50:41 PM »
Archie, off topic, but how do you safe your code snippets?
Do you mean incorporating them into the Visual Studio code snippet tool like this:

https://docs.microsoft.com/en-us/visualstudio/ide/walkthrough-creating-a-code-snippet

needhmi

  • Newbie
  • *
  • Posts: 27
    • View Profile
Re: ModbusRTU driver not closing?
« Reply #4 on: June 01, 2017, 06:13:58 PM »
I do have that- I didn't change any of that- sorry I didn't mention that before. 

Phrog30

  • Guest
Re: ModbusRTU driver not closing?
« Reply #5 on: June 01, 2017, 06:15:29 PM »
Archie, off topic, but how do you safe your code snippets?
Do you mean incorporating them into the Visual Studio code snippet tool like this:

https://docs.microsoft.com/en-us/visualstudio/ide/walkthrough-creating-a-code-snippet

Yes, just curious if you use that or something else as a repository.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: ModbusRTU driver not closing?
« Reply #6 on: June 01, 2017, 06:24:17 PM »
I do have that- I didn't change any of that- sorry I didn't mention that before.
What do you have the PollRateOverride set to for the driver instance on the second form.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: ModbusRTU driver not closing?
« Reply #7 on: June 01, 2017, 06:24:57 PM »
Yes, just curious if you use that or something else as a repository.
I do not have a formal repository that I use for code snippets.

needhmi

  • Newbie
  • *
  • Posts: 27
    • View Profile
Re: ModbusRTU driver not closing?
« Reply #8 on: June 01, 2017, 07:05:19 PM »
I have the poll rate set to zero on the second form.  If I cut and paste the BasicDataLogger21 onto the main form it's better before I open form 2, but if I open form 2 it is still slow even just viewing data, without the datalogger tied to the form.  I'm logging 20 addresses at a 40ms time interval. 

The only reason I am using it on page 2 is because I wanted the HMI to open in a not logging state and I could not get the pause logging feature to work.  Two forms set up like this works fine with less addresses, and it works fine with all 20 when just using a single form. 

I cleaned the project after the changes and rebuilt if that is a good practice.

Thanks for the help.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: ModbusRTU driver not closing?
« Reply #9 on: June 01, 2017, 08:56:44 PM »
Try setting the PollRateOverride to 40 and set your BasicDataLogger2 property of LogTriggerType to EverySample

needhmi

  • Newbie
  • *
  • Posts: 27
    • View Profile
Re: ModbusRTU driver not closing?
« Reply #10 on: June 06, 2017, 12:37:08 PM »
Thanks for that suggestion - even though it did not improve things much if any, it obviously was worth a try - I wasn't very confident the way I had it set up was the best way. 

I set up a datalogger in the main page as well and the proof of it disposing after a form change is in the log, still not sure the driver is closing however. 

Is the lack of connection delay when navigating to another form evidence that the driver is not closing?  I looked in my event logs on my computer to see if it was listed- didn't see it but I am no expert looking at those. 

I'll just have to use one form for now until this is solved so it's not too big of a deal, but would be nice to get both forms working. 

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: ModbusRTU driver not closing?
« Reply #11 on: June 06, 2017, 12:46:12 PM »
Something else to try..... For every driver instance, set the EnableLogging property to True. It should then create a log file of all communications.

needhmi

  • Newbie
  • *
  • Posts: 27
    • View Profile
Re: ModbusRTU driver not closing?
« Reply #12 on: June 06, 2017, 08:20:32 PM »
I forgot about that function.  For some reason the app crashes with that enabled- it does log for a few seconds. 

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: ModbusRTU driver not closing?
« Reply #13 on: June 06, 2017, 08:29:55 PM »
Do you get a file within those few seconds? My guess is the data is coming faster than it can open and close the file, so it causes a crash.

needhmi

  • Newbie
  • *
  • Posts: 27
    • View Profile
Re: ModbusRTU driver not closing?
« Reply #14 on: June 07, 2017, 04:35:00 PM »
Yeah I do get a file with quite a few lines.  Will it tell me if both driver instances are active?  I don't have quite enough time to change forms before it crashes so I just assumed it wasn't enough of a log.  Could I change something temporarily just to test?