Open dpcamargo opened 2 years ago
Could you please explain why you don't want to use the contextmanager (==with
block)? This is exactly the kind of use case for which contextmanagers were added to the Python language as they take care of the setup and teardown of connections to ensure no dangling connections remain. If you do have a valid use case then I can see what I can do to provide another option, but this is definitely the prefered method to make a connection.
I dont know if I can do this in another way, but I'm constantly reading tags, and the opening and closing of the connection puts a small overhead that I have to get rid of. I wanted to create a singleton with the reference, but did not manage to get it to work using the context with. I used the with before calling the reading functions and leaving it open during the program execution, but I would like to put all the PI code inside my class.
Im new at Python and OOP, so maybe i'm doing something wrong.
Maybe you are right that it would be nice to provide the possibility to connect/disconnect manually. For now, you could do the following:
import PIconnect as PI
server = PI.PIServer('SERVER_IP', 'USERNAME', 'PASSWORD')
server.connection.Connect(*server._credentials) # <- This only works if you actually provide credentials on the line above
points = server.search()
server.connection.Disconnect()
Feature request
I am trying to open a connection to the PI Server without using "with open" like the examples provided.
Works fine
Code below does not work:
Error:
I've tried using "authenticate=AuthenticationMode.PI_USER_AUTHENTICATION" but got the same error.
Is there a way that this can be done?