Add Trend Tag to existing/previous trend view [Citect Scada 2018 SA]

Hi,

The Default Info_Trend page, will upon click on the marked button show the tag in a new Process Analyst window. 

I would like to make similar button that will add the Equipment Trend tag to the existing/previous trend view that the user had open. 

Appreciate any suggestions how to assign such an button, what functions would I need to set up etc. ?

Thanks,

Rune

  • Hi Rune,

    The short answer is, you will first be duplicating the SA_Include\TrendPage.ci file and making your own customisations. You may also have to duplicate InfoTrend Page as well. The reason for this, is the goodies you need are protected by PRIVATE functions.

    You used the term "existing/previous" trend view. I assume you are using the standard workspace design that we provide as part of the Situational Awareness Starter Project?
    I also assume you really just mean the trend display you had previously visited and you have navigated away from?

    If so, you may have realised that it is currently "persisting" what you had selected when you navigate away from the page, and restoring it when you re-enter the page. This handled by the functions _TrendPage_PersistSave and _TrendPage_PersistLoad.
    By playing with the InfoTrend (your screen shot) you may have noticed that the persistance data is cleared. In essence preventing an "additive" display.
    The persistence feature is using PAV files, so to do what you want, you would need a way to Load, and then Add. To simulate this go to TrendPage_ShowForEquipment in SA_Include\TrendPage.ci and then:
    1. Comment out the _TrendPage_PersistClear line
    2. Comment out the line TrendPage_PA_CommandExecuted(oProcessAnalyst, l_sRemoveAllPens);
    Now every time you add trends via the InfoZone, they will be combined with whatever you were last viewing on the trend page.

    OK, so that will allow you to add trends to existing page from the InfoZone. By playing with that for a bit you will run into two problems:

    Problem 1: What if the trends are already there? Obviously you don't want to add them multiple times, so you will need to skip those. You can do that by creating yourself a function that enunmerates the pen collection of the Trend and Alarm Pane and removes any corresponding entries from the hTraces array. This would yield an hTraces array with just new traces.

    Problem 2: How many is too many? This Trend Page has been designed to limit the number to 16 traces. We set that soft limit just because the PA only has 16 unique colours. As we have now removed the 'clearing' code it means the TrendPage_ShowForEquipment can exceed the design. So, I would advise in your customers to respect the l_nMaxActiveTraces local variable and provide a warning to the operator that not all traces could be added if it is exceeded etc.

    Problem 3: What if you want both the old (clear) and your new behaviour (don't clear)?
    That just comes down to your target user experience. If you want the InfoZone to be able to have two modes, then you will need to duplicate the InfoTrend_<res> pages from SA_Include into your project, and then customize them with new buttons etc that call a function with a parameter to trigger the old / new behaviours. Don't forget to modify the InformationZone \ @(TREND) menu item to point at your new InfoTrend page. Omit the resolution part if you are supporting HD and UHD in your system as the workspace will auto-adjust.
    If instead, you want to do something like a right click menu on the selected equipment on a mimic (e.g. Add to Trend) then that is a matter of building up an array of trends to add and passing it to your customised TrendPage_ShowForEquipment function.

    I hope that helps,

    bradley
  • Hi Bradley,
    Thanks for your reply, you initial assumption where spot on! :-)

    I've already been playing with the two "lines" in TrendPage.ci, so good to get confirmation that I've been manipulating the right spot.

    Now, the feature to add any variable/trace to your "previous viewed" trend is an requirement from our customers and is quit common for the customer segment we are working in, (Mainly Oil & Gas, NorthSea outside Norway).

    The case with max 16 traces is ok and haven't had any issues with that, this is information that could be noted on Trend Help page in the specific customer project.

    The case with duplication is something that would be nice to make an handle for.
    As we are member of the Customer First program, are there some code available that could be shared regarding creating "a function that enumerates the pen collection of the Trend and Alarm Pane and removes any corresponding entries from the hTraces array.".
    I guess this code must have been made before, either as internal development in Citect or partly in this forum.

    Once again many thanks for your support,
    Have a great day!
    Rune
  • Hi Rune,

    Change the for loop in: "TrendPage_ShowForEquipment" as follows:

    FOR iTrace = 0 TO nTraceCount - 1 DO
    sItem = ArrayGetString(hTraces, iTrace, g_iTraceDataItem);
    sTag = ArrayGetString(hTraces, iTrace, g_iTraceDataTag);
    nTraceType = ArrayGetInt(hTraces, iTrace, g_iTraceDataTraceType);
    nPenType = ArrayGetInt(hTraces, iTrace, g_iTraceDataPenType);
    nAlarmType = ArrayGetInt(hTraces, iTrace, g_iTraceDataAlarmType);

    sPenName = _TrendPage_GetPenName(sCluster, sEquipment, sItem);

    sTraceKeyTest = _TrendPage_GetTraceKey(sPenName, nTraceType);

    // Only add the trace if it does not already exist
    IF (NOT MapKeyExists(sActiveTraceMap, sTraceKeyTest)) THEN
    _TrendPage_AddTrendToPA(sPenName, nTraceType, sTag, nPenType, nAlarmType);

    // Need to manually update active trace map as PenCreated is suppressed
    sTraceKey = _TrendPage_GetTraceKey(sPenName, nTraceType);
    MapValueSet(sActiveTraceMap, sTraceKey, 0);
    ELSE
    nSkippedTraces = nSkippedTraces + 1;
    END
    END

    Next modify the _TrendPage_UpdateEquipmentTraceCount call after the for loop to:

    // Need to manually update active equipment count as PenCreated is suppressed
    _TrendPage_UpdateEquipmentTraceCount(hSelectedEquipment, nTraceCount - nSkippedTraces);

    Lastly, make sure you create two local variables to the function:
    INT nSkippedTraces = 0;
    STRING sTraceKeyTest;

    With the earlier changes to not clear the pens and the above, you will now be able to additively add pens.
    Don't forget to add protection to this function to not exceed "l_nMaxActiveTraces". Add a msgbox to be nice to operator when that occurs. There are two situations to take care of:
    1. You are already at max active traces and therefore no traces were added
    2. current + new traces will yield only some of the traces are added.

    cheers,

    bradley
  • Hi Bradley
    Thanks for the code you shared above, most appreciated.

    Now, I'm digging further with this and are looking for a "simple" (at least I hope there is) way to create a button that can initiate the same functions as the Display In Trend button does from the Info Trend.
    You mention above that we would have to: "building up an array of trends to add and passing it to your customized TrendPage_ShowForEquipment function".

    Please excuse my lack for knowledge for a second;
    -in my simple mind I thought that I could achieve the same if we activated the function InfoTrend_ShowPADefault() as long as the selected equipment was in context and Info_Trend open.
    In the Menu setup I've set the Order of the Info_Trend to 1 as it will always display when an equipment is set in context.

    The main trend page is displayed when I run my test button but the trace is not passed on to it. I guess that has to do with WinNumber requirement in TrendPage_ShowForEquipment()?

    I've been trying to find a function that I can use to set Info_Trend_HD1080 page "Active" when I run the initiation code, playing with Win functions but no luck so far..

    I hope you see what I'm trying to do, question is, is it possible at all? I was hoping to use the same functions without creating duplicate once with modifications.

    I know I'm on thin ice... ;-)
    Hope you have some good suggestions, inputs that can help.

    Thanks,
    Rune

  • Bradley,

    I've made some progress, the following code will do the trick and act same as the "Button" on the Info_Trend page, as long as the selected equipment is in context and the Info_Trend page is open.

    FUNCTION VIC_InfoTrend()
    WinSelect(6);
    InfoTrend_ShowPADefault();
    END

    Questions:
    The WinNumber, how is that set? I figured out the number "6" by placing a trace variable in TrendPage_ShowForEquipment()
    Test_Variable = nCurWindow;
    What window is this, is it the Info_Trend or the Main Trend page?

    Further how can I be sure the number is 6? Can I retrieve the WinNumber dynamically/automatically by cicode even though the page is not "active". I guess this number can change from project to project and perhaps within a project, or is it locked?
    And finally how can I set a specific page active? I don't quit get hold of the Win function and the help file that follow them.

    Rune
  • Rune,

    See Page Table Page in the kernel to get an overview of all the pages (windows) of your workspace. You can use Workspace_GetPaneWindow() to get the right window number.

    Greetz,

    Bas
  • Hi Bas,
    Thanks for the input,
    The function Workspace_GetPaneWindow() is it a typo and should be Workspace_GetWindow() or is it a new function added in recent version of Citect? I'm on ver 8.20 Update 14.

    Rune
  • Rune,

    The Workspace_GetPaneWindow() is in the Workspace.ci of the SA_Include project. The Workspace_GetWindow() gives you the main window of your workspace. Depends om which window you want to move to using the WinSelect() function. The Workspace_GetPaneWindow() can get you the window number of a child window (which is opened at the position of a pane). I'm on update 15.

    Cheers,

    Bas