Hugovdberg / PIconnect

A python connector to the OSISoft PI and PI-AF databases
MIT License
91 stars 41 forks source link

PIconnect shows "Testing" after connect to PI servers #595

Closed lujie11111 closed 3 years ago

lujie11111 commented 3 years ago

Bug report

Description

PIconnect does not load the SDK correctly, but uses the Testing framework instead.

Steps to reproduce the behavior:

  1. Open python
  2. Run this snippet
    
    import PIconnect as PI

with PI.PIServer() as server: print(server.server_name)


3. result is "Testing" .... How to solve it? I am able to connect to my server in PI processbook

Expected behavior
-----------------

The name of the connected server is printed

Possible solutions
------------------

--

System
------

-   OS: Windows
-   Python version: 3.8.5
-   PIconnect version: 0.9.0
Hugovdberg commented 3 years ago

Hmm, I can replicate this. For some reason the pythonnet dependency is not installed by pip, not sure why it was not included in the dependencies in the wheel on PyPI. For now you can pip install pythonnet manually to fix this, I'll try to find out how to repackage it with the correct dependencies.

lujie11111 commented 3 years ago

I double checked - Requirement already satisfied: pythonnet in c:\users\luj13\appdata\local\programs\python\python38\lib\site-packages (2.5.2) Requirement already satisfied: pycparser in c:\users\luj13\appdata\local\programs\python\python38\lib\site-packages (from pythonnet) (2.20)

but still showing: with PI.PIServer() as server: print(server.search)

output: <bound method PIServer.search of PIServer(\Testing)>

Hugovdberg commented 3 years ago

Could you run this snippet to see where it goes wrong? If something fails in this step the testing framework is loaded.

import os
import sys
import clr

# Get the installation directory from the environment variable or fall back
# to the Windows default installation path
PIAF_SDK = os.getenv("PIHOME", "C:\\Program Files\\PIPC")
PIAF_SDK += "\\AF\\PublicAssemblies\\4.0\\"
if not os.path.isdir(PIAF_SDK):
    raise ImportError("PIAF SDK not found in %s, check installation" % PIAF_SDK)

sys.path.append(PIAF_SDK)
clr.AddReference("OSIsoft.AFSDK")  # pylint: disable=no-member

from OSIsoft import AF  # pylint: wrong-import-position

AF_SDK_VERSION = AF.PISystems().Version
print("OSIsoft(r) AF SDK Version: {}".format(AF_SDK_VERSION))
lujie11111 commented 3 years ago

no fault shown up. and with - OSIsoft(r) AF SDK Version: 2.10.8.440 as results

lujie11111 commented 3 years ago

I added

import PIconnect as PI
print(list(PI.PIServer.servers.keys()))

after your code, and shwon time out:

System.TimeoutException: The open operation did not complete within the allotted timeout of 00:04:59.9900115. The time allotted to this operation may have been a portion of a longer timeout.

Server stack trace:
   at System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)

Exception rethrown at [0]:
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at System.ServiceModel.ICommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.ClientBase`1.System.ServiceModel.ICommunicationObject.Open(TimeSpan timeout)
   at OSIsoft.AF.Support.AFProxy.Reconnect(Boolean autoPrompt, AFConnectionProtocol protocol, String host, Int32 port, String accountName, 
TimeSpan timeout)
Hugovdberg commented 3 years ago

Then I have no idea why in your situation the testing framework is loaded. I would think that when you import PIconnect in that same session it runs exactly that code as I copied and pasted it from the sourcecode for version 0.9.0. Is the environment correctly activated in the setting where you got the error?

Regarding the timeout, it appears one of the configured servers could not be reached. There is a check for this situation that was hard to test, but apparently the check handles the wrong base type of exceptions. I will fix this in the hotfix I linked to this issue.

Hugovdberg commented 3 years ago

I just pushed a new version to PyPI, could you please update and try if the error is now gone?

lujie11111 commented 3 years ago

Hi Hugo, the 0.9.1 version works!! Thank you so much!!

strojank commented 3 years ago

Hey @Hugovdberg - I am not sure if this is the right place for the question, but is PIconnect expected to work on a Red Hat OS?