bnjmnp / pysoem

Cython wrapper for the Simple Open EtherCAT Master Library
MIT License
96 stars 37 forks source link

about the incorrect wkc #56

Closed tom9672 closed 2 years ago

tom9672 commented 2 years ago

I try to use two functions, one does the setup and another does the teardown.

def setup():
    ...
    self.check_thread.start()
    self.proc_thread.start()
    ...
def teardown():
    ...
    self.check_thread_stop_event.set()
    self.check_thread_stop_event.set()
    self.proc_thread.join()
    self.check_thread.join()
    ...

Sometimes I call the teardown, it successfully stops the thread and closes everything. But sometimes it prints 'incorrect wkc', I checked the actual wkc is -1 or 0, and the expected is 9.

Does that mean the teardown is already close to the master, but the pdo_thread is still running?

tom9672 commented 2 years ago

It works now, I tested many times and the 'incorrect wkc' never happened. I just tried to:

class A:
    def setup():
        ...
    def teardown():
        ...
from xxx import A
class B:
    def __init__(self):
        self.a = A
        self.a.setup()

b = B
b.a.teardown() # some times, it will happen 'incorrect wkc'
from xxx import A
class B:
    def __init__(self):
        self.a = A
        self.a.setup()

    def stop(self):
        self.a.teardown()
b = B
b.stop() # tried many times, not happen  'incorrect wkc' 

not clear why, but it seems the issue is solved. Does somebody knows why? or any other better solutions.

BWT, what makes the incorrect wkc? It also happened that I didn’t use the teardown to stop the pdo. but the incorrect wkc occur.