Index: /trunk/MagicSoft/Cosy/candrv/nodedrv.cc
===================================================================
--- /trunk/MagicSoft/Cosy/candrv/nodedrv.cc	(revision 1803)
+++ /trunk/MagicSoft/Cosy/candrv/nodedrv.cc	(revision 1804)
@@ -154,5 +154,5 @@
 
     lout << hex << setfill('0');
-    lout << "Node #" << (int)fId << ": Sdo=" << idx  << "/" << (int)subidx << " set.";
+    lout << "Node #" << dec << (int)fId << ": Sdo=" << hex << idx  << "/" << (int)subidx << " set.";
     lout << endl;
 
@@ -500,4 +500,8 @@
     fTimeout->SetTime(fGuardTime);
     fTimeout->Reset();
+
+//    Timer t;
+//    fTimeoutTime = t.Now() + (fGuardTime*fLifeTimeFactor/1000.);
+
     fTimeout->TurnOn();
     //fTimeout->Start(fGuardTime, kTRUE);
@@ -576,4 +580,5 @@
     if (now > fTimeoutTime)
     {
+        cout << "==out==> " << fmod(now*1000, 10000)/10 << " > " << fmod(fTimeoutTime*10000, 10000)/10 << endl;
         //cout << "ERROR - " << GetNodeName() << " didn't respond in timeout window." << endl;
         //lout << "ERROR - " << GetNodeName() << " didn't respond in timeout window." << endl;
Index: /trunk/MagicSoft/Cosy/candrv/vmodican.cc
===================================================================
--- /trunk/MagicSoft/Cosy/candrv/vmodican.cc	(revision 1803)
+++ /trunk/MagicSoft/Cosy/candrv/vmodican.cc	(revision 1804)
@@ -147,7 +147,7 @@
         switch (c)
         {
-        //
-        // Fast message (not used/working)
-        //
+            //
+            // Fast message (not used/working)
+            //
         case FAST_QUEUE:
             cout << "--> Fast Queue:  " << flush;
Index: /trunk/MagicSoft/Cosy/devdrv/macs.cc
===================================================================
--- /trunk/MagicSoft/Cosy/devdrv/macs.cc	(revision 1803)
+++ /trunk/MagicSoft/Cosy/devdrv/macs.cc	(revision 1804)
@@ -31,5 +31,5 @@
     : NodeDrv(nodeid, name, out), fMacId(2*nodeid+1),
     fPos(0), fPosTime(0.0), fPdoPos(0), fPdoTime(0.0),
-    fPosActive(0), fRpmActive(0)
+    fPosActive(0), fRpmActive(0), fStatusPdo3(0xff)
 {
 //    fTimeout = new TTimer(this, 100); //, kFALSE); // 100ms, asynchronous
@@ -57,5 +57,5 @@
 
     case 0x2002:
-        cout << GetNodeName() << ": Actual velocity: " << dec << val << endl;
+        cout << GetNodeName() << ": Current velocity: " << dec << val << endl;
         fVel = val;
         return;
@@ -273,6 +273,6 @@
     SetNoWait(TRUE);
 
-    StartGuarding(100, 2);
-    StartHostGuarding();
+    //    StartGuarding(500, 2);
+    //    StartHostGuarding();
 }
 
@@ -300,7 +300,9 @@
     SetPDO1On(FALSE);
 
-    lout << "- " << GetNodeName() << ": Motor off." << endl;
-    SendSDO(0x3000, string('o', 'f', 'f'));
-    WaitForSdo(0x3000);
+    /*
+     lout << "- " << GetNodeName() << ": Motor off." << endl;
+     SendSDO(0x3000, string('o', 'f', 'f'));
+     WaitForSdo(0x3000);
+     */
 
     /*
@@ -550,4 +552,31 @@
 }
 
+void Macs::HandlePDO3(BYTE_t *data, timeval_t *tv)
+{
+    // 3    5    7    9
+    // 1100 1010 1110 1001
+    if (fStatusPdo3 == data[3])
+        return;
+
+    lout << GetNodeName() << ": Status PDO3 = ";
+    const Bool_t ready = data[3]&0x01;
+    const Bool_t fuse  = data[3]&0x02;
+    const Bool_t emcy  = data[3]&0x04;
+    const Bool_t vltg  = data[3]&0x08;
+    const Bool_t mode  = data[3]&0x10;
+    const Bool_t rf    = data[3]&0x20;
+    const Bool_t brake = data[3]&0x40;
+    if (ready) lout << "DKC-Ready ";
+    if (fuse)  lout << "FuseOk ";
+    if (emcy)  lout << "EmcyOk ";
+    if (vltg)  lout << "OvervoltOk ";
+    if (mode)  lout << "SwitchToManualMode ";
+    if (rf)    lout << "RF ";
+    if (brake) lout << "BrakeOpen ";
+    lout << endl;
+
+    fStatusPdo3 = data[3];
+}
+
 // FIXME? Handling of fIsZombie?
 void Macs::HandleError()
Index: /trunk/MagicSoft/Cosy/devdrv/macs.h
===================================================================
--- /trunk/MagicSoft/Cosy/devdrv/macs.h	(revision 1803)
+++ /trunk/MagicSoft/Cosy/devdrv/macs.h	(revision 1804)
@@ -28,8 +28,5 @@
     BYTE_t   fStatus;
 
-    LWORD_t string(BYTE_t b0=0, BYTE_t b1=0, BYTE_t b2=0, BYTE_t b3=0)
-    {
-        return (LWORD_t)(b0<<24 | b1<<16 | b2<<8 | b3);
-    }
+    BYTE_t   fStatusPdo3;
 
     void Init();
@@ -42,4 +39,5 @@
     void HandlePDO1(BYTE_t *data, timeval_t *tv);
     void HandlePDO2(BYTE_t *data, timeval_t *tv);
+    void HandlePDO3(BYTE_t *data, timeval_t *tv);
     //void HandleNodeguard(timeval_t *tv);
 
@@ -67,4 +65,9 @@
     Macs(const BYTE_t nodeid, const char *name=NULL, MLog &out=gLog);
     virtual ~Macs();
+
+    static LWORD_t string(BYTE_t b0=0, BYTE_t b1=0, BYTE_t b2=0, BYTE_t b3=0)
+    {
+        return (LWORD_t)(b0<<24 | b1<<16 | b2<<8 | b3);
+    }
 
     void SendMsg(BYTE_t data[6]);
Index: /trunk/MagicSoft/Cosy/devdrv/shaftencoder.cc
===================================================================
--- /trunk/MagicSoft/Cosy/devdrv/shaftencoder.cc	(revision 1803)
+++ /trunk/MagicSoft/Cosy/devdrv/shaftencoder.cc	(revision 1804)
@@ -252,4 +252,14 @@
 
     //
+    // Request Lifetimefactor for unknown reason to make guarding
+    // working in SE/Az... (FIXME)
+    //
+    //    lout << "- " << GetNodeName() << ": Requesting Lifetimefactor (Workaround, FIXME!) (SDO 0x100d)." << endl;
+    //    RequestSDO(0x100c);
+    //    WaitForSdo(0x100c);
+    //    RequestSDO(0x100d);
+    //    WaitForSdo(0x100d);
+
+    //
     // Set logic ticks/revolution = physical ticks/revolution => scale factor = 1
     //
@@ -291,5 +301,14 @@
     SendNMT(kNMT_START);
 
-    StartGuarding(175, 2);
+    /*
+     cout << "---1---" << endl;
+     MTimeout t(1000);
+     while (!t.HasTimedOut())
+      usleep(1);
+     cout << "---2---" << endl;
+     */
+
+    //    StartGuarding(175, 2); // 175
+    // StartGuarding(10*GetId(), 2); // 175
 }
 
Index: /trunk/MagicSoft/Cosy/gui/MGEmbeddedCanvas.cc
===================================================================
--- /trunk/MagicSoft/Cosy/gui/MGEmbeddedCanvas.cc	(revision 1803)
+++ /trunk/MagicSoft/Cosy/gui/MGEmbeddedCanvas.cc	(revision 1804)
@@ -52,4 +52,25 @@
 }
 
