主要内容

selectDatabase

Connect AF client to specified database

Since R2026a

    Description

    selectDatabase(afclientObj,databaseName) changes the database associated with the AF client object to the database specified by databaseName.

    Note

    You must install the AF SDK library to connect to a PI AF server from MATLAB®. For more information, see AF SDK Overview.

    example

    Examples

    collapse all

    Create an AF client. If you do not specify a database when you create the client, the client is associated with the default database of the PI AF server.

    afclientObj = afclient("EVS-Hydroplant")
    afclientObj = 
    
      Client with properties:
    
            ServerName: "EVS-Hydroplant"
                Domain: "EVS"
        ServerTimeZone: "UTC+05:30:00"
              Database: "PI-Test"

    Find the databases available on the server.

    databases = listDatabases(afclientObj)
    databases = 
    
      1×3 string array
    
        "Configuration"    "OSIDemo_PG_HydroPlant"    "PI-Test"

    Change the database associated with the AF client.

    selectDatabase(afclientObj,"OSIDemo_PG_HydroPlant");

    Verify if the database associated with the AF client is updated.

    afclientObj.Database
    ans = 
    
      "OSIDemo_PG_HydroPlant"

    Now, when you interact with the afclientObj using functions like findElementByName, findElementByPath, findElementByTemplate, getRootElements, or findAttributeByPath, you obtain results from the OSIDemo_PG_HydroPlant database.

    Input Arguments

    collapse all

    AF client, specified as an icomm.af.Client object created using the afclient function.

    Name of an AF database on the connected AF server, specified as a string or character vector.

    Data Types: char | string

    Version History

    Introduced in R2026a