Mostly Scripting

I am trying to understand the Python runspaces in Ignition and had a couple of statements/questions. Please correct me if I am wrong.

[quote]https://inductiveautomation.com/forum/viewtopic.php?f=50&t=13914&p=50718&hilit=global+variable#p50718
https://inductiveautomation.com/forum/viewtopic.php?f=72&t=8684&p=28732&hilit=global+variable#p28732[/quote]
1) Global Python variables exist in different runspaces, therefore, a client script global variable is not visible to a gateway script global variable (and vice versa)

2) Memory tags are visible to both client and gateway runspaces.

3) system.util.sendMessage looks to be helpful.
... but where do I obtain all clientSessionIds?

Questions:

  1. When does the script manager re-initialize?

  2. Can someone provide an example of a coroutine (not threading)?

  3. Are memory tags shared between multiple instance of the same project?

  4. Are gateway global variables shared between multiple instances of the same project?

  5. I see that memory tags can be typed to some simple Java types, a dataset, or a UDT.
    Can an instance of a Python object be held in a memory tag? If so, how?

  6. What kinds of serialization schemes are available to move data from client to gateway memory space?

  7. Are there plans to upgrade Python to a newer version? If so, when?

Thanks
/c

Whenever the project is saved.

I think you'll find a number of examples if you search, e.g. juandebravo.com/2015/07/06/d ... in-python/

Memory tags and global variables are both defined in the gateway, and there is only one "instance" of each project ever running on the gateway.

I think you can write any object you want to a tag, though the designer likely won't display anything meaningful for its value if you're looking at it.

I'm not sure what you mean, but using the client messaging would be an acceptable way to transfer data from client to gateway. You can also write to tags or execute database queries...

We'll be upgrading to Jython 2.7 either in 7.9 or the release immediately following it.

Thank you!

So what happens when multiple clients are running the same project?

/c

They get their own client tags, but the memory tags are shared.

Sounds scary :smiling_imp: .

[quote="Kevin.Herron"][quote="cmisztur2"]Thank you!

So what happens when multiple clients are running the same project?

/c[/quote]

They get their own client tags, but the memory tags are shared.[/quote]

What does this scenario look like if I have one project for 5 different machine cells and each cell needs their own instance of the project?

/c

[quote=“cmisztur2”][quote=“Kevin.Herron”][quote=“cmisztur2”]Thank you!
What does this scenario look like if I have one project for 5 different machine cells and each cell needs their own instance of the project?
[/quote][/quote][/quote]

Tags exist as part of the gateway, independent of whether any projects exist or not.

You need to design your project or projects with that in mind.

In this case, you could have one project that had maybe a screen for each machine cell, and some configuration or indirection dictated which tags the screen actually referenced, or (less ideally) 5 separate projects that were all slightly different in some way.

[quote=“Kevin.Herron”]

Tags exist as part of the gateway, independent of whether any projects exist or not.

You need to design your project or projects with that in mind.

In this case, you could have one project that had maybe a screen for each machine cell, and some configuration or indirection dictated which tags the screen actually referenced, or (less ideally) 5 separate projects that were all slightly different in some way.[/quote]

Understood. That gives meaning to UDTs and Templates.

Thanks.

1 Like

HI Kevin

import time
total = 0
tempa = 0
oldtotal = 0
def calculate_downtime(start):    
    global total, tempa, start_time, end_time,oldtotal
    if start == False and tempa == 0:  
        start_time = time.time()  
        tempa = 1  
    elif start == True:
         tempa = 0   
    if tempa == 1:  
        end_time = time.time()  
        total = (end_time - start_time) + oldtotal
        return total/60
    elif tempa == 0:
         oldtotal = total
         return oldtotal/60

When I save the project, the global variables above are reset to zero. How can I prevent them from being reset to zero

You are posting this in many places. This against this forum's rules.

Sorry,I don't know that
it won't be next time