Added error logging when SDO FB fails
authorEdouard Tisserant
Fri, 05 Apr 2013 11:55:09 +0900
changeset 2115 edb49073227e
parent 2114 fc1bc441cf71
child 2116 2b1980a038b1
Added error logging when SDO FB fails
etherlab/runtime_etherlab.py
--- a/etherlab/runtime_etherlab.py	Thu Apr 04 17:50:43 2013 +0900
+++ b/etherlab/runtime_etherlab.py	Fri Apr 05 11:55:09 2013 +0900
@@ -1,6 +1,7 @@
 import subprocess,sys,ctypes
 from threading import Thread
 import ctypes,time,re
+from targets.typemapping import LogLevelsDict
 
 SDOAnswered = PLCBinary.SDOAnswered
 SDOAnswered.restype = None
@@ -12,11 +13,12 @@
 def SDOThreadProc(*params):
     global Result
     if params[0] == "upload":
-        command = "ethercat upload -p %d -t %s 0x%.4x 0x%.2x"
+        cmdfmt = "ethercat upload -p %d -t %s 0x%.4x 0x%.2x"
     else:
-        command = "ethercat download -p %d -t %s 0x%.4x 0x%.2x %s"
+        cmdfmt = "ethercat download -p %d -t %s 0x%.4x 0x%.2x %s"
     
-    proc = subprocess.Popen(command % params[1:], stdout=subprocess.PIPE, shell=True)
+    command = cmdfmt % params[1:]
+    proc = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True)
     res = proc.wait()
     output = proc.communicate()[0]
     
@@ -35,6 +37,10 @@
         Result = res == 0
     
     SDOAnswered()
+    if res != 0 :
+        PLCObject.LogMessage(
+            LogLevelsDict["WARNING"], 
+            "%s : %s"%(command,output))
     
 def EthercatSDOUpload(pos, index, subindex, var_type):
     global SDOThread
@@ -89,4 +95,3 @@
     StopKMSGThread = True
     KMSGPollThread = None
 
-