Maroder1 / Openness_examples_python

27 stars 7 forks source link

FileNotFoundException: Could not load file or assembly 'Siemens.Engineering.Contract, Version=1600.0.3102.1 #6

Open illUkc opened 1 year ago

illUkc commented 1 year ago

Any tips why i cant import ?

My code : import clr clr.AddReference('C:\Program Files\Siemens\Automation\Portal V16\PublicAPI\V16\Siemens.Engineering.dll') from System.IO import DirectoryInfo, FileInfo import Siemens.Engineering as tia

Allways getting error : Output exceeds the size limit. Open the full output data in a text editor

FileNotFoundException Traceback (most recent call last) Cell In [2], line 4 2 clr.AddReference('C:\Program Files\Siemens\Automation\Portal V16\PublicAPI\V16\Siemens.Engineering.dll') 3 from System.IO import DirectoryInfo, FileInfo ----> 4 import Siemens.Engineering as tia

File :1178, in _find_andload(name, import)

File :1149, in _find_and_loadunlocked(name, import)

File :676, in _load_unlocked(spec)

File :573, in module_from_spec(spec)

File :15, in create_module(klass, spec)

FileNotFoundException: Could not load file or assembly 'Siemens.Engineering.Contract, Version=1600.0.3102.1, Culture=neutral, PublicKeyToken=37a18b206f7724a6' or one of its dependencies. The system cannot find the file specified. File name: 'Siemens.Engineering.Contract, Version=1600.0.3102.1, Culture=neutral, PublicKeyToken=37a18b206f7724a6' at System.Signature.GetSignature(Void* pCorSig, Int32 cCorSig, RuntimeFieldHandleInternal fieldHandle, IRuntimeMethodInfo methodHandle, RuntimeType declaringType) at System.Reflection.RuntimeConstructorInfo.GetParametersNoCopy() at System.Reflection.MethodBase.GetParameterTypes() at System.Reflection.MethodBase.FormatNameAndSig(Boolean serialization) at System.Reflection.RuntimeConstructorInfo.ToString() at Python.Runtime.MethodObject..ctor(MaybeType type, String name, MethodBase[] info, Boolean allow_threads) ... WRN: Assembly binding logging is turned OFF. To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1. Note: There is some performance penalty associated with assembly bind failure logging. To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

georg9382 commented 1 year ago

Hi, I was faced with the same problem. But I could fix it for me.

It noticed that fault message on some windows systems, while other ones were working fine.

A had a problem with my python script on that systems. So I went to python consol and executed the commands step by step. This is, where I got this fault message. However I don't get that fault, when I run the script normal like "py script.py". In this case the following command (after import...) was failing, that was supposed to start a TIA session. What I found out was, that it didn't work with default () parameter, but I had to give the parameter explicit.

georg9382 commented 1 year ago

Discord? What do you mean?

On Fri, Jan 27, 2023 at 3:45 PM illUka @.***> wrote:

Thanks for the answer.

Do you have discord?

V V pet., 27. jan. 2023 ob 14:06 je oseba georg9382 < @.***> napisala:

Hi, I was faced with the same problem. But I could fix it for me.

It noticed that fault message on some windows systems, while other ones were working fine.

A had a problem with my python script on that systems. So I went to python consol and executed the commands step by step. This is, where I got this fault message. However I don't get that fault, when I run the script normal like "py script.py". In this case the following command (after import...) was failing, that was supposed to start a TIA session. What I found out was, that it didn't work with default () parameter, but I had to give the parameter explicit.

β€” Reply to this email directly, view it on GitHub < https://github.com/Maroder1/Openness_examples_python/issues/6#issuecomment-1406486588 , or unsubscribe < https://github.com/notifications/unsubscribe-auth/AOYYI2IOP5DQNKWQ22VFYNDWUPB5XANCNFSM6AAAAAAUIP24IE

. You are receiving this because you authored the thread.Message ID: @.***>

β€” Reply to this email directly, view it on GitHub https://github.com/Maroder1/Openness_examples_python/issues/6#issuecomment-1406601125, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQ4PRQIONXRFTYWGUH6CYITWUPNQDANCNFSM6AAAAAAUIP24IE . You are receiving this because you commented.Message ID: @.***>

georg9382 commented 1 year ago

πŸ˜€ sounds like a lot of work. I prefer staying in public. I might not be the best one to support you.

illUkc commented 1 year ago

Hey Georg,

I fixed the previous problem. It wasn't working in Jupyter Notebook, but it worked in a .py script. I'm not sure why.

However, I'm now facing a new problem. I'm trying to export HMI tags, but I'm getting an error. Here's my code:

processes = tia.TiaPortal.GetProcesses()
process = processes[0]  
mytia = process.Attach()
myproject = mytia.Projects[0]

software_container = tia.IEngineeringServiceProvider(myproject.Devices[1]).GetService[hwf.SoftwareContainer]()
software = software_container.Software   ## error here  

tags_hmi = software.TagFolder.TagTables.Find("test")

The error message says: 'NoneType' object has no attribute 'Software'. However, when I check in the Siemens Openness Explorer, I got a code snippet that looks like this: (TiaPortal.Projects[0].Devices[1].GetService().Software as HmiTarget).TagFolder.TagTables.

Do you have any tips on what might be causing the error?

Also, do you happen to know if there is an HMI discrete alarms function in the V16 .dll? I checked the 2021 manual, and it seems like there is a function for it, but my .dll doesn't seem to have it."

link of manual : https://cache.industry.siemens.com/dl/files/533/109798533/att_1069908/v1/TIAPortalOpennessenUS_en-US.pdf

georg9382 commented 1 year ago

Hi, ok, so for your previous problem the same solution helped for you that also worked for me...

For the other problem I have no idea.