Index: /trunk/FACT++/src/RemoteControl.h
===================================================================
--- /trunk/FACT++/src/RemoteControl.h	(revision 14553)
+++ /trunk/FACT++/src/RemoteControl.h	(revision 14554)
@@ -23,4 +23,5 @@
 {
 protected:
+    std::ostream &lin;           /// Output stream for local synchrounous output
     std::ostream &lout;          /// Output stream for local synchrounous output
 
@@ -29,5 +30,5 @@
 protected:
     // Redirect asynchronous output to the output window
-    RemoteControlImp(std::ostream &, std::ostream &in) : lout(in)
+    RemoteControlImp(std::ostream &out, std::ostream &in) : lin(out), lout(in)
     {
     }
@@ -165,5 +166,5 @@
     virtual void  JsEnd(const std::string &)          { UnsubscribeAll(); SetSection(-3); }
     virtual bool  JsSend(const std::string &str)      { return ProcessCommand(str); }
-    virtual void  JsOut(const std::string &msg)       { lout << msg << endl; }
+    virtual void  JsOut(const std::string &msg)       { lin << msg << endl; }
     virtual void  JsPrint(const std::string &msg)     { if (fImp) fImp->Comment(msg.empty()?" ":msg); }
     virtual void  JsAlarm(const std::string &msg)     { if (fImp) fImp->Alarm(msg.empty()?" ":msg); }
@@ -413,5 +414,9 @@
 
             T::fScript = opt;
+
+            T::Lock();
             JsRun(opt, data);
+            T::Unlock();
+
             return true;
         }
@@ -431,5 +436,7 @@
             }
 
+            T::Lock();
             const int rc = JsWait(server, state, ms);
+            T::Unlock();
 
             if (rc<0 || rc==1)
@@ -476,5 +483,9 @@
     }
 
-    void SetReceiver(StateMachineDimControl &imp) { fImp = &imp; }
+    void SetReceiver(StateMachineDimControl &imp)
+    {
+        fImp = &imp;
+        fImp->SetStateCallback(bind(&InterpreterV8::JsHandleState, this, placeholders::_1, placeholders::_2));
+    }
 };
 
