4 Replies Latest reply on Jun 17, 2016 9:46 AM by piotrszelag

    Connect to PI using matlab when user is outside domain

    piotrszelag

      Hello

      I wrote script in matlab basing on White Paper - Using PI Data with MATLAB

      It is working when I am at work (in domain), but when I am trying to connect (through VPN, using trust) from home script didn't work.

      I searched information and I think that I know where the problem is but I can't how to write some code lines

      so I will be grateful for your help.

       

      Part of my script

       

      % załadowanie sdk

      afsdk = NET.addAssembly('OSIsoft.AFSDK');

      import OSIsoft.AF.*

      import OSIsoft.AF.Asset.*

      import OSIsoft.AF.Time.*

      import System.*

      % stworzenie obiektu reprezentującego systemy AF

      af_serwery = PISystems

      %stworzenie pojedynczego serwera poprzez właściwość domyślnego serwera

      af_serwer=af_serwery.DefaultPISystem

      here is the problem because when I write  command af_serwer.IsConnected  the answer is 0

      I found that I should connect using NetworkCredential PISystem.Connect Method (NetworkCredential)

      but I don't know how use it in Matlab   (I can't find NetworkCredential object)

       

      and mayby there is other way, for example setting trust to connect to PI AF

      for now my trust looks like below (CZERWONY is the name of my laptop)

      when I am starting PI System Explorer I must to write name and password every time (when I connect to server through VPN)

        • Re: Connect to PI using matlab when user is outside domain
          gachen

          Hi Piotr,

           

          As you said, you'll probably need to use a different connection method, since I assume currently it's using the PISystem.Connect() overload? If you choose to use the overload PISystem.Connect(NetworkCredential), you will need to provide the NetworkCredential object in your code. This object is of type System.Net.NetworkCredential, so you'll likely need to import System.Net into your project to access it. Otherwise, you may use another overload like Connect(bool, IWin32Window), which will provide a logon dialog similar to the one you see for PI System Explorer for credentials if the initial logon fails. This could be a better choice if the application is meant to be used both within and outside the domain environment (so you don't need to populate the NetworkCredential yourself in the code).

           

          By the way, since we are talking about connecting to a PISystem (AF server) here, the PI Data Archive trusts do not come into play in the connection attempts. PI Data Archive trusts will only be considered for use if you are connecting to a PI Data Archive (OSIsoft.AF.PI.PIServer). Additionally, Windows authentication is the only option for connecting to PI AF servers.

          1 of 1 people found this helpful