+void MGEmbeddedCanvas::Resize(TGDimension size)
+{
+    fWidth = size.fWidth;
+    fPix = 2.*fRange/size.fWidth;
+    TRootEmbeddedCanvas::Resize(size);
+}
+
+void MGEmbeddedCanvas::Resize(UInt_t w, UInt_t h)
+{
+    fWidth = w;
+    fPix = 2.*fRange/w;
+    TRootEmbeddedCanvas::Resize(w, h);
+}
+
+void MGEmbeddedCanvas::MoveResize(Int_t x, Int_t y, UInt_t w, UInt_t h)
+{
+    fWidth = w;
+    fPix = 2.*fRange/w;
+    TRootEmbeddedCanvas::MoveResize(x, y, w, h);
+}
+
 // ------------------------------------------------------------------------
 //
Index: /trunk/MagicSoft/Cosy/gui/MGEmbeddedCanvas.h
===================================================================
--- /trunk/MagicSoft/Cosy/gui/MGEmbeddedCanvas.h	(revision 1803)
+++ /trunk/MagicSoft/Cosy/gui/MGEmbeddedCanvas.h	(revision 1804)
@@ -37,4 +37,8 @@
     ~MGEmbeddedCanvas();
 
+    void Resize(TGDimension size);
+    void Resize(UInt_t w, UInt_t h);
+    void MoveResize(Int_t x, Int_t y, UInt_t w, UInt_t h);
+
     void UpdateCanvas();
 
