Index: branches/FACT++_lidctrl_usb/src/lidctrl.cc
===================================================================
--- branches/FACT++_lidctrl_usb/src/lidctrl.cc	(revision 18717)
+++ branches/FACT++_lidctrl_usb/src/lidctrl.cc	(revision 18718)
@@ -1,5 +1,5 @@
 #include <functional>
-
 #include <boost/bind.hpp>
+#include <cstdlib>
 
 #include "Dim.h"
@@ -30,6 +30,7 @@
 class ConnectionLid : public ConnectionUSB
 {
-    vector<uint8_t> fRecievedBytes;
-    DimDescribedService fDimLid;
+    vector<char> fRecievedBytes;
+
+    State::states_t state;
 private:
 
@@ -37,7 +38,20 @@
     void HandleReceivedData(const boost::system::error_code&, size_t bytes_received, int type, int counter)
     {
-        Out() << fRecievedBytes;
-        AsyncRead(ba::buffer(fRecievedBytes, 100), 0, 0);
-
+        string search_string("system_state=");
+        string s(fRecievedBytes.begin(), fRecievedBytes.end());
+        Out() << s << endl << endl;
+        int pos=s.find(search_string);
+        string part = s.substr(pos + search_string.size(), 1);
+        int state_number = atoi(part.c_str());        
+        Out() << "system state = " << state_number << endl;
+        if (state_number == 0)
+        {
+            state = State::kClosed;
+        }
+        if (state_number == 4)
+        {
+            state = State::kOpen;
+        }
+        AsyncRead(ba::buffer(fRecievedBytes, 1024), 0, 0);
     }
 
@@ -46,5 +60,5 @@
     void ConnectionEstablished()
     {
-        AsyncRead(ba::buffer(fRecievedBytes, 100), 0, 0);
+        AsyncRead(ba::buffer(fRecievedBytes, 1024), 0, 0);
     }
 
@@ -54,5 +68,5 @@
         ConnectionUSB(ioservice, imp()),
         fRecievedBytes(1024),
-        fDimLid("LID_CTRL_USB/STUFF", "S:1","|Stuff[foo]:some text.")
+        state(State::kOpen)
     {
         SetLogStream(&imp);
@@ -61,5 +75,5 @@
     State::states_t GetStatus()
     {
-        return State::kOpen;
+        return state;
     }
 };
@@ -95,22 +109,22 @@
     S fLid;
 
-    int Disconnect()
-    {
-        fLid.PostClose(-1);
+    int Execute()
+    {
+        return fLid.GetStatus();
+    }
+
+
+    int Open()
+    {
+        std::array<char, 1> cmd = {{'o'}};
+        fLid.PostMessage(cmd);
         return T::GetCurrentState();
     }
-
-    int Reconnect(const EventImp &evt)
-    {
-        fLid.PostClose(-1);
-        ba::io_service::poll();
-        fLid.PostClose(0);
+    
+    int Close()
+    {
+        std::array<char, 1> cmd = {{'c'}};
+        fLid.PostMessage(cmd);
         return T::GetCurrentState();
-    }
-
-    int Execute()
-    {
-        const int state = fLid.GetStatus();
-        return state;
     }
 
@@ -156,5 +170,5 @@
     control.add_options()
         ("no-dim,d",        po_bool(),  "Disable dim services")
-        ("dev",             var<string>(),       "Device address of USB port to lid-arduino")
+        ("dev",             var<string>("lid-arduino"),       "Device address of USB port to lid-arduino")
         ("quiet,q",         po_bool(true),       "Disable printing contents of all received messages (except dynamic data) in clear text.")
         ;
