Can't threads be executed in the remapping script?

More
17 Dec 2021 12:17 #229284 by chen1234
I created a thread in the remapping code, but it cannot execute the loop in the thread.
I remapped a code to receive an external io signal. I need to read this signal in a loop for judgment, so I created a thread and let this loop execute in the thread. But when I tested this code, I found that it could not execute the function in this thread. I don't know why. My thread was created successfully. Hope someone can give me advice.
#!/usr/bin/env python3

import struct
import sys 
import os
from interpreter import *
import hal
import linuxcnc
import _thread



def Z_jogs(self,a):
        print('a = ',a)
        b=a
        print('b=',b)
        while True :
            x = hal.get_value('lcec.0.5.RXPDO-5') #read EtherCAT io  
            print('x_in5 =',x)
            if x == 1:
                print("in5 = ",x)
                self.execute("G0 Z %d"%b)    #Control Z axis movement
                b += a
            elif x == 0:
                print("in5 = ",x)
            if hal.get_value('lcec.0.5.TXPDO-2') == 1:   
                break 

# read EtherCAT io 
def m203(self,**words):
    yield INTERP_EXECUTE_FINISH
    if self.task:
        self.Z_jogs = Z_jogs()
        a = (words['s'])
        print("a=",a)
        try:
           _thread.start_new_thread(Z_jogs,(a,))
           print('qw')
        except:
           print('erro')

Please Log in or Create an account to join the conversation.

More
17 Dec 2021 13:06 #229288 by andypugh
I haven't tried this, but I really wouldn't expect it to work.

Why do you want to start a thread? Can you explain what you are trying to do?

Please Log in or Create an account to join the conversation.

More
20 Dec 2021 01:43 #229535 by chen1234
Thank you for your reply,
my job is like this: I need to control the Z-axis movement by receiving the feed signal of the scanning head.
It works as follows: When the device is in the hole-making state during operation, it will send a high-level signal to my EtherCAT board. When I receive this signal, I need to control the Z-axis movement for a specified distance. This high-level signal It is not continuous, so I need a thread to let it execute the read signal in a loop. But the problem I currently encounter is that the thread is successfully created and the function is not executed. Is the remapping code not supporting threads? Or is there another way?

Please Log in or Create an account to join the conversation.

More
20 Dec 2021 03:17 #229536 by cmorley

Please Log in or Create an account to join the conversation.

More
21 Dec 2021 20:47 #229652 by andypugh
You can probably do this with a custom HAL component and the external offsets feature.
linuxcnc.org/docs/2.8/html/motion/external-offsets.html

Please Log in or Create an account to join the conversation.

Time to create page: 0.180 seconds
Powered by Kunena Forum