                      (clock-ms))]
     (when (pos? sleep-time)
       (Thread/sleep sleep-time)))
-  (clock-ms))
+  (clock-ms)) 
+ 
+(def device-agents
+  (let [devs (seq (. mmc getLoadedDevices))]
+    (zipmap devs (repeatedly (count devs) #(agent nil)))))
+
+(defn set-stage-position
+  ([stage-dev z] (. mmc setPosition stage-dev z))
+  ([stage-dev x y] (. mmc setXYPosition stage-dev x y)))
+
+(defn set-property
+  ([dev prop] (. mmc setProperty (prop 0) (prop 1) (prop 2))))
   
-(defn wait-for-devices [event]
-  (. mmc waitForDevice (. mmc getFocusDevice))
-  ;; more
-  )
+(defn send-device-action [dev action]
+  (send-off (device-agents dev) (fn [_] (action))))
+    
+(defn create-presnap-actions [event]
+  (into {} (concat
+    (for [[axis pos] (get-in event [:position :axes])]
+      [axis #(apply set-stage-position axis pos)])
+    (for [prop (get-in event [:channel :properties])]
+      [(prop 0) #(.setProperty mmc (prop 0) (prop 1) (prop 2))]))))
+
+(defn run-actions [action-map]
+  (doseq [[dev action] action-map]
+    (send-device-action dev action))
+  (doseq [dev (keys action-map)]
+    (send-device-action dev #(. mmc waitForDevice dev)))
+  (doall (map (partial await-for 10000) (vals device-agents))))
+
+(defn snap-image [open-before close-after]
+  (if open-before
+    (. mmc setShutterOpen true)
+    (. mmc waitForDevice (. mmc getShutterDevice)))
+  (. mmc snapImage)
+  (if close-after
+    (. mmc setShutterOpen false))
+    (. mmc waitForDevice (. mmc getShutterDevice)))
+
+(defn collect-image [event]
+  (. mmc getImage))
   
-(defn run-event [event last-wake-time]
-  (update-channel event)
-  (update-position event)
-  (let [new-wake-time (acq-sleep event last-wake-time)]
-    (run-autofocus event)
-    (update-slice event)
-    (wait-for-devices event)
-    (snap-image event)
-    new-wake-time))
-
-(defn run-events [events]
-  (doall (map run-event events)))
+(defn run-event [event]
+  (run-actions (create-presnap-actions event))
+  (await-for 10000 (device-agents (. mmc getCameraDevice)))
+  (snap-image true true)
+  (send-device-action (. mmc getCameraDevice) #(collect-image event)))
   
 (defn run-acquisition [settings] 
   (def acq-settings settings)
   (let [acq-seq (generate-acq-sequence settings)]
      (def acq-sequence acq-seq)
-     (doall (map println acq-seq))))
+     (map run-event acq-seq)))
   
 (defn convert-settings [^SequenceSettings settings]
   (-> settings
     (data-object-to-map)
-    (assoc :frames (range (.numFrames settings))
-           :channels (filter :use-channel (map ChannelSpec-to-map (.channels settings)))
-           :positions (map MultiStagePosition-to-map (.positions settings)))
     (rekey
       :slicesFirst             :slices-first
       :timeFirst               :time-first

(defn test-dialog [eng]
  (.show (AcqControlDlg. eng (Preferences/userNodeForPackage (.getClass gui)) gui)))

   

   
      :skipAutofocusCount      :autofocus-skip
      :relativeZSlice          :relative-slices
      :intervalMs              :interval-ms
      :slices                  :slices
    )
    (assoc :frames (range (.numFrames settings))
           :channels (filter :use-channel (map ChannelSpec-to-map (.channels settings)))
           :positions (map MultiStagePosition-to-map (.positions settings)))))

(defn run-acquisition-from-settings [^SequenceSettings settings]
  (println settings)
  (def orig-settings settings)
  (println (run-acquisition (convert-settings settings))))

(defn create-acq-eng []
  (doto
