# HG changeset patch
# User Edouard Tisserant
# Date 1365130509 -32400
# Node ID edb49073227ec4c4222772e2aab67cedf4ea598b
# Parent  fc1bc441cf71d5007bcc62100203961ff01713dc
Added error logging when SDO FB fails

diff -r fc1bc441cf71 -r edb49073227e 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
 
-