AdvancedHMI Software

General Category => Support Questions => Topic started by: AabeckControls on June 06, 2018, 11:40:40 AM

Title: Object Reference Nor Set o An Inistance.." Using AB DF1 & 399Vw
Post by: AabeckControls on June 06, 2018, 11:40:40 AM
I have a machine with a version W AdvancedHMI using SerialDF1forSLCMicroCom1 to a SLC5/03

On a screen of value entries/display most of the time it shows the correct value and can enter and change them to a new value - however I frequently get values displaying the error "Object Reference Not Set To An Instance Of An Object" I have searched the forum and the results that show are either for a very old version, or an Ethernet driver, and seem to put the fault on the driver.

This happens on 3 screens that I display and change between 2 recipes. All the other pages don't show this message on any of the values they have, and the driver is copied and pasted from MainForm with all the same settings.

Title: Re: Object Reference Nor Set o An Inistance.." Using AB DF1 & 399Vw
Post by: Archie on June 06, 2018, 03:05:14 PM
Can you update your application to version 3.99x to see if it corrects the issue?
Title: Re: Object Reference Nor Set o An Inistance.." Using AB DF1 & 399Vw
Post by: AabeckControls on June 06, 2018, 03:38:15 PM
Archie,

I will try to update it - but I have tried to update projects before to a newer version and either I'm not doing it right or missing something because it has never worked.
Title: Re: Object Reference Nor Set o An Inistance.." Using AB DF1 & 399Vw
Post by: Archie on June 06, 2018, 03:41:54 PM
The method of updating:

- Download and extract the latest version
- Open the latest version in VS
- In Solution Explorer, right click the AdvancedHMI project and select Add->Existing Item
- Browse to the old solution and select 1 form's *.vb file (perform these steps once for each form because they will not import if multiple are selected)

After importing all of the forms, you may get some errors. Post those errors and I will advise how to correct.
Title: Re: Object Reference Nor Set o An Inistance.." Using AB DF1 & 399Vw
Post by: AabeckControls on June 06, 2018, 06:23:25 PM
Archie,

I opened v399x, Built it, added all forms, graphics and a .TXT file

When I rebuilt it I got a few errors that PLCAddressHighlight is not a member of BasicButton on 2 pages. See screenshot.

When I tried to open those 2 pages I got the error screen and then it went to blank 300x300 screens for both (9 PLC and MainForm)

When I opened all the other pages I got an error screen with an error for every FormChangeButton on it, then the screens all opened with everything except all the FormChangeButtons. Adding these back won't be a problem.

I uploaded a zipped copy to We Transfer     https://we.tl/bcAJSq9yTU
Title: Re: Object Reference Nor Set o An Inistance.." Using AB DF1 & 399Vw
Post by: bachphi on June 06, 2018, 06:35:13 PM
try changing each to PLCAddressHighlightX.

Back to the original problem, since it is intermittent problem, I also assume that you use USB to serial adapter? If so, do you have a really good adapter?
Title: Re: Object Reference Nor Set o An Inistance.." Using AB DF1 & 399Vw
Post by: Godra on June 06, 2018, 06:50:09 PM
There is also a modified version of BasicButton here:

https://www.advancedhmi.com/forum/index.php?topic=1916.msg10739

It should be sufficient to add it to the Controls folder as existing item and replace the stock control.

You can always restore the stock control if this modified version doesn't help.
Title: Re: Object Reference Nor Set o An Inistance.." Using AB DF1 & 399Vw
Post by: Godra on June 06, 2018, 07:26:44 PM
I just tried your solution and it shows properly and switches between forms.

The only thing I did was to replace the BasicButton control.

The driver on Recipe1 form has its baud set to AUTO - maybe change it to 19200 like all other forms.
Title: Re: Object Reference Nor Set o An Inistance.." Using AB DF1 & 399Vw
Post by: AabeckControls on June 06, 2018, 08:07:20 PM
backphi,

No adapter, this computer has a serial port on the motherboard.

Godra,

I downloaded that BasicButton and will try it tomorrow. When you opened the project did all the formchange buttons show properly? No errors shown?

The AUTO baud rate was missed, I will change that tomorrow also.
Title: Re: Object Reference Nor Set o An Inistance.." Using AB DF1 & 399Vw
Post by: Godra on June 06, 2018, 08:48:15 PM
Everything shows properly.

Attached is a screenshot.

Title: Re: Object Reference Nor Set o An Inistance.." Using AB DF1 & 399Vw
Post by: AabeckControls on June 07, 2018, 07:25:39 AM
I added the new BasicButton and there were no errors during rebuild.

Then when I opened a screen I got the error page with all the FormChangeButton errors, so I added the FormChangeButton from Ver W and rebuilt, now all the pages open correctly.

I am on my way to the machine with the new build, I will let you know if everything works right or there is any problems.

Thank loads.

EDIT: I did change the baud on Recipe 1 to 19200 also.
Title: Re: Object Reference Nor Set o An Inistance.." Using AB DF1 & 399Vw
Post by: AabeckControls on June 07, 2018, 10:46:48 AM
I put the v399X project on the machine and still get various, random "Object Reference.." errors - only on the 3 recipe screens.

