I recently moved my code to a new computer at work. A basic example code is as follows (but you wouldn't be able to run it as you can't connect to my server - sorry that I couldn't make it any more reproducible).
With the new computer, I get the following error:
System.ArgumentException: since Python.NET 3.0 int can not be converted to Enum implicitly. Use Enum(int_value) in method OSIsoft.AF.Asset.AFValue RecordedValue(OSIsoft.AF.Time.AFTime, OSIsoft.AF.Data.AFRetrievalMode) ---> Python.Runtime.PythonException: since Python.NET 3.0 int can not be converted to Enum implicitly. Use Enum(int_value)*".
My old computer uses Spyder 4 and Python 3.7 and Python.NET 2.5.2. The new computer uses Spyder 5 and Python 3.9 and Python.NET 3.0. Because of IT restrictions, I am unable to install the same version of Spyder and Python on my computer. However, I do not think it is causing this error.
Would anyone have any idea what would cause an Enum-related problem? Thanks!
import PIconnect as PI
def pidownload(tag):
with PI.PIServer() as server:
point = server.search(tag)[0]
data = point.recorded_value('-1m')
data=data.to_frame()
return data
tag='xxxx.pv' #confidential data tag replaced with xxxx
print(pidownload(tag))
Judging by the documentation for the RecordedValue
function in OSIsoft's documentation and the documentation for recorded_value
in the PIConnect documentation, it seems that the Python-side function is sending an enum and the C#-side function is receiving an enum value. However, when inspecting the GitHub documentation for PIConnect, we can see that the issue is with the retrieval_mode
variable, which has a default value of RetrievalMode.AUTO
, which is an IntEnum
. It appears that the conversion is not working properly, as I noticed this GitHub issue on their repository.
EDIT
After further inspection, it looks like your issue is an installation problem and can be fixed by reinstalling piconnect
, see this question.