Index: /trunk/MagicSoft/Cosy/gui/MGSkyPosition.cc
===================================================================
--- /trunk/MagicSoft/Cosy/gui/MGSkyPosition.cc	(revision 1803)
+++ /trunk/MagicSoft/Cosy/gui/MGSkyPosition.cc	(revision 1804)
@@ -262,26 +262,5 @@
     float y = c*zdaz.Zd()*kRad2Deg;             // [deg]
 
-    if (x>95 || x<-95 || y>95 || y<-95)
-    {
-        if (arc->GetX1()==10 && arc->GetY1()==100)
-            return;
-
-        x=-100;
-        y= 100;
-    }
-
-    const int pixx = (int)(x/fPix);
-    const int pixy = (int)(y/fPix);
-
-    const int oldx = (int)(arc->GetX1()/fPix);
-    const int oldy = (int)(arc->GetY1()/fPix);
-
-    if (pixx==oldx && pixy==oldy)
-        return;
-
-    arc->SetX1(x);
-    arc->SetY1(y);
-
-    SetModified(); //***MEMORY LEAK!!!***
+    SetDotRange(arc, x, y);
 }
 
@@ -393,4 +372,32 @@
 }
 
+bool MGSkyPosition::SetDotRange(TArc *arc, float &x, float &y)
+{
+    if (!(x>-95 && x<95 && y>-95 && y<95))
+    {
+        if (arc->GetX1()==-100 && arc->GetY1()==100)
+            return false;
+
+        x=-100;
+        y= 100;
+    }
+
+    const int pixx = (int)(x/fPix);
+    const int pixy = (int)(y/fPix);
+
+    const int oldx = (int)(arc->GetX1()/fPix);
+    const int oldy = (int)(arc->GetY1()/fPix);
+
+    if (pixx==oldx && pixy==oldy)
+        return false;
+
+    arc->SetX1(x);
+    arc->SetY1(y);
+
+    SetModified(); 
+
+    return true;
+}
+
 void MGSkyPosition::UpdatePlanet(Int_t planet, TArc *arc)
 {
@@ -400,5 +407,5 @@
     fSlaPlanet->UpdatePlanetPos((ePlanets_t)planet);
 
-    ZdAz zdaz = fSlaPlanet->GetPlanetPos((ePlanets_t)planet);
+    const ZdAz zdaz = fSlaPlanet->GetPlanetPos((ePlanets_t)planet);
 
     //
@@ -413,29 +420,6 @@
     float y = c*deg;
 
-    if (x>95 || x<-95 || y>95 || y<-95)
-    {
-        if (arc->GetX1()==10 && arc->GetY1()==100)
-            return;
-
-        x=-100;
-        y= 100;
-    }
-
-    const int pixx = (int)(x/fPix);
-    const int pixy = (int)(y/fPix);
-
-    const int oldx = (int)(arc->GetX1()/fPix);
-    const int oldy = (int)(arc->GetY1()/fPix);
-
-    if (oldx==pixx && oldy==pixy)
+    if (!SetDotRange(arc, x, y))
         return;
-
-    //
-    // Set new position
-    //
-    arc->SetX1(x);
-    arc->SetY1(y);
-
-    SetModified();
 
     if (planet==kESaturn)
Index: /trunk/MagicSoft/Cosy/gui/MGSkyPosition.h
===================================================================
--- /trunk/MagicSoft/Cosy/gui/MGSkyPosition.h	(revision 1803)
+++ /trunk/MagicSoft/Cosy/gui/MGSkyPosition.h	(revision 1804)
@@ -54,9 +54,5 @@
     const MObservatory::LocationName_t fObservatory;
 
-//    Int_t fStarX[13];
-//    Int_t fStarY[13];
-
-//    Int_t fPlanetX[9];
-//    Int_t fPlanetY[9];
+    bool SetDotRange(TArc *arc, float &x, float &y);
 
     void InitArc(TArc *arc, Int_t fillstyle, Int_t fillcolor, Int_t linecolor);
Index: /trunk/MagicSoft/Cosy/gui/MGStarguider.cc
===================================================================
--- /trunk/MagicSoft/Cosy/gui/MGStarguider.cc	(revision 1803)
+++ /trunk/MagicSoft/Cosy/gui/MGStarguider.cc	(revision 1804)
@@ -77,5 +77,4 @@
     gVirtualX->GrabButton(fId, kButton2, 0, 0, 0, 0, kTRUE);
 
-
     fList = new MGList;
 
@@ -188,5 +187,5 @@
     fList->Add(fCZdAz);
 
-    const Double_t pixsize = 23.4;
+    const Double_t pixsize = 23.5;
 
     fSao->SetPixSize(pixsize/3600);
@@ -555,4 +554,18 @@
 void MGStarguider::ProcessFrame(const unsigned long n, byte *img, struct timeval *tm)
 {
+    static float myimg[768*576];
+
+    for (int i=0; i<768*576; i++)
+        myimg[i] += img[i];
+
+    if (n%fIntRate)
+        return;
+
+    cout << "Img: " << n << endl;
+
+    byte c[768*576];
+    for (int i=0; i<768*576; i++)
+        c[i] = (byte)(myimg[i]/fIntRate+.5);
+
     if (!fWrite->IsEntryEnabled(IDM_kStart) &&
         (!(n%fWrtRate) || fWriteType->IsEntryChecked(IDM_kOnce)))
@@ -563,5 +576,5 @@
             char name[80];
             sprintf(name, "pix/file%04d.png", num++);
-            Writer::Png(name, img, tm);
+            Writer::Png(name, c, tm);
         }
 
@@ -571,5 +584,5 @@
             char name[80];
             sprintf(name, "pix/file%04d.ppm", num++);
-            Writer::Ppm(name, img);
+            Writer::Ppm(name, c);
         }
 
