etherlab/runtime_etherlab.py
changeset 2360 2a3d022a7dac
parent 2358 8e5a9830867e
child 2363 9c7da6ff6a34
equal deleted inserted replaced
2359:e945fcb54cd4 2360:2a3d022a7dac
    13 SDOAnswered.argtypes = []
    13 SDOAnswered.argtypes = []
    14 
    14 
    15 SDOThread = None
    15 SDOThread = None
    16 SDOProc = None
    16 SDOProc = None
    17 Result = None
    17 Result = None
       
    18 
    18 
    19 
    19 def SDOThreadProc(*params):
    20 def SDOThreadProc(*params):
    20     global Result, SDOProc
    21     global Result, SDOProc
    21     if params[0] == "upload":
    22     if params[0] == "upload":
    22         cmdfmt = "ethercat upload -p %d -t %s 0x%.4x 0x%.2x"
    23         cmdfmt = "ethercat upload -p %d -t %s 0x%.4x 0x%.2x"
    46     if res != 0 :
    47     if res != 0 :
    47         PLCObject.LogMessage(
    48         PLCObject.LogMessage(
    48             LogLevelsDict["WARNING"],
    49             LogLevelsDict["WARNING"],
    49             "%s : %s" % (command,output))
    50             "%s : %s" % (command,output))
    50 
    51 
       
    52 
    51 def EthercatSDOUpload(pos, index, subindex, var_type):
    53 def EthercatSDOUpload(pos, index, subindex, var_type):
    52     global SDOThread
    54     global SDOThread
    53     SDOThread = Thread(target=SDOThreadProc, args=["upload", pos, var_type, index, subindex])
    55     SDOThread = Thread(target=SDOThreadProc, args=["upload", pos, var_type, index, subindex])
    54     SDOThread.start()
    56     SDOThread.start()
    55 
    57 
       
    58 
    56 def EthercatSDODownload(pos, index, subindex, var_type, value):
    59 def EthercatSDODownload(pos, index, subindex, var_type, value):
    57     global SDOThread
    60     global SDOThread
    58     SDOThread = Thread(target=SDOThreadProc, args=["download", pos, var_type, index, subindex, value])
    61     SDOThread = Thread(target=SDOThreadProc, args=["download", pos, var_type, index, subindex, value])
    59     SDOThread.start()
    62     SDOThread.start()
       
    63 
    60 
    64 
    61 def GetResult():
    65 def GetResult():
    62     global Result
    66     global Result
    63     return Result
    67     return Result
    64 
    68 
    65 KMSGPollThread=None
    69 KMSGPollThread=None
    66 StopKMSGThread=False
    70 StopKMSGThread=False
       
    71 
       
    72 
    67 def KMSGPollThreadProc():
    73 def KMSGPollThreadProc():
    68     """
    74     """
    69     Logs Kernel messages starting with EtherCAT
    75     Logs Kernel messages starting with EtherCAT
    70     Uses GLibc wrapper to Linux syscall "klogctl"
    76     Uses GLibc wrapper to Linux syscall "klogctl"
    71     Last 4 KB are polled, and lines compared to last
    77     Last 4 KB are polled, and lines compared to last
    93                         "4":"WARNING",
    99                         "4":"WARNING",
    94                         "3":"CRITICAL"}.get(lvl,"DEBUG")],
   100                         "3":"CRITICAL"}.get(lvl,"DEBUG")],
    95                     msg)
   101                     msg)
    96         time.sleep(0.5)
   102         time.sleep(0.5)
    97 
   103 
       
   104 
    98 def _runtime_etherlab_init():
   105 def _runtime_etherlab_init():
    99     global KMSGPollThread, StopKMSGThread
   106     global KMSGPollThread, StopKMSGThread
   100     StopKMSGThread = False
   107     StopKMSGThread = False
   101     KMSGPollThread = Thread(target = KMSGPollThreadProc)
   108     KMSGPollThread = Thread(target = KMSGPollThreadProc)
   102     KMSGPollThread.start()
   109     KMSGPollThread.start()
       
   110 
   103 
   111 
   104 def _runtime_etherlab_cleanup():
   112 def _runtime_etherlab_cleanup():
   105     global KMSGPollThread, StopKMSGThread, SDOProc, SDOThread
   113     global KMSGPollThread, StopKMSGThread, SDOProc, SDOThread
   106     try:
   114     try:
   107         os.kill(SDOProc.pid, SIGTERM)
   115         os.kill(SDOProc.pid, SIGTERM)