11 Replies Latest reply on Mar 24, 2009 6:16 PM by mweiss

    Re-establish SDK connection & update trends

      Hello,

       

      I have a little niggly issue that I want to get sorted in ProcessBook v3.0.15.7.

       

      Have a whole library of Processbook controlled by a central store of routines.  In some of these routines I change the connected PI user of the SDK connection, as "switchuser" is not implemented I close the connection then re-open with required credentials. This is fine and works just great with no real overhead, but trends, multistated symbols etc all become disconnected (I guess ProcessBook hooks into PISDK.Server.Close).  Even when the PISDK connection is restored the display does not reconnect.

       

      Now I can call "ThisDisplay.Refresh" but it does not update symbols, only something like "ThisDisplay.Revert" does because it forces a data refresh.  Is there a "nice" way to update the symbols connection to data? Revert is not an option as a user may have scrolled back in time to analyse data.

        • Re: Re-establish SDK connection & update trends
          cescamilla

          How are you changing the SDK connection?

           

          I'm think that process is not built to keep one connection per PDI but instead it keeps connection information per dynamic element.

           

          What I see here is that, since each element in the PDI can be connected to different PI Servers, what needs to be refreshed is not the Display object but the individual dynamic elements, depending on how you changed the connection this may take a few seconds and refreshing one may refresh the others. So, I'm pretty sure you need to go trought all the symbols and refresh each one.

           

          Want to try this out and give us feedback?

            • Re: Re-establish SDK connection & update trends

              Changing the SDK connection via some central routines based on an action the user performs in the display (also based on their user name and what they should be allowed to do - similar to OSI's new security model for the PI server!).  So I call "PISDK.Server.Close" and then reopen "PISDK.Server.Open" - unless of course the SDK connections current user is the one I need.

               

              I hook into the selectionchange event so I could do with avoiding iterating through every symbol on a display as this gets triggered and then triggers further code.

               

              What I have noticed is if there are certain symbols on the display then the displays symbols don't loose their data connection.  All very random so let me see if I can see what symbol is causing this, I suspect a the Bar symbol.

               

               

            • Re: Re-establish SDK connection & update trends
              cescamilla

              PI SDK connections are actually handled by the the ProcessBook application itself (1 per server that is used). Then the dynamic symbols get their data through these connections.

              When the symbols detect the disconnection, they disconnect. So far, so good ;)

               

              When you tell the symbols to refresh/revert - using ThisDisplay.Revert() - they do so according to their "build mode" configuration, not their current "run mode" state. And that's your problem.

              A way around that (although not elegant) would probably be to go through each and every symbol and "restore" their "run mode" state after the reconnection (which assumes you somehow saved it prior to the disconnection)

               

              You could so something else that is almost guaranteed to work:

               

              You save the state for all the symbols, do a display.revert and then restore the state of all the symbols in your display. I am not so hot about this method as it includes copying, acting, copying. but hey, give it a try!

              • Re: Re-establish SDK connection & update trends
                andreas

                Rhys,

                 

                Have you tried to set the start and end time of each symbol after you reopened the connection? That might help to refresh the symbol and you will not have to store something.


                    PISDK.Servers("andreaspc").Open
                    Me.Trend1.SetTimeRange Me.Trend1.StartTime, Me.Trend1.EndTime

                 

                Regards,

                 

                 

                • Re: Re-establish SDK connection & update trends
                  formerpigeek

                  Manually closing a connection, as opposed to a forced network disconnect, is not supported in PB. As you have found when the connection is reopened the symbols on the display will not automatically reconnect. Only by doing a Revert will the symbols be reconnected. 

                   

                  Closing and reopening the connection from the PI Connection Manager dialog is a known issue. As we did not see a situation in which the user would want to do that it was decided to leave it as an unsupported operation. This is essentially the same as closing and reopening the connection through the Automation Interface. 

                   

                  As a workaround you could iterate through the Symbols collection and get the Start and End Times for each symbol before closing the connection. The Start and End Times could then be restored after the connection is reopened and the display reverted.

                    • Re: Re-establish SDK connection & update trends

                      Boooo, hisssss.

                       

                      Well in this situation we are talking about controlled library of displays centrally managed so we need to change the connection based on actions or the purpose of the display (we merged some manual entry functionality into the displays).

                       

                      I have done as Andreas pointed out earlier and expanded on it to reset each symbol on a display.  Problem is other displays that are open can be effected so added the symbol fix to the display activate event to ensure all displays within the library are OK - not a nice overhead.  Problem now is randomly an error is thrown from PISDK from "get_UTCSeconds" because I forcibly close a connection.  Used to work great with an API based ProcessBook....

                       

                      By the way, using Revert through automation does not work the same as the Revert control on the Time Range Toolbar - what extra calls are made in the Revert control that are not exposed through automation?

                       

                       

                        • Re: Re-establish SDK connection & update trends

                          Rhys @ RJK Solutions

                          using Revert through automation does not work the same as the Revert control on the Time Range Toolbar

                           

                          I'd be interested to see an example of that, as they should behave the same: they essentially take action on the "selected symbols" (Display.SelectedSymbols).

                           

                          A very common mistake I've seen is when people execute a Display.Revert() in code that's called by a button. That buttons gets "selected" when you click on it and becomes is the only symbol in the Display.SelectedSymbols property - therefore the Revert method tries to take action on the button only. Solution to this is to call the the Display.SelectedSymbols.RemoveAll() method before to revert:

                          ThisDisplay.SelectedSymbols.RemoveAll
                          ThisDisplay.Revert

                           

                          Hope this helps!

                            • Re: Re-establish SDK connection & update trends

                              Steve Pilon

                              Rhys @ RJK Solutions

                              using Revert through automation does not work the same as the Revert control on the Time Range Toolbar

                               

                              I'd be interested to see an example of that, as they should behave the same: they essentially take action on the "selected symbols" (Display.SelectedSymbols).

                               

                              A very common mistake I've seen is when people execute a Display.Revert() in code that's called by a button. That buttons gets "selected" when you click on it and becomes is the only symbol in the Display.SelectedSymbols property - therefore the Revert method tries to take action on the button only. Solution to this is to call the the Display.SelectedSymbols.RemoveAll() method before to revert:

                              ThisDisplay.SelectedSymbols.RemoveAll
                              ThisDisplay.Revert

                              Hope this helps!

                               

                               

                              I suspect there may well be a selectedsymbol before revert is called (revert is called from an event rather than a control).  Let me check - if so I owe you a pint!

                            • Re: Re-establish SDK connection & update trends
                              mweiss

                              Rhys @ RJK Solutions

                              Problem now is randomly an error is thrown from PISDK from "get_UTCSeconds" because I forcibly close a connection.  Used to work great with an API based ProcessBook....

                               

                              Dynamic SDK time objects do not work if the server they were create with is closed (via the connection manager or code). They will magically start working again once that server is re-connected (you don't even have to re-create the objects). The error they return is pretty clear that this is by design. They will work if the network connection between the client and server is lost, however.