Index: trunk/MagicSoft/Cosy/candrv/canopen.cc
===================================================================
--- trunk/MagicSoft/Cosy/candrv/canopen.cc	(revision 808)
+++ trunk/MagicSoft/Cosy/candrv/canopen.cc	(revision 909)
@@ -223,5 +223,5 @@
 }
 
-WORD_t CanOpen::CobId(BYTE_t node, BYTE_t fcode)
+WORD_t CanOpen::CobId(BYTE_t node, BYTE_t fcode) const
 {
     return (fcode<<7) | node&0x1f;
Index: trunk/MagicSoft/Cosy/candrv/network.cc
===================================================================
--- trunk/MagicSoft/Cosy/candrv/network.cc	(revision 808)
+++ trunk/MagicSoft/Cosy/candrv/network.cc	(revision 909)
@@ -6,12 +6,18 @@
 void Network::Start()
 {
-    StartReceiver();
+    lout << "- Starting network." << endl;
+
+    VmodIcan::Start();
     InitNodes();
+
+    lout << "- Network started." << endl;
 }
 
 void Network::Stop()
 {
+    lout << "- Stopping network." << endl;
+
     StopNodes();
-    StopReceiver();
+    VmodIcan::Stop();
 
     lout << "- Network stopped." << endl;
@@ -166,5 +172,5 @@
 }
 
-bool Network::HasError()
+bool Network::HasError() const
 {
     for (int i=0; i<32; i++)
Index: trunk/MagicSoft/Cosy/candrv/network.h
===================================================================
--- trunk/MagicSoft/Cosy/candrv/network.h	(revision 808)
+++ trunk/MagicSoft/Cosy/candrv/network.h	(revision 909)
@@ -31,5 +31,5 @@
     virtual void Stop();
 
-    bool HasError();
+    bool HasError() const;
 };
 
Index: trunk/MagicSoft/Cosy/candrv/nodedrv.cc
===================================================================
--- trunk/MagicSoft/Cosy/candrv/nodedrv.cc	(revision 808)
+++ trunk/MagicSoft/Cosy/candrv/nodedrv.cc	(revision 909)
@@ -116,10 +116,10 @@
 }
 
-void NodeDrv::WaitForSdo(WORD_t idx, BYTE_t subidx)
+void NodeDrv::WaitForSdo(WORD_t idx, BYTE_t subidx, WORD_t timeout)
 {
-    while (fNetwork->WaitingForSdo(fId, idx, subidx))
-        usleep(1);
+    fNetwork->WaitForSdo(fId, idx, subidx, timeout);
 }
 
+/*
 void NodeDrv::WaitForSdos()
 {
@@ -127,4 +127,5 @@
         usleep(1);
 }
+*/
 
 void NodeDrv::WaitForNextPdo1()
Index: trunk/MagicSoft/Cosy/candrv/nodedrv.h
===================================================================
--- trunk/MagicSoft/Cosy/candrv/nodedrv.h	(revision 808)
+++ trunk/MagicSoft/Cosy/candrv/nodedrv.h	(revision 909)
@@ -29,5 +29,5 @@
     virtual void StopDevice() = 0;
 
-    bool HasError()        { return fError; }
+    bool HasError()       { return fError; }
 
     virtual void HandleSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, struct timeval *tv);
@@ -64,6 +64,6 @@
     void WaitForNextPdo4();
 
-    void WaitForSdos();
-    void WaitForSdo(WORD_t idx, BYTE_t subidx=0);
+    // void WaitForSdos();
+    void WaitForSdo(WORD_t idx, BYTE_t subidx=0, WORD_t timeout=500);
 
     void EnableCanMsg(BYTE_t fcode);
Index: trunk/MagicSoft/Cosy/candrv/sdolist.cc
===================================================================
--- trunk/MagicSoft/Cosy/candrv/sdolist.cc	(revision 808)
+++ trunk/MagicSoft/Cosy/candrv/sdolist.cc	(revision 909)
@@ -86,5 +86,5 @@
 }
 
-int PendingSDOList::IsPending()
+int PendingSDOList::IsPending() const
 {
     return (int)fFirst->Next;
Index: trunk/MagicSoft/Cosy/candrv/sdolist.h
===================================================================
--- trunk/MagicSoft/Cosy/candrv/sdolist.h	(revision 808)
+++ trunk/MagicSoft/Cosy/candrv/sdolist.h	(revision 909)
@@ -34,5 +34,5 @@
     void DelAll();
 
-    int IsPending();
+    int IsPending() const;
     int IsPending(BYTE_t node);
     int IsPending(BYTE_t node, WORD_t idx, BYTE_t subidx);
Index: trunk/MagicSoft/Cosy/candrv/vmodican.cc
===================================================================
--- trunk/MagicSoft/Cosy/candrv/vmodican.cc	(revision 808)
+++ trunk/MagicSoft/Cosy/candrv/vmodican.cc	(revision 909)
@@ -52,14 +52,7 @@
 }
 