I did change the baud on Recipe 1 to 19200 like all the others.

Now, for displaying the Steps1.txt I get an error on MainForm - and I added it to the project, and copied it into the Debug folder, before I rebuilt it.

Everything else is working as it should so far, but still testing all operations.
Title: Re: Object Reference Nor Set o An Inistance.." Using AB DF1 & 399Vw
Post by: Archie on June 07, 2018, 10:51:26 AM
Now, for displaying the Steps1.txt I get an error on MainForm - and I added it to the project, and copied it into the Debug folder, before I rebuilt it.
After you add a file to the AdvancedHMI project, if you select it in Solution Explorer, then in the Properties Window set the CopyToOutputFolder, it will place it in the Debug folder automatically on each Build.


Do you get any more details on the error? In particular I'm looking for a stack trace that will give a line number.
Title: Re: Object Reference Nor Set o An Inistance.." Using AB DF1 & 399Vw
Post by: AabeckControls on June 07, 2018, 12:40:36 PM
Archie,

I didn't get an error in VS - it was only when I ran it on the machine I got that message.

I will follow your instructions then rebuild it again, last time I just added it then rebuilt.
Title: Re: Object Reference Nor Set o An Inistance.." Using AB DF1 & 399Vw
Post by: Archie on June 07, 2018, 05:50:55 PM
One of my thoughts is a brief loss of communication during a write may be causing this. I don't have a way to test this right now, but it should be able to be tested by unplugging the serial cable just before writing a value to see if it gives the same error.
Title: Re: Object Reference Nor Set o An Inistance.." Using AB DF1 & 399Vw
Post by: AabeckControls on June 08, 2018, 08:32:10 AM
Archie,

I still get a various Object..  error, when I wrote with the serial cable unplugged I got a Failed To Write To PLC popup window, and then the displays started showing loss of comm's errors - only get the Object error when it is communicating.
Title: Re: Object Reference Nor Set o An Inistance.." Using AB DF1 & 399Vw
Post by: AabeckControls on June 08, 2018, 12:06:41 PM
Archie,

I added the steps1.txt and changed the properties as instructed, but still get the same error - it was put in the debug folder - I checked after the rebuild.

I tried to write a value with the serial cable unplugged and got a popup about PLC comm's loss not the Object..., and while testing the Object .. error does show occasionally on other screens.
Title: Re: Object Reference Nor Set o An Inistance.." Using AB DF1 & 399Vw
Post by: Godra on June 08, 2018, 04:39:24 PM
Besides for the MainForm, no other form has a section of code to reduce communication when the form is not visible:

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

Have you considered that or do you need all the activated drivers to continuously poll?
 
Title: Re: Object Reference Nor Set o An Inistance.." Using AB DF1 & 399Vw
Post by: bachphi on June 08, 2018, 05:47:33 PM
Good catch, Godra.
I thought he's been around enough to know this
Title: Re: Object Reference Nor Set o An Inistance.." Using AB DF1 & 399Vw
Post by: AabeckControls on June 08, 2018, 06:25:47 PM
Godra,

No, that's something I have never added to any form - I presumed that a closed form shut down completely.

I will add it to all the forms, and on other projects too.

Title: Re: Object Reference Nor Set o An Inistance.." Using AB DF1 & 399Vw
Post by: AabeckControls on June 09, 2018, 07:02:14 AM
When I went to MainForm and copied the code to shut down the driver I noticed the following section that warns .NET does not close windows - so I copied that to all other pages with the driver shut-down code.

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
Title: Re: Object Reference Nor Set o An Inistance.." Using AB DF1 & 399Vw
Post by: Godra on June 09, 2018, 08:42:50 AM
You should avoid that since it will create recursive loop.

Besides for your MainForm, all other forms are designed as borderless and have the "Home" button to return to the MainForm (which is designed to close the application).
The only way to close these other forms would be to press Alt+F4 on the keyboard.
If it is ever done then each form, while closing, will try to close the other open forms.

Instead, for all other forms, you should just have MainForm.Show() line:

Code: [Select]
    Private Sub Me_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
        MainForm.Show()
    End Sub
Title: Re: Object Reference Nor Set o An Inistance.." Using AB DF1 & 399Vw
Post by: AabeckControls on June 09, 2018, 11:36:33 AM
Godra,

First - shutting down the drivers fixed all those errors. Thanks for that one.

I will go through and remove all the form close code.

I still have problem with MainForm displaying the Steps1.txt. It is looking at the right PLC integer, the value of the integer is 21, which should show "Not Ready" but it still shows "Can't find part of..."
Title: Re: Object Reference Nor Set o An Inistance.." Using AB DF1 & 399Vw
Post by: Godra on June 09, 2018, 12:45:19 PM
You need to set IniFileName to Steps1.txt, as in the attached picture.

It works for me.
Title: Re: Object Reference Nor Set o An Inistance.." Using AB DF1 & 399Vw
Post by: AabeckControls on June 09, 2018, 01:03:25 PM
Godra,

Again, Thanks.

When I put it in it added it with the full path name, not just the file name - obviously it was looking in the wrong place as the HMI computer doesn't have a second hard drive..