@@ -578,17 +591,4 @@
     }
 
-    static float myimg[768*576];
-
-    for (int i=0; i<768*576; i++)
-        myimg[i] += img[i];
-
-    if (n%fIntRate)
-        return;
-
-    cout << "Img: " << n << endl;
-
-    byte c[768*576];
-    for (int i=0; i<768*576; i++)
-        c[i] = (byte)(myimg[i]/fIntRate+.5);
 
     MStarList spots;
Index: /trunk/MagicSoft/Cosy/videodev/PngReader.cc
===================================================================
--- /trunk/MagicSoft/Cosy/videodev/PngReader.cc	(revision 1803)
+++ /trunk/MagicSoft/Cosy/videodev/PngReader.cc	(revision 1804)
@@ -94,5 +94,4 @@
     // Write bitmap data
     //
-    static int first = 0;
     for (unsigned int y=0; y<576; y++)
         for (unsigned int x=0; x<768; x++)
Index: /trunk/MagicSoft/Cosy/videodev/Writer.cc
===================================================================
--- /trunk/MagicSoft/Cosy/videodev/Writer.cc	(revision 1803)
+++ /trunk/MagicSoft/Cosy/videodev/Writer.cc	(revision 1804)
@@ -21,5 +21,8 @@
     FILE *fd = fopen(fname, "w");
     if (!fd)
+    {
+        cout << "Warning: Cannot open file for writing." << endl;
         return;
+    }
 
     //
@@ -78,4 +81,5 @@
     // Write Time Chunks
     //
+    /*
     if (date)
     {
@@ -87,5 +91,6 @@
         sprintf(text,"*** %s %s %.1f %i ***", tzname[0], tzname[1], 1.0/3600*timezone, daylight);
         png_write_chunk(fPng, (png_byte*)"ZONE", (png_byte*)text, strlen(text));
-    }
+        }
+        */
 
     //
@@ -117,5 +122,8 @@
     ofstream fout(fname);
     if (!fout)
+    {
+        cout << "Warning: Cannot open file for writing." << endl;
         return;
+    }
 
     //