-void *VmodIcan::ReceiveThread(void *data)
-{
-    VmodIcan *cal = (VmodIcan*)data;
-
-    cal->lout << "- Starting Receiver Loop." << endl;
-
-    //
-    // set higher priority to make sure that no messages are lost.
-    //
-    setpriority(PRIO_PROCESS, 0, -10);
+void *VmodIcan::Thread()
+{
+    lout << "- Starting Receiver Loop." << endl;
 
     while (1)
@@ -70,5 +63,5 @@
         //cout << "waiting..." << endl;
 
-        const int n = read(cal->fd, &c, 1); // sleep until message arrive
+        const int n = read(fd, &c, 1); // sleep until message arrive
 
         gettimeofday(&tv, NULL);
@@ -89,5 +82,5 @@
             FastMessage fmsg;
 
-            if (cal->ReceiveFast(&fmsg) < 0)
+            if (ReceiveFast(&fmsg) < 0)
                 return (void *)1;
 
@@ -105,14 +98,14 @@
             Message msg;
 
-            if (cal->Receive(&msg) < 0)
+            if (Receive(&msg) < 0)
                 return (void *)1;
 
             //cal->PrintMsg(&msg);
-            cal->HandleMessage(&msg, &tv);
+            HandleMessage(&msg, &tv);
 
             break;
         }
-
     }
+    return NULL;
 }
 
@@ -765,6 +758,12 @@
 }
 
-VmodIcan::VmodIcan(const char *dev, const int baud, ostream &out) : Log(out), fRxThrd(NULL)//: CanDriver(dev, baud)
-{
+VmodIcan::VmodIcan(const char *dev, const int baud, ostream &out) : Log(out), MThread(false)//: CanDriver(dev, baud)
+{
+    //
+    // Set priority of receiving thread and detach the receiving thread
+    //
+    SetPriority(-10);
+    Detach();
+
     Open(dev);                         // open module
     Reset();
@@ -782,5 +781,5 @@
 VmodIcan::~VmodIcan()
 {
-    StopReceiver();
+    Stop();
     DisableCanBusConnection();
     Close();
@@ -794,5 +793,5 @@
     SendCanFrame(cobid, msg);
 }
-
+/*
 void VmodIcan::StopReceiver()
 {
@@ -804,12 +803,14 @@
     delete fRxThrd;
     fRxThrd = NULL;
-
     lout << "- Receiver Thread stopped." << endl;
 }
+*/
+
+/*
 void VmodIcan::StartReceiver()
 {
-    //**************************************
-    //* create thread waiting for messages *
-    //**************************************
+    **************************************
+    * create thread waiting for messages *
+    **************************************
     if (fRxThrd)
     {
@@ -823,3 +824,4 @@
     pthread_create(fRxThrd, NULL, ReceiveThread, this);
 }
-
+*/
+
Index: trunk/MagicSoft/Cosy/candrv/vmodican.h
===================================================================
--- trunk/MagicSoft/Cosy/candrv/vmodican.h	(revision 808)
+++ trunk/MagicSoft/Cosy/candrv/vmodican.h	(revision 909)
@@ -9,13 +9,32 @@
 #include "gendef.h"
 
-class VmodIcan : public Log
+#include "MThread.h"
+/*
+class VmodIcanRX : public MThread
 {
 private:
+    VmodIcan *fModule;
+
+    void *Thread();
+
+public:
+    MTGui(VmodIcan *mod) : MThread(false), fModule(mod)
+    {
+        SetPriority(-10);
+        Detach();
+    }
+};
+*/
+class VmodIcan : public Log, protected MThread
+{
+    friend class VmodIcanRX;
+
+private:
     int fd; // file descriptor for can module
-    pthread_t *fRxThrd;
+    //    pthread_t *fRxThrd;
 
     int Ioctl(int msg, void *arg);
 
-    static void *ReceiveThread(void *data);
+    void *Thread();
 
     void HandleMessage(Message *msg, struct timeval *tv);
@@ -52,7 +71,7 @@
     virtual void TerminateApp() { exit(-1); }
 
-protected:
-    void StartReceiver();
-    void StopReceiver();
+//protected:
+//    void StartReceiver();
+//    void StopReceiver();
 
 public:
