I am using a thread to monitor an input signal whenever it is required in the program sequence.
The thread is created in Installation Node and called from the Program Node when required.
As i am calling and killing the thread in the same URCap, the thread is created as many times the URCap is used in the program sequence.
The current situation is i could use only 50 one particualr URCap in the program as i get an error “Cannot create thread: All 50 allowed threads are used by the program”.
I would like to use more than 50 URCaps and at the same time use the thread to monitor the input signal when required in the program.
How do i solve this problem?
There is hard limit of 50 threads in controller.
Could you post script code example?
Potentially you could create a monitoring thread in installation contribution, and then communicate status through global variable.
I’ve ran in the same issue as OP. Can you elaborate a bit more on what “monitoring thread in installation contribution is” and how a global variable solves the issue?
URCap should create single thread monitoring input, and make it available on global variable to all script contributions.
Installation contribution is always called exactly once no matter how many urcap nodes are in the program. Here is an example:
global input1_status = 0
global input2_status = 0
...
def urcap_monitor_thread():
input1_status = read_custom_input(1)
input2_status = read_custom_input(2)
...
end
Node contribution is added every time urcap node is added to the program:
# action dependent on last input state
if input1_status == 1:
...
elif input1_status == 2:
...
end