etherlab/runtime_etherlab.py
changeset 2422 45aa510d7a2a
parent 2407 5f2b1bb464a0
child 2643 b98d9e08231f
equal deleted inserted replaced
2421:a5994ee1f6a7 2422:45aa510d7a2a
    63     SDOThread = Thread(target=SDOThreadProc, args=["download", pos, var_type, index, subindex, value])
    63     SDOThread = Thread(target=SDOThreadProc, args=["download", pos, var_type, index, subindex, value])
    64     SDOThread.start()
    64     SDOThread.start()
    65 
    65 
    66 
    66 
    67 def GetResult():
    67 def GetResult():
    68     global Result
       
    69     return Result
    68     return Result
    70 
    69 
    71 
    70 
    72 KMSGPollThread = None
    71 KMSGPollThread = None
    73 StopKMSGThread = False
    72 StopKMSGThread = False
    78     Logs Kernel messages starting with EtherCAT
    77     Logs Kernel messages starting with EtherCAT
    79     Uses GLibc wrapper to Linux syscall "klogctl"
    78     Uses GLibc wrapper to Linux syscall "klogctl"
    80     Last 4 KB are polled, and lines compared to last
    79     Last 4 KB are polled, and lines compared to last
    81     captured line to detect new lines
    80     captured line to detect new lines
    82     """
    81     """
    83     global StopKMSGThread
       
    84     libc = ctypes.CDLL("libc.so.6")
    82     libc = ctypes.CDLL("libc.so.6")
    85     klog = libc.klogctl
    83     klog = libc.klogctl
    86     klog.argtypes = [ctypes.c_int, ctypes.c_char_p, ctypes.c_int]
    84     klog.argtypes = [ctypes.c_int, ctypes.c_char_p, ctypes.c_int]
    87     klog.restype = ctypes.c_int
    85     klog.restype = ctypes.c_int
    88     s = ctypes.create_string_buffer(4*1024)
    86     s = ctypes.create_string_buffer(4*1024)
   111     KMSGPollThread = Thread(target=KMSGPollThreadProc)
   109     KMSGPollThread = Thread(target=KMSGPollThreadProc)
   112     KMSGPollThread.start()
   110     KMSGPollThread.start()
   113 
   111 
   114 
   112 
   115 def _runtime_etherlab_cleanup():
   113 def _runtime_etherlab_cleanup():
   116     global KMSGPollThread, StopKMSGThread, SDOProc, SDOThread
   114     global KMSGPollThread, StopKMSGThread, SDOThread
   117     try:
   115     try:
   118         os.kill(SDOProc.pid, signal.SIGTERM)
   116         os.kill(SDOProc.pid, signal.SIGTERM)
   119     except Exception:
   117     except Exception:
   120         pass
   118         pass
   121     SDOThread = None
   119     SDOThread = None