26 Replies Latest reply on Mar 2, 2010 3:13 PM by andreas

    How to add a cursor to a Batch Trend

    formerpigeek

      Hello guys,

       

      I'm searching a solution to add a cursor to a Batch Trend from a C# Process Book Add-In.

       

      I tried different ways but I had always casting or COM errors.

       

      Is it possible to do it from the Add-In and not from VBA ?

       

      The

      ((OSISoft.ProcessBook.BatchView.Cursors) <BatchGroupObject>.Trends.Item("BatchTrend1").Cursors).Add(<NewCursorObject>);

       

      doesn't work because I'm not able to create a new Cursor object.

       

      Do you have some good idea for me ?

       

      I thank you all.Have a nice day.

       

      Best regards,
      Gabriele

        • Re: How to add a cursor to a Batch Trend
          andreas

          Hi Gabriele,

           

          after trying the same and getting the same result I have contacted the developer.

           

          Regards,

            • Re: How to add a cursor to a Batch Trend
              formerpigeek

              Hi,

               

              Instead of passing “null” as “vArg” to method PIBTPB.Cursors.Add(object vArg); if “System.DBNull.Value” is passed – this method works fine. So try,

              OSIsoft.ProcessBook.BatchView.Cursors Curs ;
              ....
              OSIsoft.ProcessBook.BatchView.Cursor Cur = Curs.Add(System.DBNull.Value);
              ....

              A “null” passed from C# is translated (somewhere in the Interop layers) to “VT_EMPTY” – where as the Cursors.Add method is only looking for “VT_NULL” or “VT_ERROR” to ascertain that a NULL value was passed as a parameter. Passing “System.DBNull.Value” from C# would pass in VT_NULL and so the method works as expected.

               

              Passing NULL from VBA does get translated into "VT_NULL" and hence the call works fine in VBA for NULL value.

               

              Rgds.,

                • Re: How to add a cursor to a Batch Trend
                  formerpigeek

                  Hi,

                   

                  I finally tried your example but

                   
                  OSIsoft.ProcessBook.BatchView.Cursor Cur = Curs.Add(System.DBNull.Value);

                  doesn't work. It says that the value is outside the expected range...

                  Regards,
                  Gabriele
                    • Re: How to add a cursor to a Batch Trend
                      andreas

                      I see - you have added a reference to OSIsoft.ProcessBook.Batchview while we use the Interop.PIBTPB (COM: PI-BatchTrend Type Library) ...

                       

                      So using the PIBTPB here is some code:

                      foreach (PBObjLib.Symbol _MySymbol in _MySymbols)
                      {
                          MessageBox.Show(_MySymbol.Name.ToString(), m_strAddInName);

                          if (_MySymbol.Name.ToString() == "BatchGroup1")
                          {
                              PIBTPB.BatchGroup _MYBatchGroup;
                              _MYBatchGroup = (PIBTPB.BatchGroup)_MySymbol;

                              PIBTPB.Cursors _MyCursors;
                              try
                              {
                                  _MyCursors = (PIBTPB.Cursors)_MYBatchGroup.Cursors;int _count = _MyCursors.Count;
                                  for (int i = 1; i <= _count; i++)
                                  {
                                      MessageBox.Show(i.ToString()
                                          + Environment.NewLine
                                          + _MyCursors.Count.ToString()
                                          + Environment.NewLine
                                          + _count);
                                      _MyCursors.Remove(1);
                                  }PIBTPB.Cursor _MyNewCursor;
                                  _MyNewCursor = _MyCursors.Add(System.DBNull.Value);}
                              catch (Exception _ex)
                              {
                                  MessageBox.Show(_ex.ToString());
                              }
                          }
                      }

                      hope this helps!

                        • Re: How to add a cursor to a Batch Trend
                          formerpigeek

                          Doesn't work :(

                           

                           

                           

                          Here is my configuration:

                           

                           

                           

                          PI BatchView
                          Version 3.1.4
                              Btrend32.dll    3.1.4.0
                              pbBatchView.dll    3.1.3.2
                              PIBVExcel.xla    3.1.3.2
                              PIBVExcel.dll    3.1.3.2
                              PIBatchCommon.dll    3.1.4.0
                              PIBatchCustomNames.dll    1.0.0.140
                              PIBatchCustomNamesCtrls.ocx    1.0.0.140
                              PIBatchDialogs.dll    3.1.1.164
                              PIBatchResultsCtrls.ocx    3.1.1.164
                              PIBatchSearch.dll    3.1.1.164
                              PIBatchSearchCtrls.ocx    3.1.3.2
                              PIBatchUtilities.ocx    3.1.1.164
                              PIBatchView.exe    3.1.4.0
                              SftTree_IX86_A_45.ocx    4.5.15.500
                              SSubTmr6.dll    2.0.0.0
                          Copyright © 2006-2009, OSIsoft, Inc.


                          PI ProcessBook
                          Version 3.1.1.0
                              BTREND32.DLL       3.1.4.0          3.1.4.0          C:\Program Files\PIPC\Procbook\
                              COMCTL32.dll       6.00.2900.2982    6.0.2900.2982    C:\WINDOWS\WinSxS\X86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.2982_x-ww_ac3f9c03\
                              MFC80.DLL          8.00.50727.762    8.0.50727.762    C:\WINDOWS\WinSxS\x86_Microsoft.VC80.MFC_1fc8b3b9a1e18e3b_8.0.50727.762_x-ww_3bf8fa05\
                              ModContextSupport.ocx    3.01.0001        3.1.0.1          C:\Program Files\PIPC\Procbook\ModuleContext\
                              ModuleContext.dll    3.01.0001        3.1.0.1          C:\Program Files\PIPC\Procbook\ModuleContext\
                              MSO9.DLL           9.0.4402         9.0.0.4402       C:\Program Files\Office\
                              MSVBVM60.DLL       6.00.9782        6.0.97.82        C:\WINDOWS\system32\
                              MSVCR80.dll        8.00.50727.3053    8.0.50727.3053    C:\WINDOWS\WinSxS\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.3053_x-ww_b80fa8ca\
                              msvcrt.dll         7.0.2600.2180    7.0.2600.2180    C:\WINDOWS\system32\
                              Pblib32.dll        3.1.1.0          3.1.1.0          C:\Program Files\PIPC\Procbook\
                              pisdk.dll          1.3.6.0          1.3.6.363        C:\Program Files\PIPC\PISDK\
                              PISDKCommon.dll    1.3.6.0          1.3.6.361        C:\Program Files\PIPC\PISDK\
                              PISDKDlg.dll       1.06.0365        1.6.0.365        C:\Program Files\PIPC\PISDK\
                              PITimeServer.dll    1.3.6.0          1.3.6.361        C:\Program Files\PIPC\Library\
                              Plot.dll           3.1.0.1          3.1.0.1          C:\Program Files\PIPC\Procbook\
                              Prims32.dll        3.1.0.1          3.1.0.1          C:\Program Files\PIPC\Procbook\
                              Procbook.exe       3.1.1.0          3.1.1.0          C:\Program Files\PIPC\Procbook\
                              svg_addin.dll      3.01.0001        3.1.0.1          C:\Program Files\PIPC\PROCBOOK\SVG_addin\
                              Toolbox.dll        3.1.0.1          3.1.0.1          C:\Program Files\PIPC\Procbook\
                              Trend32.dll        3.1.0.1          3.1.0.1          C:\Program Files\PIPC\Procbook\
                              VBE6.DLL           6.04.9969        6.4.99.69        C:\PROGRA~1\COMMON~1\MICROS~1\VBA\VBA6\
                              xyplot.dll         3.1.0.1          3.1.0.1          C:\Program Files\PIPC\Procbook\
                          Copyright © 1993 - 2008 OSIsoft, Inc.

                            • Re: How to add a cursor to a Batch Trend
                              andreas

                              Hi Gabriele,

                               

                              when I tried to create a simple example for you I did run into some weird issues. I will have to get a PB developer look into it but meanwhile - can you try something?

                               

                              The issue I see is that my code works fine as long as I have two PB displays open (it does not matter what the 2nd display shows, it can be empty), if I open only the PB display that has the BatchGroup1 - my code starts sending an exception as yours does. Can you confirm this behavior on your side?

                               

                              Kind regards,

                          • Re: How to add a cursor to a Batch Trend
                            formerpigeek

                            Hi Gabriele,

                             

                            Can you please post the code (whole method/function) that you are using to add the Cursor.

                             

                            Thanks,

                             

                             

                              • Re: How to add a cursor to a Batch Trend

                                Customers issue ended up on my desk with call reference # 274158 - cannot create a new Trend Cursor programmatically

                                 

                                I have asked the customer to send the code and here's what he sent marked as example code:

                                try
                                {

                                    OSIsoft.ProcessBook.BatchView.Cursors myCursors = 
                                        (OSIsoft.ProcessBook.BatchView.Cursors) _batchgroup.Cursors;

                                    // Existing cursors deletion
                                    int countCur = _ myCursors.Count;

                                    for (int i = 1; i <= countCur; i++) myCursors.Remove(1);

                                    // Adding cursors
                                    OSIsoft.ProcessBook.BatchView.Cursor newCursor = myCursors.Add(System.DBNull.Value);

                                    […]
                                }
                                catch (Exception _ex)
                                {
                                    […]
                                }

                                I am doubting if this does look like what this thread was starting with but I am not sure.

                                 

                                If you have any comments, please let me know.

                                  • Re: How to add a cursor to a Batch Trend
                                    andreas

                                    Hi Gregor,

                                     

                                    here is your code, tested and working:

                                    try
                                    {
                                        PBObjLib.Symbols _MySymbols;
                                        _MySymbols = m_theApp.ActiveDisplay.Symbols;

                                        foreach (PBObjLib.Symbol _MySymbol in _MySymbols)
                                        {
                                            if (_MySymbol.Name.ToString() == "BatchGroup1")
                                            {
                                                MessageBox.Show("BatchGroup1 found!");
                                     
                                                OSIsoft.ProcessBook.BatchView.BatchGroup _batchgroup;
                                                _batchgroup =
                                                    (OSIsoft.ProcessBook.BatchView.BatchGroup)_MySymbol;

                                                OSIsoft.ProcessBook.BatchView.Cursors _myCursors =
                                                        (OSIsoft.ProcessBook.BatchView.Cursors)_batchgroup.Cursors;
                                     
                                                // Existing cursors deletion
                                                int countCur = _myCursors.Count;
                                     
                                                for (int i = 1; i <= countCur; i++)
                                                {
                                                    _myCursors.Remove(1);
                                                }
                                     
                                                // Adding cursors
                                                OSIsoft.ProcessBook.BatchView.Cursor newCursor =
                                                    _myCursors.Add(System.DBNull.Value);
                                            }
                                        }
                                    }
                                    catch (Exception _ex)
                                    {
                                        MessageBox.Show(_ex.ToString(), m_strAddInName);
                                    }

                                    so I guess we need some more info on what does not work, and probably the complete project to understand why the code works here and does not on your side. Please emphasize to the customer that OSIsoft vCampus is the place to get support for the PB AddIn development just as we emphasize to the customer that TechSupport is the place to get support for end-user and piadmin type of questions.

                                     

                                    Regards,

                                      • Re: How to add a cursor to a Batch Trend
                                        formerpigeek

                                        It is important how one obtains a BatchGroup symbol from the Symbols collection. Make sure that a BatchGroup symbol is obtained by iterating through the Symbols collection as given in the example above (foreach construct).

                                         

                                        Type casting a symbol to BatchGroup symbol will fail when a BatchGroup symbol is retrieved from the Symbols collection using the syntax  - Symbol sym = display.Symbols.Item("BatchGroup1");- or adding a BatchGroup symbol using - display.Symbols.Add(...) - . This is because of an issue in BatchView code and applies only to code written in C#(NOT an issue in VBA). 

                                         

                                        Also make sure that prior to the foreach construct in the above example (or in the customer's code), no other calls to - display.Symbols.Item(); exist.

                                         

                                        If customer is still having a problem - ask them to try unloading all addins and load only his addin to test this out.

                                         

                                         

                                          • Re: How to add a cursor to a Batch Trend

                                            The customer is back with the following answer:

                                             

                                            when it executes

                                            // Adding cursors

                                            OSIsoft.ProcessBook.BatchView.Cursor newCursor = _myCursors.Add(System.DBNull.Value);
                                            passing the value (as suggested in the vCampus)
                                            System.DBNull.Value

                                             

                                            It says that the value is outside the expected range... but I already wrote it in the Dev-forum on 28. Sept.

                                             

                                            Please let me know if you have any idea what's going wrong.

                                             

                                            Thanks,

                                              • Re: How to add a cursor to a Batch Trend
                                                andreas

                                                Hi Gregor,

                                                 

                                                Andreas

                                                ... we need some more info on what does not work, and probably the complete project to understand why the code works here and does not on your side...

                                                 

                                                Please emphasize again to the customer that OSIsoft vCampus is the place to get support for the PB AddIn development and he should post directly to this thread.

                                                 

                                                Regards,

                                                  • Re: How to add a cursor to a Batch Trend
                                                    tomster71

                                                    Hello,

                                                     

                                                    I finally fixed my code and now I am able to create cursors on the Batch Trend.

                                                     

                                                    Using for example this code to create a cursor programmatically:

                                                    // Adding cursors
                                                    OSIsoft.ProcessBook.BatchView.Cursor newCursor = _myCursors.Add(System.DBNull.Value);
                                                    newCursor.Time = "15.12.2009 10:00:00";

                                                    The cursor is correctly shown on the Batch Trend (I created the cursor at my PC time "19.02.2010 17:28").

                                                     

                                                    Now I have another problem: the BatchGroup DropCursor event gives back a different DroppedCursor object. In particular:
                                                    DroppedCursor.Time variable of DropCursor event is "19.02.2010 17:00:00"
                                                    Time variable of DropCursor event is "15.12.2009 09:16:53"

                                                     

                                                    * TRIAL 2 *
                                                    I tried also other values (I created this cursor at my PC time "19.02.2010 18:01")

                                                    newCursor.Time = "16.12.2009 12:00:00";

                                                    and
                                                    DroppedCursor.Time variable of DropCursor event is "19.02.2010 17:00:00"
                                                    Time variable of DropCursor event is "16.12.2009 13:03:08"

                                                     

                                                    It doesn't happen when the cursor is dropped manually.
                                                    Please help me. Many thanks.

                                                      • Re: How to add a cursor to a Batch Trend

                                                        Hello Thomas,

                                                         

                                                        I haven't had a chance to try it myself (and I'm not sure which regional settings you are using...), but it seems to me like this could very well be a date/time format issue. Have you tried setting the cursor time using the PI absolute time format (dd-MMM-yy HH:mm:ss)? E.g. 19-feb-10 18:01:00

                                                          • Re: How to add a cursor to a Batch Trend
                                                            tomster71

                                                            I tried your suggestion but without success. The DropCursor event today gives me back always "22.02.2010 10:00:00".

                                                             

                                                            The strange thing is that the newCursor, created using

                                                            OSIsoft.ProcessBook.BatchView.Cursors _myCursors =
                                                                (OSIsoft.ProcessBook.BatchView.Cursors)_batchgroup.Cursors;

                                                            // Adding cursors
                                                            OSIsoft.ProcessBook.BatchView.Cursor newCursor =
                                                                _myCursors.Add(System.DBNull.Value);

                                                            has exactly the value "22.02.2010 10:00:00" in the newCursor.Time by default.

                                                             

                                                            It is like that my next

                                                            newCursor.Time = "<mynewdatetime>"
                                                            is completely ignored.

                                                             

                                                            Have a nice day.

                                                            • Re: How to add a cursor to a Batch Trend
                                                              tomster71

                                                              Hello Michael,

                                                               

                                                              do you have news about the problem ?

                                                               

                                                              Thanks

                                                               

                                                               

                                                                • Re: How to add a cursor to a Batch Trend
                                                                  andreas

                                                                  Hi Thomas,

                                                                   

                                                                  to avoid any issues with the time format and with the time range of the trend, I tried the following:

                                                                  OSIsoft.ProcessBook.BatchView.Cursor _MyNewCursor;
                                                                  _MyNewCursor = _MyCursors.Add(System.DBNull.Value);
                                                                  _MyNewCursor.Time = _MYBatchGroup.StartTime.ToString();
                                                                  _MyNewCursor = _MyCursors.Add(System.DBNull.Value);
                                                                  _MyNewCursor.Time = _MYBatchGroup.EndTime.ToString();

                                                                  this adds two cursors to my BatchTrend - one at the end, the other at the start of the batch. If this works - we just have to deal with how we format the strings

                                                                    • Re: How to add a cursor to a Batch Trend
                                                                      andreas

                                                                      Hi Thomas,

                                                                       

                                                                      one additional point I noticed: it seems that the cursor time is the absolute time the cursor has on the first batch, this might be an issue as well. In my example the batch was running from 2/26/2010 08:56 to 2/26/2010 09:01 and any time between this was working (with exactly this format - my system time format).

                                                                        • Re: How to add a cursor to a Batch Trend
                                                                          andreas

                                                                          Hi Thomas,

                                                                           

                                                                          I tried Michael's suggestion with the PI Time format, using "1-mar-2010 08:55" (my batch trend shows a start time of "3/1/2010 08:52:31" and an end time of "3/1/2010 08:57:31") - and that works as well, so it seems for me that PI Time formatting and US format works. Any chance you could do this test as well?

                                                                           

                                                                          If you prefer I can attach my project to the post, just let me know.

                                                                            • Re: How to add a cursor to a Batch Trend
                                                                              cescamilla

                                                                              Whenever I encounter time issues I usually convert the date to string and then reparse with the provided mechanism, in such a way that lenguage settings, regional settings and the os specific settings won't change the way the date is displayed.

                                                                               

                                                                              this usually solves a lot of problems with SQL queries, server connections, etc. may it be of use here? Don't know, but you could try it out.

                                                                              • Re: How to add a cursor to a Batch Trend
                                                                                tomster71

                                                                                Hello Andreas,

                                                                                 

                                                                                the problem is not on the cursor creation. The cursor is correctly created and shown on the Batch Trend.

                                                                                 

                                                                                The problem is on the value "DroppedCursor" coming with the BatchGroup's DropCursor event. When this event is fired, because I created programmatically a new cursor, the Cursor object has a wrong value (please see my test examples).

                                                                                 

                                                                                I hope that now is more clear.

                                                                                 

                                                                                Thanks and have a nice day.

                                                                                 

                                                                                 

                                                                                  • Re: How to add a cursor to a Batch Trend
                                                                                    andreas

                                                                                    I Think that I understand now. If you add your own EBatchSymGroup_DropCursorEventHandler event handler, this event handler takes two arguments, the cursor and a string. The string represents the time stamp the cursor is dropped, while the Cursor.Time represents the time the cursor had before.

                                                                                     

                                                                                    In other words say we monitor the Cursor.Time in the event handler (C1.time), it *looks* like changing the cursor.time (C2.time) in the add in did not change anything, while in fact the cursor.time (C1.time) in the event handler will be the cursor.time (C2.time) *before* you set it to a new value, while the string in the event handler represents the cursor.time (C2.time) that was set. Not sure if anyone can follow what I am trying to say (I can't) - but I suggest you do a simple event handler like:

                                                                                    privatevoid myDropCursor(OSIsoft.ProcessBook.BatchView.Cursor myCursor, string myStr)
                                                                                    {
                                                                                        MessageBox.Show("Cursor:" + myCursor.Time.ToString(),"String: " + myStr);
                                                                                    }

                                                                                    and see what happens.

                                                                                     

                                                                                    Hope this helps

                                                                                      • Re: How to add a cursor to a Batch Trend
                                                                                        tomster71

                                                                                        Hello Andreas,

                                                                                         

                                                                                        now I am using the String to get the new Cursor time. In any case the returned value is not exact (and I think it is not in relationship with time formats, GMT etc etc).

                                                                                         

                                                                                        For example, if I set

                                                                                         

                                                                                        01.11.2009 14:12:00

                                                                                         

                                                                                        I receive from the String of the EBatchSymGroup_DropCursorEventHandler handler the following value

                                                                                         

                                                                                        01.11.2009 13:47:34,43707

                                                                                         

                                                                                         

                                                                                         

                                                                                        Thanks,

                                                                                         

                                                                                        PS: the PI BatchView Programming Help, at the DropCursor event, says wrongly "DroppedCursor: A reference to the Cursor that was dropped".

                                                                                          • Re: How to add a cursor to a Batch Trend
                                                                                            andreas

                                                                                            Thomas,

                                                                                             

                                                                                            I am not able to reproduce, for me the time in the string is almost identical (I drop the cursor at 16:25:00 and it reports 16:24:59.99939) to the time I set the cursor - so I will get in touch with the developers. I agree that the documentation is a bit misleading, however, the example as well as the documentation leave no doubt that the string is the time to look at

                                                                                            Time A String that represents the time on which the Cursor was dropped.