Index: trunk/FACT++/src/fadctrl.cc
===================================================================
--- trunk/FACT++/src/fadctrl.cc	(revision 10874)
+++ trunk/FACT++/src/fadctrl.cc	(revision 10875)
@@ -380,4 +380,10 @@
     }
 
+    void CmdSetRunNumber(uint32_t num)
+    {
+        PostCmd(FAD::kCmdWriteRunNumberLSW, num&0xffff);
+        PostCmd(FAD::kCmdWriteRunNumberMSW, num>>16);
+    }
+
     void CmdSetRegister(uint8_t addr, uint16_t val)
     {
@@ -398,16 +404,18 @@
     bool CmdSetRoi(int8_t addr, uint16_t val)
     {
-        if (addr>FAD::kMaxRoiAddr)
-            return false;
-
         if (val>FAD::kMaxRoiValue)
             return false;
 
         if (addr<0)
-            for (int i=0; i<=FAD::kMaxRoiAddr; i++)
+        {
+            for (unsigned int i=0; i<=FAD::kMaxRoiAddr; i++)
                 PostCmd(FAD::kCmdWriteRoi + i, val);
-        else
-            PostCmd(FAD::kCmdWriteRoi + addr, val);
-
+            return true;
+        }
+
+        if (uint8_t(addr)>FAD::kMaxRoiAddr)
+            return false;
+
+        PostCmd(FAD::kCmdWriteRoi + addr, val);
         return true;
     }
@@ -732,4 +740,25 @@
     }
 
+    int SetRunNumber(const EventImp &evt)
+    {
+        if (!CheckEventSize(evt.GetSize(), "SetRunNumber", 8))
+            return T::kSM_FatalError;
+
+        const uint64_t num = evt.Get<uint64_t>();
+
+        if (num>FAD::kMaxRunNumber)
+        {
+            ostringstream msg;
+            msg << hex << "Value " << num << " out of range, max=" << FAD::kMaxRunNumber;
+            T::Error(msg);
+            return false;
+        }
+
+        for (BoardList::iterator i=fBoards.begin(); i!=fBoards.end(); i++)
+            i->second.second->CmdSetRunNumber(num);
+
+        return T::GetCurrentState();
+    }
+
     int Test(const EventImp &evt)
     {
@@ -750,5 +779,5 @@
 
         for (BoardList::iterator i=fBoards.begin(); i!=fBoards.end(); i++)
-            i->second.second->SetVerbose(evt.GetText()[0]!=0);
+            i->second.second->SetVerbose(evt.GetBool());
 
         return T::GetCurrentState();
@@ -761,5 +790,5 @@
 
         for (BoardList::iterator i=fBoards.begin(); i!=fBoards.end(); i++)
-            i->second.second->SetHexOutput(evt.GetText()[0]!=0);
+            i->second.second->SetHexOutput(evt.GetBool());
 
         return T::GetCurrentState();
@@ -772,5 +801,5 @@
 
        for (BoardList::iterator i=fBoards.begin(); i!=fBoards.end(); i++)
-            i->second.second->SetDataOutput(evt.GetText()[0]!=0);
+            i->second.second->SetDataOutput(evt.GetBool());
 
         return T::GetCurrentState();
@@ -1144,4 +1173,8 @@
             ("");
 
+        T::AddEvent("SET_RUN_NUMBER", "X:1")
+            (boost::bind(&StateMachineFAD::SetRunNumber, this, _1))
+            ("");
+
         T::AddEvent("SET_REGISTER", "I:2")
             (boost::bind(&StateMachineFAD::SetRegister, this, _1))
