Factelligence Client API

622
Wonderware ® Factelligence™ Client API Programmers Guide Invensys Systems, Inc. Revision A Last Revision: 11/12/08

description

client api wonderware

Transcript of Factelligence Client API

  • Wonderware Factelligence

    Client API Programmers Guide

    Invensys Systems, Inc.

    Revision A

    Last Revision: 11/12/08

  • Copyright 2008 Invensys Systems, Inc. All Rights Reserved.All rights reserved. No part of this documentation shall be reproduced, stored in a retrieval system, or transmitted by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior written permission of Invensys Systems, Inc. No copyright or patent liability is assumed with respect to the use of the information contained herein. Although every precaution has been taken in the preparation of this documentation, the publisher and the author assume no responsibility for errors or omissions. Neither is any liability assumed for damages resulting from the use of the information contained herein.The information in this documentation is subject to change without notice and does not represent a commitment on the part of Invensys Systems, Inc. The software described in this documentation is furnished under a license or nondisclosure agreement. This software may be used or copied only in accordance with the terms of these agreements.

    Invensys Systems, Inc.26561 Rancho Parkway SouthLake Forest, CA 92630 U.S.A.(949) 727-3200http://www.wonderware.comFor comments or suggestions about the product documentation, send an e-mail message to [email protected].

    TrademarksAll terms mentioned in this documentation that are known to be trademarks or service marks have been appropriately capitalized. Invensys Systems, Inc. cannot attest to the accuracy of this information. Use of a term in this documentation should not be regarded as affecting the validity of any trademark or service mark.Alarm Logger, ActiveFactory, ArchestrA, Avantis, DBDump, DBLoad, DT Analyst, Factelligence, FactoryFocus, FactoryOffice, FactorySuite, FactorySuite A2, InBatch, InControl, IndustrialRAD, IndustrialSQL Server, InTouch, MaintenanceSuite, MuniSuite, QI Analyst, SCADAlarm, SCADASuite, SuiteLink, SuiteVoyager, WindowMaker, WindowViewer, Wonderware, Wonderware Factelligence, and Wonderware Logger are trademarks of Invensys plc, its subsidiaries and affiliates. All other brands may be trademarks of their respective owners.

    http://www.wonderware.com

  • 3

    Wonderware Factelligence Client API Reference Guide

    Contents

    Welcome.......................................... 19Documentation Conventions.............................................19Technical Support .............................................................20

    Chapter 1 Introduction to Factelligence API Scripts in ArchestrA ...................................... 21

    Factelligence Client API Wrapper....................................22Installing the Factelligence Client API Wrapper ............22Accessing the Factelligence Client API Help File ...........23Using the Factelligence Client API Functions ................23

    Chapter 2 Using the Factelligence Client API ........... 27Using Sessions...................................................................28

    Configuring UDAs for Sample Scripts ..........................28Creating Sessions ...........................................................28Starting Sessions............................................................29Logging into Sessions .....................................................29Logging on to Entities ....................................................30Monitoring Events in Sessions ......................................31Interacting with Factelligence.......................................33Logging off from Entities ...............................................37Ending Sessions..............................................................38

    Web Access.........................................................................39Using Web Access...........................................................39

    Attrs Class .........................................................................43Attrs Constructor ...........................................................43AddLotAttrs() Method....................................................43GetAttrID() Method (String)..........................................44

  • 4

    Wonderware Factelligence Client API Reference Guide

    GetAttrID() Method (String, Generic Nullable) ...........45GetAttrs() Method ..........................................................46GetAttrSet() Method ......................................................46GetAttrsVisibleInInv Method........................................47GetAttrValue() Method (String, String, String, String)48GetAttrValue() Method (String, String, String, String,

    String, String) ............................................................49GetAttrValue() Method (String, String, String, String,

    String, String, String, String) ...................................51GetEntAttrs() Method (Int32) .......................................53GetEntAttrs Method (Int32, Int32)...............................53GetJobAttrs() Method ....................................................54GetLotAttrs() Method.....................................................55GetWOAttrs() Method....................................................57PopupItemAttributes() Method (String) .......................57PopupItemAttributes Method (String, Boolean) ..........58PopupJobAttrsDlg Method (String, String, Int32, String)

    59PopupJobAttrsDlg() Method (String, String, Int32,

    String, ColumnList) ...................................................60PopupLotNoAttributes() Method (String, String) ........61PopupLotNoAttributes() Method (String, String,

    Boolean, ColumnList) ................................................62SetAttrValue() Method (String, Object, String, String,

    String, String, String, Boolean) ................................64SetAttrValue() Method (String, Object, String, String,

    String, String, String, String, String, Boolean) .......65SetAttrValue() Method (String, Object, String, String,

    String, String, String, String, String, String, String, Boolean) ......................................................................68

    SetLotAttrs() Method .....................................................70ClientSession Class ...........................................................71

    ChangePassword() Method ............................................72ClearFormLoginStatus() Method ..................................73CloseChildForms() Method ............................................74End Session() Method ....................................................74GetCurUserCurEntInfo Method (Int32, Int32) ............75GetCurUserCurEntInfo Method (Object, Object) .........76GetDS() Method..............................................................77GetDSbySQL() Method ..................................................78GetInstance() Method ....................................................78GetLangStringsObject() Method ...................................79GetServerTime() Method ...............................................80Login() Method ...............................................................80

  • 5

    Wonderware Factelligence Client API Reference Guide

    LoginWithDialog() Method (String) ..............................81LoginWithDialog() Method (String, Boolean, Boolean) 82LoginWithDialog() Method (String, Boolean, Boolean,

    Boolean) ......................................................................84LoginWithDialog() Method (String, Boolean, Boolean,

    Boolean, String) .........................................................85LogOffAllUsers() Method ...............................................87LogOffCurrentUser() Method ........................................87LogOffUser() Method (String)........................................88LogOffUser() Method (String, Boolean) ........................89OnRefreshControls() Method.........................................90PopupConfigureMiddlewareAccess() Method ...............90PopupSwitchUserDialog() Method (String, String)......90PopupSwitchUserDialog() Method (String, String,

    Boolean) ......................................................................92ReadTextFile() Method ..................................................93RefreshCurUserStatusDataSet() Method .....................94RegisterDNCControl() Method ......................................94RemoveControlFromSingleSignOn() Method ...............95SaveTextFile() Method...................................................96SendXMLCmd() Method (String) ..................................97SendXMLCmd() Method (String, XMLParser) .............98SendXMLCmd() Method (String, DateTime) ................99SendXMLCmd() Method (String, Int32) .....................100SendXMLCmd() Method (String, Int32, DateTime)...101SendXMLCmd() Method (String, Int32, String) .........102SendXMLCmd() Method (String, String) ....................104SendXMLCmd() Method (String, String, Int32) .........105StartLoggingXMLMsgs() Methods ..............................106StartSession() Method..................................................107StopLoggingXMLMsgs() Method .................................108SwitchUser() Method....................................................108UnregisterDNCControl() Method ................................110UpdateSystemParameter() Method.............................110VerifyUser() Method.....................................................111ApplicationName Property ..........................................112ClientType Property .....................................................113curUser Property ..........................................................113DBMSName Property ..................................................114EntitiesRequired Property...........................................114IsHostedByInTouch Property ......................................115IsInTouchUserLoggedIn Property...............................115IsSingleSignOnEnabled Property ...............................116

  • 6

    Wonderware Factelligence Client API Reference Guide

    LicenseInfo Property ....................................................116MainForm Property......................................................117MESVersion Property ..................................................117MiddlewareAccess Property.........................................117SelectForm Property ....................................................118SessionId Property .......................................................118ShowLanguageIDs Property........................................119SystemAttrs Property ..................................................120TopLevelFont Property ................................................120UIPlatform Property ....................................................121UserList Property.........................................................121

    Ent Class..........................................................................122AddDirectory() Method (Int32, String) .......................122AddDirectory() Method (Int32, Int32, String) ............123AddShift() Method........................................................124CopyEntityShiftSchedule() Method ............................127DeleteShift() Method....................................................128EndJob() Method ..........................................................129EntIdFromName() Method ..........................................130GetDirectories() Method (seqNo).................................131GetDirectories() Method (entID, seqNo) .....................132GetEntAttributes() Method .........................................133GetJobPos() Method .....................................................134GetJobString() Method ................................................136GetNumberOfJobsOnEntUserLoggedInto() Method..137GetTagValue() Method.................................................137GetUsersOnEnt() Method............................................138GetEntityShiftSchedule() Method...............................139GetEntAttributes() Method .........................................139PauseJob() Method.......................................................140ProcessJobsBeforeLogoff() Method..............................143PromptForQuantities() Method...................................144PromptForQuantities() Method (String, String, String,

    Int32, Double, Double, Double, String) ..................144PrepareProductionAttributes() Method ......................146SetCurJobExec() Method (Int32).................................149SetCurJobExec() Method (String, String, Int32)........150SetEntAttributes() Method ..........................................151SetTagValue() Method .................................................152StartJob() Method ........................................................154UpdateEntity() Method................................................155UpdateJobExec() Method.............................................160UpdateShift() Method ..................................................167

  • 7

    Wonderware Factelligence Client API Reference Guide

    CanCaptureLabor Property .........................................170CanCaptureUtil Property ............................................170CanDoDNC Property....................................................171CanLogData Property ..................................................171CanRunJobs Property ..................................................172CanSchedJobs Property ...............................................172CanSchedShifts Property.............................................172CanStore Property........................................................173CanTrackOEE Property...............................................173CertExec Property ........................................................174CurShiftDesc Property .................................................174CurShiftID Property.....................................................175CurShiftStartTime Property........................................175DNCExec Property .......................................................176EntDesc Property .........................................................176EntID Property.............................................................176EntName Property .......................................................177FoldersExec Property ...................................................177JobExec Property..........................................................178LaborExec Property......................................................178NumberOfJobsEntCanRun Property ..........................179NumberOfRunningJobs Property................................179OEEExec Property .......................................................180Site Property.................................................................180SiteName Property.......................................................181StorageExec Property...................................................181User Property ...............................................................182UtilExec Property.........................................................182

    Ents Class ........................................................................183AddEntity() Method......................................................183AddEntLink() Method ..................................................188DeleteEntity() Method..................................................189DeleteEntLink() Method ..............................................190GetCountsAndDuration() Method ...............................191GetEntChildren() Method ............................................194GetEntityFromComboBoxEntry Method (Object, Int32,

    String).......................................................................195GetEntityFromComboBoxEntry Method (Object,

    Generic Nullable, String).........................................196GetEntProperties() Method .........................................197NumberOfJobsRunning() Method ...............................198PopulateEntityComboBox() Method (ComboBox,

    Boolean) ....................................................................199

  • 8

    Wonderware Factelligence Client API Reference Guide

    PopulateEntityComboBox() Method (ComboBox, DataTable, Boolean) ................................................200

    PrepareProductionAttributes() Method ......................201PrepareProductionAttributes() Method ......................204SelectEntityInComboBox() Method (ComboBox, Int32)...

    207SelectEntityInComboBox() Method (ComboBox, Generic

    Nullable) ...................................................................208UpdateEntity() Method................................................209UpdateJobExec() Method.............................................214UpdateOEEExec() Method...........................................221UpdateUtilExec() Method ............................................224

    Jobs Class ........................................................................227AddConsDirect() Method .............................................227AddConsPostExec() Method.........................................231AddJobEvent() Method ................................................236AddProd () Method .......................................................242AddProdPostExec() Method .........................................243EndJob() Method ..........................................................247EndAllJobs () Method...................................................249GetAllJobStates() Method............................................250GetConfirmation() Method...........................................250GetDownstreamOperations() Method .........................253GetDownstreamProduction() Method .........................255GetJob() Method ...........................................................256GetJobEvents() Method ...............................................257GetJobExecData() Method...........................................259GetJobAttrs() Method (String, String, Int32)(Jobs Class)

    260GetJobAttrs() Method (String, String, Int32, Int32)(Jobs

    Class) ........................................................................262GetJobBomAvailSubst() Method (Jobs Class) ............263GetJobBOMData() Method ..........................................265GetJobBOMProducibles() Method (Jobs Class) ..........266GetJobBomSubst() Method (Jobs Class) .....................268GetJobBomSubstitutesForSerializedItem() Method ..269GetJobBOMWithSubData() Method (Jobs Class) ......270GetJobEvents() Method ...............................................272GetJobQueue() Method ................................................273GetJobsByWo() Method ...............................................274GetJobStateData() Method..........................................275GetNextWOId() Method...............................................276GetQueue() Method ......................................................276

  • 9

    Wonderware Factelligence Client API Reference Guide

    GetScheduledJobForWo() Method...............................278GetStartQtyOfItemInWO() Method ............................279GetWO() Method...........................................................280GetWoForSerializedItems() Method............................281GetWORouteData() Method.........................................282IsFirstJob() Method......................................................283ItemConsSplit() Method...............................................285JobStateDesc() Method ................................................288PopupCreateJobDialog() Method.................................289PopupJobBOMDlg() Method........................................290PopupJobEventDlg() Method (Jobs Class) ..................291PopupJobSplitDlg.........................................................293PopupSelectPausedStateDlg() Method........................295PopupStartSomeDlg() Method (String, Int32, String,

    String, Int32, Double, Double, Double, Double).....297PopupStartSomeDlg() Method (String, String, String,

    Int32, Double, Double, Double, Double) .................299SetJobConcurrentLink() Method.................................302SetJobQueue() Method.................................................303SetProdProcessedFlag() Method..................................305SplitJob() Method .........................................................306StartSome() Method .....................................................309

    JobExec Class ..................................................................311AddCons() Method........................................................311AddConsByLot() Method (String) ................................315AddConsByLot() Method (String, Double) ..................315AddProd() Method (Double) .........................................317AddProd Method (Double, Object, String, String, Object,

    Object, String, String, String, String, String) ........317CalculateProductionTarget() Method..........................320EndJob() Method ..........................................................321GetAvailLots() Method.................................................322GetBatchOfJobs() Method............................................323GetConsData() Method ................................................324GetJobBomAvailSubst() Method .................................325GetJobBOMData() Method ..........................................326GetJobBOMProducibles() Method ...............................326GetJobBomSubst() Method ..........................................328GetJobBOMWithSubData() Method ...........................328GetJobEvents() Method................................................329GetJobSchedData() Method .........................................331GetProdData() Method.................................................331GetProduction () Method..............................................332

  • 10

    Wonderware Factelligence Client API Reference Guide

    GetQueue() Method ......................................................333GetShortages() Method ................................................335GetSPCCharJobData() Method ...................................335PauseJob() Method (JobStates, String, String, Int32,

    String, Boolean, Int32)(JobExec Class) ..................336PauseJob() Method (JobStates, String, String, Int32,

    String, Boolean, Int32, Boolean)(JobExec Class)...338PopUpAddConsDlg Method (String, Boolean, String,

    String, Object, Boolean, Boolean, Boolean, Boolean, Boolean, Double, Double, Double, Int32)................340

    PopUpAddConsDlg() Method (String, Boolean, String, String, Object, Boolean, Boolean, Boolean, Boolean, Boolean, Double, Double, Double, Int32, Double, Object, Object) ..........................................................344

    PopupAddProdDlg() Method (String, String, Boolean, Double, Double, Double, String, DateTime, Int32) 348

    PopupAddProdDlg() Method (String, String, Double, Double, Double, String) ...........................................350

    PopupAddWasteDlg() Method .....................................352PopupCreateJobDialog() Method ................................354PopupEditConsDlg() Method .......................................354PopupEditProdDlg() Method (String, String, Int32,

    String, Int32, Int32, DateTime, Boolean, Double) .356PopupEditProdDlg() Method (String, String, Int32,

    String, Int32, Int32, DateTime, Boolean, Double, String).......................................................................358

    PopupJobEventDlg() Method.......................................361PopupReduceConsDlg() Method ..................................362PopupReduceProdDlg() Method (DateTime, String,

    String, String, Int32, Int32, String, Double, Double, Double, Object, String, Int32, Boolean) ..................365

    PopupReduceProdDlg() Method (DateTime, String, String, String, Int32, Int32, String, Double, Object, String, Int32)............................................................369

    PopupSetConsLotDataDlg() Method...........................371PopupSetProdLotDataDlg() Method ...........................373ReadyJob() Method.......................................................375Refresh() Method ..........................................................376RejectProd() Method.....................................................377SetCurLotdata() Method..............................................378SetUIScreenTagValues() Method ................................380StartDataEntryJob() Method ......................................381StartJob() Method ........................................................383UnreadyJob() Method ..................................................385AllowZeroQtySplit Property ........................................386

  • 11

    Wonderware Factelligence Client API Reference Guide

    AutoAllocateQtyToRunningJob Property ...................386CanRunWithoutOperator Property.............................387CertExecObject Property .............................................387CurGoodQty Property ..................................................388CurJobState Property ..................................................388CurOperId Property .....................................................389CurRejectQty Property.................................................389CurSeqNo Property ......................................................390CurWOId Property .......................................................390DefConsReasCD Property............................................390DefConsReasDesc Property .........................................391DefFromEntID Property ..............................................391DefFromEntName Property ........................................392DefLotNo Property .......................................................392DefProdReasCD Property ............................................393DefToEntID Property ...................................................393DefToEntName Property .............................................393JobPos Property............................................................394JobStepExecObject Property .......................................394SpecExecObject Property .............................................395SuppressStartSomeQtyPrompt Property....................395UserLoggedIn Property................................................396

    LangStrings Class ...........................................................396LangStrings Constructor .............................................397LangStrings Constructor .............................................397GetLanguages() Method...............................................398Translate() Method.......................................................399LangID Property...........................................................400

    LicenseInfo Class.............................................................400MaxSessions() Method .................................................401ModuleLicensed() Method............................................401

    OEEExec Class ................................................................402GetValue() Method .......................................................402Refresh() Method ..........................................................404CurrentOEE Property ..................................................405CurrentPerf Property ...................................................405CurrentQual Property..................................................405TargetOEE Property ....................................................406TargetPerf Property .....................................................406TargetQual Property ....................................................407

    Operations Class .............................................................407GetOperationDataFromComboBoxEntry() Method ...407

  • 12

    Wonderware Factelligence Client API Reference Guide

    GetOperationsForWorkOrder() Method......................408PopulateComboBoxWithOperations() Method............409PopulateComboBoxWithSeqNos() Method..................410

    PersistImage Class..........................................................412ListImageNames() Method ..........................................412LoadImage() Method ....................................................412SaveImage() Method ....................................................413

    Priv Class.........................................................................414Priv Constructor ...........................................................414Desc Property ...............................................................415Id Property....................................................................415Value Property..............................................................416

    Shifts Class......................................................................416AddEntShift() Method..................................................416DefineShift () Method...................................................419DeleteEntShift() Method..............................................420DeleteShift() Method....................................................421GetAllShifts() Method ..................................................422GetShiftDataFromComboBoxEntry() Method ............422GetShiftID() Method ....................................................424PopulateComboBoxWithShiftDescs() Method ............424UpdateEntShift() Method ............................................425UpdateShift() Method ..................................................428

    SystemAttr Class ............................................................429System Attr Constructor..............................................429System Attr Constructor..............................................430AttrDesc Property ........................................................432AttrId Property.............................................................432AttrSeq Property ..........................................................433AttrValue Property.......................................................433Constraints Property....................................................433EditType Property........................................................434GrpId Property .............................................................435ReqdLicenses Property.................................................435

    SystemAttrs Class...........................................................436Item Property ...............................................................436

    UIConfig Class ................................................................436DeleteUIConfigDefaultValue() Method.......................436DeleteUIConfigValue() Method ...................................437GetParameterValue() Method .....................................439ReadUIConfigDefaultValue() Method.........................440ReadUIConfigValue() Method .....................................441

  • 13

    Wonderware Factelligence Client API Reference Guide

    RestoreControlsVisibility() Method.............................442RestoreControlsVisibilityFromDefaults() Method......444RestoreTabsVisibilityFromDefaults() Method............445SaveControlsVisibility() Method .................................446SaveControlsVisibilityAsDefaults() Method ...............447SaveTabsVisibility() Method........................................448SaveTabsVisibilityAsDefaults() Method .....................450SaveUIConfigDefaultValue() Method .........................451SaveUIConfigDefaultValues() Method........................452SaveUIConfigValue() Method......................................453SaveUIConfigValues() Method ....................................455

    User Class........................................................................456User Constructor ..........................................................456AddUserToGroups () Method.......................................457ChangePassword() Method ..........................................458CloneUser() Method .....................................................459GetEntList() Method ....................................................460IsUserLoggedIntoJob() Method (Int32, String, String,

    Int32) ........................................................................461IsUserLoggedIntoJob() Method (String, String, Int32)....

    462IsUserLoggedOntoEnt() Method .................................463JobBasedLogin() Method..............................................464LogoffEnt Method.........................................................465LogoffEntList() Method................................................465LogOffJob() Method......................................................466LogOffJobWithDialog() Method...................................468LogonEnt() Method.......................................................469LogonEntList() Method (Int32[]) .................................470LogonEntList() Method (String, DataTable)...............471LogonEntWithDialog() Method (Boolean)...................472LogonEntWithDialog() Method (Boolean, Object) ......473LogonEntWithDialog() Method (Boolean, Object, String)

    474LogOnJob() Method ......................................................475MayAccessEntity() Method ..........................................477RefreshCurUserStatusRecordset() Method ................478RefreshCurUserStatusRecordset Method (DataSet)..478SaveEntList() Method ..................................................479UpdateUser() Method...................................................480curEnt Property............................................................481EntList Property...........................................................482EntsStatusInfo Property ..............................................482

  • 14

    Wonderware Factelligence Client API Reference Guide

    LangStrings Property...................................................483Privs Property...............................................................483UserDisplay Property...................................................484UserDisplayWithLabel Property .................................484UserID Property ...........................................................485UserName Property .....................................................485

    UserPrivs Class ...............................................................485UserPrivs Constructor .................................................486GetPrivObject() Method ...............................................486Item Property ...............................................................487

    Users Class ......................................................................488AddUser() Method ........................................................488FormatUser() Method ..................................................489GetUserDataFromComboBoxEntry Method...............490GetUsers() Method .......................................................491GetUsers() Method (Boolean) ......................................492PopulateComboBoxWithUsers() Method ....................493

    UserGrp Class .................................................................494AddUserGroup() Method..............................................494CloneUserGroup() Method...........................................495DeleteUserGroup() Method..........................................496GetGroupId() Method...................................................497GetUserGroups() Method.............................................498GetUserGroups() Method.............................................499GetUserGroupEntities() Method .................................499Set UserGroupEntityAccess() Method ........................500GetUserGroupLinks() Method.....................................502GetUserGroupLinks() Method.....................................502GetUserGroupLinks() Method.....................................503GetUserGroupLinks() Method.....................................504SetUserGroupPrivileges() Method ..............................505SetUserGroupPrivValue() Method ..............................507UpdateUserGroup() Method ........................................508

    Util Class .........................................................................509GetOEEExecData() Method.........................................509GetOldAvailableReasons() Method .............................510GetUtilExecData() Method ..........................................511GetUtilLogData() Method............................................512GetUtilReasons() Method ............................................513SetRawReason() Method..............................................514

    UtilExec Class .................................................................516UtilExec Constructor ...................................................516

  • 15

    Wonderware Factelligence Client API Reference Guide

    GetCountsAndDuration() Method ...............................517GetOldAvailableReasons() Method .............................519GetUtilExecData() Method ..........................................520GetUtilLogData() Method ............................................520GetUtilReasons() Method.............................................521GetUtilByFilter() Method ............................................522GetUtilByTimePeriod() Method ..................................526Refresh() Method ..........................................................528CurrentUtil Property ...................................................529TargetUtil Property......................................................529UtilReasCd Property ....................................................530UtilReasReqd Property ................................................530UtilReasStart Property ................................................531UtilStateCd Property ...................................................531UtilStateColor Property ...............................................532

    Utility Class.....................................................................532CloseIPForm() Method .................................................532ConvertStringToEnum() Method.................................533FindButtonBar() Method .............................................534FormatDuration() Method ...........................................534GetAutoLoginUserId() Method ....................................535GetAutoLoginUserPw() Method ..................................536GetAutoLogonEntId() Method .....................................536GetAutoLogonEntIds() Method ...................................537GetCodeColor() Method................................................537GetItemGrade() Method...............................................538GetListIndex() Method.................................................539GetOperEntLinkData() Method ..................................540GetStringFromConfigFile() Method ............................541GetTopLevelForm() Method.........................................542GetTopLevelFormName() Method...............................542InspectorLogin() Method (String, Boolean, String,

    String, User).............................................................543InspectorLogin() Method (String, Boolean, String,

    String, User, Boolean, String) .................................545ItemIDorDesc() Method................................................546LaunchExternalApplication() Method (String, Boolean) .

    547LaunchExternalApplication() Method (String, DataRow,

    Boolean) ....................................................................548LaunchStepDocument() Method (String, String) .......549OpenIPForm() Method (String) ...................................550OpenIPForm() Method (String, FormOpenType) .......551

  • 16

    Wonderware Factelligence Client API Reference Guide

    OpenIPForm() Method (String, FormOpenType, String).552

    PadDuration() Method .................................................553ParseDuration() Method ..............................................553ParseNameAndArgs() Method.....................................554PopupContextMenu() Method......................................556PopupDateTimeEntry() Method ..................................557PopupDurationEntry() Method (Control, Int32, Int32,

    Int32, Int32, Boolean)..............................................558PopupDurationEntry() Method (NumericUpDown,

    MaskedTextBox, MaskedTextBox, Int32, Int32, Int32, Int32) ........................................................................559

    PopupEntitySelection() Method (EntityCapabilities, Boolean, Int32, Boolean, Int32, String, String) .....561

    PopupEntitySelection() Method ...... (EntityCapabilities, Boolean, Int32, Int32, String, String).....................563

    PopupEntitySelection() Method (EntityCapabilities, Boolean, Int32, String) ............................................565

    PopupEntitySelection() Method (EntityCapabilities, Int32, Int32, String).................................................566

    PopupEntitySelection() Method (EntityCapabilities, Int32, String)............................................................567

    PopupEntitySelection() Method (EntityCapabilities, Int32, String)............................................................569

    PopupEntitySelection() Method (String).....................570PopupHideControlsForm() Method (Control) .............570PopupHideControlsForm() Method (Control, String,

    String, String, Boolean)...........................................571PopupHideTabsForm() Method ...................................573PopupItemReasonSelection() Method (Boolean, Int32,

    String).......................................................................574PopupItemReasonSelection() Method (String, Int32,

    Boolean, Boolean, Int32, String) .............................575PopupKeyboard() Method ............................................576PopupKeypad() Method (String, Int32, Decimal,

    Decimal, Double)......................................................577PopupKeypad() Method (Control)................................579PopupLotAttributes() Method (String, String) ...........579PopupLotAttributes() Method (String, String, Boolean)..

    580PopupNotesDlg() Method.............................................581PopupOperationSelection() Method ............................583PopupUtilReasonSelection() Method ..........................584PopupWorkOrderSelection() Method ..........................586ResizeWindowBasedOnFont() Method........................587

  • 17

    Wonderware Factelligence Client API Reference Guide

    SetFont() Method..........................................................588SetTextFromKeyPad() Method (Control, String) .......589SetTextFromKeyPad() Method (Control, String, Int32) ..

    590ShowHelpFile() Method ...............................................591ShowJobFlowDiagram() Method .................................591TranslateForm() Method (Control)..............................592TranslateForm() Method (Control, ILanguageStrings)....

    593UtilRawReason Class......................................................594

    AddUtilRawReasonLink() Method ..............................594Delete() Method ............................................................595DeleteUtilRawReasonLink() Method ..........................596GetAllUtilRawReasonLinks() Method ........................597GetAllUtilRawReasonLinks() Method ........................598GetAllUtilRawReasonLinks() Method ........................599GetAllUtilRawReasonLinks() Method ........................600GetAllUtilRawReasonLinks() Method ........................600GetUtilRawReasons() Method .....................................601GetUtilRawReasons() Method .....................................602Refresh() Method ..........................................................603Save() Method...............................................................604

    UtilReason Class .............................................................604Delete() Method ............................................................604GetUtilReasons() Method.............................................605LoadHashTableWithUtilReasonData() Method .........605Refresh() Method ..........................................................606Save() Method...............................................................606

    UtilReasonGrp Class.......................................................607Delete() Method ............................................................607GetUtilReasonGroups() Method ..................................608Refresh() Method ..........................................................608Save() Method...............................................................609

    UtilState Class ................................................................610Delete() Method ............................................................610GetAllStates() Method..................................................610GetStateDataFromComboBoxEntry() Method ...........611PopulateComboBoxWithEntStates() Method .............612Refresh() Method ..........................................................613Save() Method...............................................................613

    Index .............................................615

  • 18

    Wonderware Factelligence Client API Reference Guide

  • 19

    Wonderware Factelligence Client API Reference Guide

    Welcome

    This guide shows you how to use the Factelligence Client API within the ArchestrA Integrated Development Environment (IDE) to develop and customize ArchestrA scripts.

    You can view this document online or you can print it, in part or whole, by using the print feature in Adobe Acrobat Reader.

    This guide assumes you know how to use Microsoft Windows, including navigating menus, moving from application to application, and moving objects on the screen. If you need help with these tasks, see the Microsoft online help.

    In some areas of the Industrial Application Server, you can also right-click to open a menu. The items listed on this menu change, depending on where you are in the product. All items listed on this menu are available as items on the main menus.

    Documentation ConventionsThis documentation uses the following conventions:

    Convention Used for

    Initial Capitals Paths and file names.

    Bold Menus, commands, dialog box names, and dialog box options.

    Monospace Code samples and display text.

  • 20 Welcome

    Wonderware Factelligence Client API Reference Guide

    Technical SupportWonderware Technical Support offers a variety of support options to answer any questions on Wonderware products and their implementation.

    Before you contact Technical Support, refer to the relevant section(s) in this documentation for a possible solution to the problem. If you need to contact technical support for help, have the following information ready:

    The type and version of the operating system you are using.

    Details of how to recreate the problem.

    The exact wording of the error messages you saw.

    Any relevant output listing from the Log Viewer or any other diagnostic applications.

    Details of what you did to try to solve the problem(s) and your results.

    If known, the Wonderware Technical Support case number assigned to your problem, if this is an ongoing problem.

  • 21

    Wonderware Factelligence Client API Reference Guide

    Chapter 2

    Introduction to FactelligenceAPI Scripts in ArchestrA

    Factelligence client controls can use the Factelligence Client API to access and interact with Factelligence middleware. However, if you attempt to use the Factelligence Client API in ArchestrA scripts, events and exceptions are not handled correctly.

    To avoid these ArchestrA scripting limitations, you can use the Factelligence Client API wrapper to access Factelligence Client API functionality in ArchestrA scripts.

    This section shows how to:

    Identify the Factelligence Client API wrapper. Install the Factelligence Client API wrapper. Use Factelligence Client API Wrapper functions. Use the Factelligence Client API help file.

  • 22 Chapter 2 Introduction to Factelligence API Scripts in ArchestrA

    Wonderware Factelligence Client API Reference Guide

    Factelligence Client API WrapperFactelligence API wrapper class names start with aa and their functionality corresponds to their equivalent Factelligence Client API functions.

    Application Server scripting can access the Factelligence client API wrapper from:

    Scripts tab of any automation object. Any script window within ArchestrA symbols, such

    as, the symbol script, the event script, or action scripts for individual elements on the canvas.

    Installing the Factelligence Client API Wrapper

    The Factelligence Client API wrapper is contained in a set of DLL files. You can install the Factelligence Client API wrapper by importing an aaSLIB file from the Factelligence installation image.

    To install the Client API Wrapper

    1 Open the ArchestrA IDE.2 Select the Galaxy menu, point to Import, and then Script

    Function Library. The Import Script Function Library dialog box appears.

    3 Browse to the \Program Files\Wonderware\Factelligence\Controls folder on your local hard drive.

    Note If you selected to install the .NET Controls during your Factelligence installation the aaFactMES.aaSLIB file will be copied into your local hard drive. You can also browse onto the Factelligence Installation CD and copy the file manually from the \Factelligence\Controls directory.

    4 Select the aaFactMES.aaSLIB file and click Open. The script library is imported and a success message appears.

    5 Click OK.

    Client API Function Client API Wrapper Class Name

    AddAttrArrayList aaAddAttrArrayList

    ClientSession aaClientSession

    Users aaUsers

  • Accessing the Factelligence Client API Help File 23

    Wonderware Factelligence Client API Reference Guide

    Accessing the Factelligence Client API Help File

    The Factelligence Client API help file (FactMESClientCommon.chm) is located on the Factelligence installation CD in the \Factelligence\Docs folder.

    You can browse the installation CD and open the file directly, or copy the file to your hard drive for future reference.

    Using the Factelligence Client API FunctionsTo use Factelligence Client API functions in an ArchestrA script, you need to know the following:

    Function name Function parameters Purpose and data type of the return result The class to which the function belongs

    The FactMESClientCommon.chm help file contains two entries for each function:

    Base Client API functions Client API Wrapper functions

    Client API wrapper classes are prefixed with aa under the aaFactMES node of the help file and used when scripting for Factelligence functionality.

  • 24 Chapter 2 Introduction to Factelligence API Scripts in ArchestrA

    Wonderware Factelligence Client API Reference Guide

    Base client API functions with more complete descriptions are found under the FactMES.Client.Common node of the help file and should only be used for functional reference when scripting with the client API wrapper.

    Important All Factelligence API scripting in the ArchestrA IDE requires the use of the Client API wrapper. The base Client API library is included in the help file for functional reference.

    To determine the API function name and its parameters

    1 Open the Factelligence Client API help file (FactMESClientCommon.chm).

    2 On the left pane, locate the class or function you want to use. You can also click the Search tab to search the help file for the class or function.

    3 Read the syntax of the [Visual Basic (Declaration)] section in the right pane. For example:Public Function IsUserLoggedOntoEnt( _ ByVal entId As Integer _ ) As Result

    The data types appear underlined in blue. The preceding example includes an integer data type.

    Note The data type of the function result for the new API functions appears as Result. To determine the data type of the result, complete the following procedure.

    To determine the data type of the function return result

    1 Open the Factelligence Client Scripting Library help file (FactMESClientCommon.chm).

  • Using the Factelligence Client API Functions 25

    Wonderware Factelligence Client API Reference Guide

    2 On the left pane, locate the function for which you want to determine the return result data type.

    3 Locate the equivalent legacy method. For example, the aaUser.IsUserLoggedOntoEnt() method has the User.IsUserLoggedOnToEnt() legacy method.

    4 In the syntax for Visual Basic, read the data type of the return result. In this example it would be Boolean.

    5 Expand the aaFactMES, Result Structure, Result Fields nodes in the help file and locate the equivalent data type. The right pane contains further information on the data type.

  • 26 Chapter 2 Introduction to Factelligence API Scripts in ArchestrA

    Wonderware Factelligence Client API Reference Guide

  • 27

    Wonderware Factelligence Client API Reference Guide

    Chapter 3

    Using the Factelligence Client API

    Using Factelligence Client API scripts in ArchestrA follows the same rules and conventions as required when creating objects in the Application Server. It is important to use the Factelligence Client API wrapper functions at all times.

    This section explains how to use several pre-built API scripts. These scripts illustrate the basic coding required to use the full range of Factelligence API functions.

    The example code illustrates common programming techniques related to using the API.

    Task Sample Script

    Create and log into a session. Init

    Log on to an entity. LogonEnt

    Get information about an entity.

    ShowEntityData

    Get information about the current user.

    GetCurrentUserInfo

    Get information when the user logon changes.

    UserChanged

    Monitor events. MonitorEvents

    Log off an entity. LogOffEnt

    Close and log off from a session.

    Term

  • 28 Chapter 3 Using the Factelligence Client API

    Wonderware Factelligence Client API Reference Guide

    Using SessionsThe key to writing script for Factelligence is the session.

    In order to use any Factelligence functionality, you must first create a session.

    Configuring UDAs for Sample ScriptsThe following UDAs (User Defined Attribute) need to be configured for a custom application object to use the sample scripts:

    1 EntityNameThe EntityName attribute is a string used as an input argument to several scripts.

    2 UserChangedThe UserChanged attribute is a string that is set by the MonitorEvents script to trigger the UserChanged script.

    3 LogonEntTrigThe LogonEntTrig attribute is a Boolean value that , when set to TRUE, triggers the LogonEnt script.

    4 LogoffEntTrigThe LogoffEntTrig attribute is a Boolean value that, when set to TRUE, triggers the LogOffEnt script.

    5 GetCurUserInfoTrigThe GetCurUserInfoTrig is a Boolean value that, when set to TRUE, triggers the GetCurrentUserInfo script.

    6 ShowEntityDataTrigThe ShowEntityDataTrig is a Boolean value that, when set to TRUE, triggers the ShowEntityData script.

    Creating SessionsYou use the aaFactMES.aaClientSession object to create and manage a Factelligence session. There is only one aaFactMES.aaClientSession object created for an application, but there may be many references to that object.

    You get a reference to the object by calling the aaFactMES.aaClientSession.GetInstance method. The first time this method is called, it creates the object; all subsequent calls return a reference to that object.

    For an example, see the Example: Init Script on page 29.

  • Using Sessions 29

    Wonderware Factelligence Client API Reference Guide

    Starting SessionsAfter you create an aaFactMES.aaClientSession object, you can use it to start a Factelligence session with the Factelligence middleware. The Factelligence middleware requires a session in order for most functions to work.

    Example: Init ScriptYou can call the Init script to start a session, initialize any attributes and log on a user. The Init script should be called one time by one Application Object.

    If you use the Init script to log on a user, you must change the user and password in the Login method.

    You can use the Init script as either an OnScan or Execute script with some attribute-based trigger. If you use it as an Execute script, you should mark it as an asynchronous script.

    Logging into SessionsAfter you have started a session, you need to log one or more users into the session.

    ' Init Script

    dim clientSession As aaFactMES.aaClientSession;

    dim result As aaFactMES.Result;

    ' Get the singleton client session - if one doesn't exist yet,

    ' it will be created

    result = aaFactMES.aaClientSession.GetInstance();

    clientSession = result.Value;

    if ( clientSession null and clientSession.SessionId == -1) then' Start the session. Only do this if a session isn't already startedresult = clientSession.StartSession(aaFactMES.aaClientTypes.clientOperator);

    if (result.Success == true) thenLogMessage("Session Started!");

    ' Login a user - this should cause a UserChanged event (see MonitorEvents script)result = clientSession.Login("fact_user", "fact_user_pswd");if (result.Success == true) then

    LogMessage("Login succeeded!");endif;

    elseLogMessage("Session failed to start!");

    endif;

    endif;

  • 30 Chapter 3 Using the Factelligence Client API

    Wonderware Factelligence Client API Reference Guide

    The aaFactMES.ClientSession object can manage multiple users logged into a session at once, but there will only every be one user that is the current user for which commands are being executed.

    All Factelligence commands must be executed for a user, and most commands must be executed for an entity. If you are using Factelligence controls in your application, they can be set up to log the user into the Factelligence either by using the current InTouch user or by prompting the user to login.

    You can also write script to log a user in. If you know the user's Factelligence user ID and password, you can call the Login method in aaFactMES.aaClientSession to directly login the user or you can call the LoginWithDialog method in aaFactMES.aaClientSession to open the Factelligence login dialog box.

    For an example, see the Example: Init Script on page 29.

    Logging on to EntitiesAfter the user logs in, the user will need to log on to one or more entities. If you are using Factelligence controls in your application, they can be set up to display a dialog for allowing the user to log onto one or more entities.

    Example: LogonEnt ScriptYou can call the LogonEnt script after setting UDA (me.EntityName) with the entity name you want to log on. You should mark this as an asynchronous script.

  • Using Sessions 31

    Wonderware Factelligence Client API Reference Guide

    You can use the LogonEnt script as an Execute or OnTrue script with a UDA trigger (me.LogonEntTrig).

    Monitoring Events in SessionsWhen a new user logs onto a session, or the current user is changed, the aaFactMES.aaClientSession object can inform you of this fact. To do this you need to set a UDA to UserChanged_DateTime variable in the aaFactMES.aaClientSession object. You must then create a Data Change script triggered by this UDA.

    Example: Monitor Events ScriptYou can call the MonitorEvents script to check for new events that have occurred on the aaFactMEScontrol.

    ' LogonEnt Script

    dim clientSession As aaFactMES.aaClientSession;

    dim result As aaFactMES.Result;

    dim entityID as Integer;

    ' reset the trigger

    me.LogonEntTrig = false;

    ' Get the singleton client session

    result = aaFactMES.aaClientSession.GetInstance();

    clientSession = result.Value;

    if ( clientSession null ) thenif ( clientSession.curUser null and me.EntityName "" ) then

    ' get Entity ID from input UDA Entity Nameresult = aaFactMES.aaEnt.EntIdFromName( me.EntityName );if ( result.Success == true and result.Int32_Value -1) then

    ' go an entity ID - attempt to logonentityID = result.Int32_Value;result = clientSession.curUser.LogonEnt( entityID, "", 100.0 );if ( result.Success == true ) then

    ' Print Success messageLogMessage(clientSession.curUser.userName + " has logged onto entity

    " + me.EntityName + " - id=" + StringFromIntg(entityID, 10) );endif;

    else' Failed to get Entity ID from Entity NameLogMessage("Entity " + me.EntityName + " does not seem to exist");

    endif;endif;

    endif;

  • 32 Chapter 3 Using the Factelligence Client API

    Wonderware Factelligence Client API Reference Guide

    You can use the MonitorEvents script as an Execute / Periodic script with a trigger period of 00:00:01.0000000.

    Example: UserChanged scriptYou can call the UserChanged script when the trigger UDA changes. The trigger indicates that an event has arrived and should be processed.

    Every event in the Client API will have a date time property exposed in the Client API Wrapper. Every time an event is fired the date time property associated with that event will be updated with the date time the event was fired. The user will then have to poll this property and keep track of its value so they can determine when an event occurred. The polling script will change the trigger UDA when it finds that a change has occurred.

    Every event in the Client API will have a date time property exposed in the Client API Wrapper. Every time an event is fired the date time property associated with that event will be updated with the date time the event was fired. The user will then have to poll this property and keep track of its value so they can determine when an event occurred.

    ' MonitorEvents Script

    dim clientSession As aaFactMES.aaClientSession;

    dim result As aaFactMES.Result;

    ' Get the singleton client session

    result = aaFactMES.aaClientSession.GetInstance();

    clientSession = result.Value;

    if (clientSession null) then' Get the DateTime of each event we are interested in' and store it in a UDA. The DateTime will' change each time the event fires. Use the UDA as a trigger' on another event handler script (see UserChanged script)' NOTE: the UserChanged UDA should be a stringme.UserChanged = clientSession.UserChanged_DateTime;

    endif;

  • Using Sessions 33

    Wonderware Factelligence Client API Reference Guide

    You can use the UserChanged script as an Execute or Data Change script with a trigger UDA (me.UserChanged) that is set in the Monitor Events script.

    Interacting with FactelligenceAfter you have a user logged into a session and on to an entity, you can start calling methods to interact with Factelligence.

    Example: Show Entity Data ScriptYou can trigger the ShowEntityData script after setting the UDA Trigger (me.EntityName) with the Entity Name you want to obtain information. You must be logged on to the entity.

    You can use the ShowEntityData script as an Execute or OnTrue script with a UDA trigger (me.ShowEntityDataTrig).

    ' ShowEntityData Script

    dim clientSession As aaFactMES.aaClientSession;

    dim result As aaFactMES.Result;

    dim entity As aaFactMES.aaEnt;

    ' reset the trigger

    me.ShowEntityDataTrig = false;

    ' UserChanged Script

    dim clientSession As aaFactMES.aaClientSession;

    dim result As aaFactMES.Result;

    dim userName as string;

    ' Get the singleton client session

    result = aaFactMES.aaClientSession.GetInstance();

    clientSession = result.Value;

    userName = "???";

    if (clientSession null) thenif (clientSession.UserChanged_e null) then

    if (clientSession.UserChanged_e.UserObject null) thenuserName = clientSession.UserChanged_e.UserObject.User

    endif;endif;LogMessage("User changed to " + userName );

    endif;

  • 34 Chapter 3 Using the Factelligence Client API

    Wonderware Factelligence Client API Reference Guide

    ' Get the singleton client session

    result = aaFactMES.aaClientSession.GetInstance();

    clientSession = result.Value;

    if ( clientSession null ) thenif ( clientSession.curUser null and me.EntityName "" ) then' get entity from passed in name - Note: we must be logged into entity

    entity = null;dim ii as integer;dim tmpEnt as aaFactMES.aaEnt;for each ii in clientSession.curUser.EntList.Keys

    tmpEnt = clientSession.curUser.EntList[ii];if ( tmpEnt.EntName == me.EntityName ) then

    entity = tmpEnt;exit for;

    endif;next;if ( entity null ) then

    ' print info about entityLogMessage("Info: "+entity.EntName+" id=" + entity.EntId );LogMessage("Entity Capabilities: ");LogMessage("CanRunJobs: "+entity.CanRunJobs.ToString() );LogMessage("CanCaptureUtil: "+entity.CanCaptureUtil.ToString() );LogMessage("CanTrackOEE: "+entity.CanTrackOEE.ToString() );LogMessage("Entity Shift Information:");LogMessage("CurShift: " + entity.CurShiftDesc);LogMessage("Start Time: "+entity.CurShiftStartTime.ToString() );if ( entity.JobExec null ) then

    LogMessage("Job State: "+entity.JobExec.CurJobState.ToString() );else

    LogMessage("Job State: n/a" );endif;if ( entity.OEEExec null ) thenLogMessage("Current OEE:"+entity.OEEExec.CurrentOEE.ToString() );LogMessage("Target OEE:"+entity.OEEExec.TargetOEE.ToString() );LogMessage("Perform.: "+entity.OEEExec.CurrentPerf.ToString() );LogMessage("Target Perf.: "+entity.OEEExec.TargetPerf.ToString() );LogMessage("Curr. Quality:"+entity.OEEExec.CurrentQual.ToString() );LogMessage("Target Qual.: "+entity.OEEExec.TargetQual.ToString() );else

    LogMessage("Current OEE: n/a" );LogMessage("Target OEE: n/a" );LogMessage("Current Performance: n/a" );LogMessage("Target Performance: n/a" );LogMessage("Current Quality: n/a" );LogMessage("Target Quality: n/a" );

    endif;if ( entity.UtilExec null ) thenLogMessage("Utilization:");LogMessage("Current: "+entity.UtilExec.CurrentUtil.ToString() );LogMessage("Target: "+entity.UtilExec.TargetUtil.ToString() );LogMessage("Reason Code: "+entity.UtilExec.UtilReasCd.ToString() );LogMessage("Start Time: "+entity.UtilExec.UtilReasStart );LogMessage("State Code: "+entity.UtilExec.UtilStateCd.ToString() );' List reason codes available to entity

    result = entity.UtilExec.GetUtilReasons();if ( result.Success == true ) then

  • Using Sessions 35

    Wonderware Factelligence Client API Reference Guide

    dim dts As System.Data.DataTableCollection;dim dr As System.Data.DataRow;dim dt As System.Data.DataTable;dts = result.Value.Tables;dt = dts[0];for each dr in dt.Rows

    ' show each column in DS (uncomment lines below to ' see what column are available)' dim dc As System.Data.DataColumn;' for each dc in dt.Columns' LogMessage("Column: " + dc.ColumnName);' LogMessage(" Value: " + dr[dc] );' Next;

    ' Show Reason Code and Desc columnsLogMessage("Reason Code: " + dr["reas_cd"] );LogMessage("Reason Description: " + dr["reas_desc"]);

    Next;endif;

    elseLogMessage("Current Utilization: n/a" );LogMessage("Target Utilization: n/a" );LogMessage("Utilization Reason Code: n/a" );LogMessage("Utilization Start Time: n/a" );LogMessage("Utilization State Code: n/a" );LogMessage("Utilization Reasons: n/a" );

    endif;else

    LogMessage("Could not find entity " + me.EntityName + ".");LogMessage("Does it exist? Is the current user logged on to it?" );

    endif;endif;

    endif;

    Example: GetCurrentUserInfo ScriptThe GetCurrentUserInfo script writes information about the current user to the Logger. You should mark this as an asynchronous script.

  • 36 Chapter 3 Using the Factelligence Client API

    Wonderware Factelligence Client API Reference Guide

    You can use the GetCurrentUserInfo script as an Execute or OnTrue script with the UDA trigger (me.GetCurUserInfoTrig).

    ' GetCurrentUserInfo Script

    dim clientSession As aaFactMES.aaClientSession;

    dim result As aaFactMES.Result;

    dim entityID as Integer;

    ' reset the trigger

    me.GetCurUserInfoTrig = false;

    ' Get the singleton client session

    result = aaFactMES.aaClientSession.GetInstance();

    clientSession = result.Value;

    if ( clientSession null ) thendim i as integer;dim ent as aaFactMES.aaEnt;dim entNameList as string;LogMessage("***********************************************");

    'Current User NameLogMessage("Current User Name: " + clientSession.curUser.UserName);

    'Current User IDLogMessage("Current User ID: " + clientSession.curUser.UserId);

    'Current User Display NameLogMessage("Current User Display Name: " + clientSession.curUser.UserDispl

    'Show the entities the user is logged ontofor each i in clientSession.CurUser.EntList.Keys

    'Seperate the Entity Namesif (entNameList.Length > 0) then

    entNameList = entNameList + ", ";endif;

    'Get the entity which matches the Key.ent = clientSession.CurUser.EntList[i];

    'Append the entity name to the list.entNameList = entNameList + ent.EntName;

  • Using Sessions 37

    Wonderware Factelligence Client API Reference Guide

    Logging off from EntitiesWhen the user is finished with an entity, they can log off the entity using the Job Summary control or you can script the log off as shown in the LogOffEnt script.

    Example: LogOffEnt ScriptYou can call the LogoffEnt script after setting UDA (me.EntityName) with the entity name you want to log off from. You should mark this as an asynchronous script.

    Next;if (entNameList.Length > 0) then

    LogMessage("The user is logged onto the following Entities: " + entNameList);else

    LogMessage("The user is not logged onto any entities");endif;

    LogMessage("***********************************************");

    endif;

  • 38 Chapter 3 Using the Factelligence Client API

    Wonderware Factelligence Client API Reference Guide

    You can use the LogoffEnt script as an Execute or OnTrue script with a UDA trigger (me.LogoffEntTrig).

    Ending SessionsWhen the application is terminating, you can use the code in the Term script shown below to end the session. If you do not end a session, the Factelligence Service cleans it up as soon as it determines that the session is stale.

    Example: Term ScriptYou can call the Term script to clean up and end a session. The Term script should be called one time by one Application Object.

    ' LogOffEnt Script

    dim clientSession As aaFactMES.aaClientSession;

    dim result As aaFactMES.Result;

    dim entityID as Integer;

    ' reset the triggerme.LogoffEntTrig = false;

    ' Get the singleton client session

    result = aaFactMES.aaClientSession.GetInstance();

    clientSession = result.Value;

    if ( clientSession null ) thenif ( clientSession.curUser null and me.EntityName "" ) then

    ' get Entity ID from input UDA Entity Nameresult = aaFactMES.aaEnt.EntIdFromName( me.EntityName );if ( result.Success == true and result.Int32_Value -1) then

    ' go an entity ID - attempt to logoffentityID = result.Int32_Value;result = clientSession.curUser.LogoffEnt( entityID );if ( result.Success == true ) then

    LogMessage(clientSession.curUser.userName + " has logged off of entity " + me.EntityName + " - id=" + StringFromIntg(entityID, 10) );

    endif;else

    ' Failed to get Entity ID from Entity NameLogMessage("Entity " + me.EntityName + " does not seem to exist");

    endif;endif;

    endif;

  • Web Access 39

    Wonderware Factelligence Client API Reference Guide

    You can use the Term script as either an OffScan or Execute script with some attribute-based trigger. If you use it as an Execute script, you should mark it as an asynchronous script.

    Web AccessWonderware Factelligence provides a variety of extensibility capabilities to application authors, enabling access to the core business logic, runtime data, and historical data store at the heart of the product. The Web Access feature exposes the Factelligence Middleware functionality through a standardized Web Service.

    Note It is assumed that the reader and the application programmer have a solid understanding and working knowledge of the Factelligence Client API.

    Using Web AccessThe Web Access usage code example below represents a standard web page, utilizing the client-side capabilities of Factelligence, which accesses a list of entities configured in the Factelligence database and populates an editbox on the webpage with the list. The key elements of this example are:

    1 XMLExecBuilder (from Fact.Common.DLL) is used to create and format the XML request which is sent to the Factelligence Middleware.

    2 Encoding XML string into XML bytes via System.Text.UnicodeEncoding.ASCII.GetBytes().

    ' Term Script

    dim clientSession As aaFactMES.aaClientSession;

    dim result As aaFactMES.Result;

    ' Get the singleton client session

    result = aaFactMES.aaClientSession.GetInstance();

    clientSession = result.Value;

    if ( clientSession null and clientSession.SessionId -1 ) then' log everyone off and stop sessionclientSession.LogOffAllUsers();clientSession.EndSession();LogMessage("Session Ended");

    endif;

  • 40 Chapter 3 Using the Factelligence Client API

    Wonderware Factelligence Client API Reference Guide

    3 Formatted XML request is sent to the Factelligence Middleware via HttpWebRequest method 'GetResponse()'.

    Sample Client Code to access the HTTP Hander:

    System.Net.HttpWebRequest request = (System.Net.HttpWebRequest) System.Net.WebRequest.Create( "http://Factelligence/WebServices/XMLRequest.aspx" );

    request.ContentType = "text/xml";

    request.Method = "POST";

    // Build XML command / request

    //You can build the xml request using the standard Fact.Common.dll

    Fact.Common.XMLExecBuilder xe = new XMLExecBuilder(111, "ent", StdWriteCommands.Add);

    xe.AddParam("ent_name", "TEST ENTITY");

    xe.AddParam("can_sched_jobs", "1");

    xe.AddParam("can_capture_util", "1");

    xe.AddParam("identical_job_execs", "10");

    // Add more parameters here as needed.

    reqstr = xe.Xml.ToString();

    byte[] xmlBytes = System.Text.UnicodeEncoding.ASCII.GetBytes(reqstr);

    request.ContentLength = xmlBytes.Length;

    //Send Request

    Stream QueryStream = request.GetRequestStream();

    QueryStream .Write(xmlBytes, 0, xmlBytes.Length);

    QueryStream .Close();

    // Send the request and get the response.

    System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();

    // Read the response stream.

    Stream responseStream = response.GetResponseStream();

    StreamReader reader = new StreamReader(responseStream);

    string responseString = reader.ReadToEnd();

    textBox4.Text = responseString;

    //Close the response stream objects.

  • Web Access 41

    Wonderware Factelligence Client API Reference Guide

    responseStream.Close();

    reader.Close();

    request = null;

    response = null;

    QueryStream = null;

    responseStream = null;

    reader = null;

  • 42 Chapter 3 Using the Factelligence Client API

    Wonderware Factelligence Client API Reference Guide

  • 43

    Wonderware Factelligence Client API Reference Guide

    Chapter 4

    API Classes

    Attrs ClassThe Attrs class contains methods that retrieves and sets various attributes within the Factelligence system.

    Attrs ConstructorThe Attrs Constructor initializes a new instance of the Attrs class.

    AddLotAttrs() MethodThe AddLotAttrs() method adds the specified attribute to the specified lot with an initial value. Syntax[Visual Basic (Declaration)]Public Shared Sub AddLotAttrs( _

    ByVal itemId As String, _ ByVal lotNo As String, _ ByVal attrId As Integer, _ ByVal initialValue As String _

    )

    [C#]public static void AddLotAttrs(

    string itemId, string lotNo, int attrId, string initialValue

    )

    [C++]

  • 44 Chapter 4 API Classes

    Wonderware Factelligence Client API Reference Guide

    public:static void AddLotAttrs(String itemId, String lotNo, int attrId, String initialValue

    )

    [J#] public static void AddLotAttrs(

    string itemId, string lotNo, int attrId, string initialValue

    )

    [JScript]public static function AddLotAttrs(

    itemId : String, lotNo : String, attrId : int, initialValue : String

    )

    Parameters

    itemIdHolds the item ID used to identify the lot.

    lotNoHolds the lot number to identify the lot.

    attrIdHolds the attribute ID to initialize for this lot.

    initialValueHolds the attribute value for this lot.

    ExceptionsAn exception is thrown if the command fails for any reason.

    GetAttrID() Method (String)The GetAttrID() method looks up the specified attribute name and returns the ID of the attribute.Syntax[Visual Basic (Declaration)]Public Shared Function GetAttrID( _

    ByVal attrName As String _ ) As Integer

    [C#]public static int GetAttrID(

    string attrName)

  • Attrs Class 45

    Wonderware Factelligence Client API Reference Guide

    [C++]public:

    static int GetAttrID(String attrName

    )

    [J#]public static int GetAttrID(

    string attrName)

    [JScript]public static function GetAttrID(

    attrName : String) : int

    Parameter

    attrNameHolds the name of the attribute to look up.

    Return Value Returns an integer representing the attribute ID.

    GetAttrID() Method (String, Generic Nullable)The GetAttrID() method looks up the specified attribute name and returns the ID of the attribute.Syntax[Visual Basic (Declaration)]Public Shared Function GetAttrID( _

    ByVal attrName As String, _ ByVal attr_grp As Nullable(Of Integer) _

    ) As Integer

    [C#]public static int GetAttrID(

    string attrName, Nullable attr_grp

    )

    [C++]public:

    static int GetAttrID(String attrName, Nullable attr_grp

    )

    [J#]public static int GetAttrID(

    string attrName, Nullable attr_grp

    )

  • 46 Chapter 4 API Classes

    Wonderware Factelligence Client API Reference Guide

    [JScript]public static function GetAttrID(

    attrName : String, attr_grp : Nullable

    ) : int

    Parameters

    attrNameHolds the name of the attribute to look up.

    attr_grpHolds the attribute group type.

    Return Value Returns an integer representing the attribute ID.

    Exception This method throws an error if an error occurs while fetching the data.

    GetAttrs() MethodThe GetAttrs() method returns a DataSet containing all the attributes defined on to the system.Syntax[Visual Basic (Declaration)]Public Shared Function GetAttrs() As DataSet [C#]public static DataSet GetAttrs()

    [C++]public:

    static DataSet GetAttrs() [J#]public static DataSet GetAttrs()

    [JScript]public static function GetAttrs() : DataSet

    Return Value Returns a DataSet containing a table with a row for each attribute.

    ExceptionsThis method throws an exception if an error occurs while retrieving the attributes.

    GetAttrSet() MethodThe GetAttrSet() method returns a DataSet containing all of the possible attribute values for the given attribute name.

  • Attrs Class 47

    Wonderware Factelligence Client API Reference Guide

    Syntax[Visual Basic (Declaration)]Public Shared Function GetAttrSet( _

    ByVal attrName As String _ ) As DataSet

    [C#]public static DataSet GetAttrSet(

    string attrName)

    [C++]public:

    static DataSet GetAttrSet(String attrName

    )

    [J#]public static DataSet GetAttrSet(

    string attrName

    )

    [JScript]public static function GetAttrSet(

    attrName : String) : DataSet

    Parameter

    attrNameAttribute name.

    Return Value Returns a DataSet containing the possible values for the named attribute.

    GetAttrsVisibleInInv MethodThe GetAttrsVisibleInInv() method returns a DataSet containing all the attributes defined on the system that are visible in inventory.Syntax[Visual Basic (Declaration)]Public Shared Function GetAttrsVisibleInInv() As

    DataSet

    [C#]public static DataSet GetAttrsVisibleInInv()

    [C++]public:

    static DataSet GetAttrsVisibleInInv()

    [J#]

  • 48 Chapter 4 API Classes

    Wonderware Factelligence Client API Reference Guide

    public static DataSet GetAttrsVisibleInInv()

    [JScript]public static function GetAttrsVisibleInInv() :

    DataSet

    Return Value Returns a DataSet containing a table with a row for each attribute.

    ExceptionsThis method throws an exception if an error occurs while retrieving the attributes.

    GetAttrValue() Method (String, String, String, String)

    The GetAttrsValue () method functions to return an AttrValue class containing the attribute value, last_edit_at, mod_ID, and the attribute ID from the passed in attribute name and an associated filter item.Syntax[Visual Basic (Declaration)]Public Shared Function GetAttrValue( _

    ByVal attrName As String, _ ByVal tableName As String, _ ByVal filterField As String, _ ByVal filterValue As String _

    ) As Attrs.attrValue

    [C#]public static Attrs.attrValue GetAttrValue(

    string attrName, string tableName, string filterField, string filterValue

    )

    [C++]public:

    static Attrs.attrValue GetAttrValue(String attrName, String tableName, String filterField, String filterValue

    )

    [J#]public static Attrs.attrValue GetAttrValue(

    string attrName, string tableName, string filterField, string filterValue

  • Attrs Class 49

    Wonderware Factelligence Client API Reference Guide

    )

    [JScript]public static function GetAttrValue(

    attrName : String, tableName : String, filterField : String, filterValue : String

    ) : Attrs.attrValue

    Parameters

    attrNameAttribute name.

    tableName"Attribute" table name to be read, for example "item_attr" for item attributes.

    filterFieldFirst filter field to be used, for example "item_ID".

    filterValueFirst filter value associated with the first filter field.

    Return Value Returns an AttrValue object for the specified attribute.

    GetAttrValue() Method (String, String, String, String, String, String)

    The GetAttrsValue () method functions to return an AttrValue class containing the attribute value, last_edit_at, mod_ID, and the attribute ID from the passed in attribute name and associated filter items with an optional filter field (up to 2 filters).Syntax[Visual Basic (Declaration)]Public Shared Function GetAttrValue( _

    ByVal attrName As String, _ ByVal tableName As String, _ ByVal filterField As String, _ ByVal filterValue As String, _ ByVal filterField1 As String, _ ByVal filterValue1 As String _

    ) As Attrs.attrValue

    [C#]public static Attrs.attrValue GetAttrValue(

    string attrName, string tableName, string filterField, string filterValue, string filterField1,

  • 50 Chapter 4 API Classes

    Wonderware Factelligence Client API Reference Guide

    string filterValue1)

    [C++]public:

    static Attrs.attrValue GetAttrValue(String attrName, String tableName, String filterField, String filterValue, String filterField1, String filterValue1

    )

    [J#]public static Attrs.attrValue GetAttrValue(

    string attrName, string tableName, string filterField, string filterValue, string filterField1, string filterValue1

    )

    [JScript]public static function GetAttrValue(

    attrName : String, tableName : String, filterField : String, filterValue : String, filterField1 : String, filterValue1 : String

    ) : Attrs.attrValue

    Parameters

    attrNameAttribute name.

    tableName"Attribute" table name to be read, for example "item_attr" for item attributes.

    filterFieldFirst filter field to be used, for example "item_ID".

    filterValueFirst filter value associated with the first filter field.

    filterField1Second filter field to be used, for example "item_ID".

    filterValue1Second filter value associated with the second filter field.

    Return Value Returns an AttrValue object for the specified attribute.

  • Attrs Class 51

    Wonderware Factelligence Client API Reference Guide

    Exceptions

    Exception Type Condition An exception is thrown if an error occurs while getting the attribute value from the database.

    GetAttrValue() Method (String, String, String, String, String, String, String, String)

    The GetAttrsValue () method functions to return an AttrValue class containing the attribute value, last_edit_at, mod_ID, and the attribute ID from the passed in attribute name and associated filter items with 2 optional filters (up to 3 filters).Syntax[Visual Basic (Declaration)]Public Shared Function GetAttrValue( _

    ByVal attrName As String, _ ByVal tableName As String, _ ByVal filterField As String, _ ByVal filterValue As String, _ ByVal filterField1 As String, _ ByVal filterValue1 As String, _ ByVal filterField2 As String, _ ByVal filterValue2 As String _

    ) As Attrs.attrValue

    [C#]public static Attrs.attrValue GetAttrValue(

    string attrName, string tableName, string filterField, string filterValue, string filterField1, string filterValue1, string filterField2, string filterValue2

    )

    [C++]public:

    static Attrs.attrValue GetAttrValue(String attrName, String tableName, String filterField, String filterValue, String filterField1, String filterValue1, String filterField2, String filterValue2

    )

    [J#]public static Attrs.attrValue GetAttrValue(

  • 52 Chapter 4 API Classes

    Wonderware Factelligence Client API Reference Guide

    string attrName, string tableName, string filterField, string filterValue, string filterField1, string filterValue1, string filterField2, string filterValue2

    )

    [JScript]public static function GetAttrValue(

    attrName : String, tableName : String, filterField : String, filterValue : String, filterField1 : String, filterValue1 : String, filterField2 : String, filterValue2 : String

    ) : Attrs.attrValue

    Parameters

    attrNameAttribute name.

    tableName"Attribute" table name to be read, for example "item_attr" for item attributes.

    filterFieldFirst filter field to be used, for example "item_ID".

    filterValueFirst filter value associated with the first filter field.

    filterField1Second filter field to be used, for example "item_ID".

    filterValue1Second filter value associated with the second filter field.

    filterField2Third filter field to be used, for example "item_ID".

    filterValue2Third filter value associated with the third filter field.

    Return Value Returns an AttrValue object for the specified attribute.

    Exceptions

    Exception Type Condition An exception is thrown if an error occurs while getting the attribute value from the database.

  • Attrs Class 53

    Wonderware Factelligence Client API Reference Guide

    GetEntAttrs() Method (Int32)The GetEntAttrs() method retrieves all the defined entity attributes for the specified entity ID from the database.Syntax[Visual Basic (Declaration)]Public Shared Function GetEntAttrs( _

    ByVal entId As Integer _ ) As DataSet

    [C#]public static DataSet GetEntAttrs(

    int entId

    ) [C++]public:

    static DataSet GetEntAttrs(int entId

    )

    [J#]public static DataSet GetEntAttrs(

    int entId)

    [JScript]public static function GetEntAttrs(

    entId : int) : DataSet

    Parameter

    entIdHolds the entity for which attributes are requested.

    Return Value Returns a DataSet containing 0 or more rows for each entity attribute that is assigned to this entity.

    GetEntAttrs Method (Int32, Int