Permalink
Browse files

add exposure control and channel switching

  • Loading branch information...
1 parent 0b4fde7 commit d456c653dd281ac80679ac6d523a4dd9c4ce78a8 @imrehg committed May 9, 2012
Showing with 62 additions and 6 deletions.
  1. +33 −5 client/wavemeter.py
  2. +29 −1 views/dashboard.ejs
View
@@ -10,6 +10,7 @@
from socketIO import SocketIO
import logging
import os
+import serial
try:
import simplejson as json
@@ -26,15 +27,31 @@
settingsQ = mp.Queue()
readingsQ = mp.Queue()
+class Switcher(object):
+
+ def __init__(self, port):
+ self.ser = serial.Serial(port,
+ 115200,
+ timeout=1,
+ parity=serial.PARITY_NONE,
+ bytesize=8,
+ stopbits=1,
+ xonxoff=1)
+ self.terminator = ""
+
+ def setChannel(self, i):
+ self.ser.write("%d%s" %(i, self.terminator))
+
class RemoteClient(asyncore.dispatcher):
- def __init__(self, host, path, rQ, sQ):
+ def __init__(self, host, path, rQ, sQ, switch):
asyncore.dispatcher.__init__(self)
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
self.connect(('localhost', 3000)) # needs it on windows otherwise doesn't write
self.mysocket = SocketIO('localhost', 3000)
self.rQ = rQ
self.sQ = sQ
+ self.switch = switch
def handle_connect(self):
logger.debug("RC connected")
@@ -111,17 +128,28 @@ def run(self):
i = int(ch['num'])
t1 = int(ch['t1'])
t2 = int(ch['t2'])
- totalt = (t1 + t2 + 10) / 1000.0
- print "Totalt", totalt
- # do setup
+ # have to add some extra delay of there are switching involved
+ # especially if there's a big difference in the exposure times
+ # the optimal value depends on: number of channels, current and
+ # previous channel exposure time, and probably other things
+ tdelay = 50 # ms
+ totalt = (t1 + t2 + tdelay) / 1000.0
wmdriver.SetExposure((t1, t2))
+ switch.setChannel(i-1) # Channel number goes from 0
+ # wmdriver.SetExposure((t1, t2))
+ xt1, xt2 = wmdriver.GetExposure()
+ logger.info("Setting: %d / %d || %d / %d" %(t1, xt1, t2, xt2))
+ if (t1 != xt1) | (t2 != xt2):
+ logger.info("Exposure setting failed? %d / %d || %d / %d" %(t1, xt1, t2, xt2))
sleep(totalt) # wait
self.vals[i] = wmdriver.GetFrequency()
+ logger.debug("Channel %d: measured %f" %(i, self.vals[i]))
timestamp = time()
self.rQ.put({"wavelength" : { "channel": i, "value": self.vals[i], "timestamp": timestamp}})
self.done.wait(self.interval)
-client = RemoteClient('www.python.org', '/', readingsQ, settingsQ)
+switch = Switcher("COM3")
+client = RemoteClient('www.python.org', '/', readingsQ, settingsQ, switch)
wavemeterThread = Wavemeter(0.0, settingsQ, readingsQ)
wavemeterThread.start()
View
@@ -30,6 +30,29 @@
$("document").ready(function() {
$(".wavedisplay").hide();
$(".btnchn").button();
+ $(".tslider").slider({
+ value: 3,
+ min: 1,
+ max: 100,
+ slide: function( event, ui ) {
+ var id = $(this).attr('id');
+ var chn = id.slice(7,id.length+1);
+ var value = ui.value;
+ $( "#tval"+chn ).val( value );
+ },
+ stop: function( event, ui ) {
+ var charray = channels.toArray();
+ var settings = new Array();
+ channels.forEach(function(e) {
+ var t = $('#tslider'+e).slider("value");
+ settings.push({"num": e, "t1": t, "t2": t});
+ });
+ socket.emit("message", {"settings": settings});
+ }
+ });
+ for(i=1; i <= <%= channels %>; i++) {
+ $( "#tval"+i ).val( $("#tslider"+i).slider("value") );
+ }
$(".btnchn").click(function() {
var turnon = false;
if ($(this).is(':checked')) {
@@ -61,11 +84,14 @@
console.log("Settings", data);
for(i=0; i< data.length; i++) {
var num = data[i].num;
+ var t = data[i].t1;
channels.add(num);
channelToggle(num, true);
$('#btncn'+num).prop("checked", true);
console.log($('#btncn'+num).prop("checked"));
console.log("CheckState", $('#btncn'+num).is(':checked'));
+ $('#tslider'+num).slider({ value: t });
+ $('#tval'+num).val(t);
}
});
@@ -82,9 +108,11 @@
<h2>Wavemeter channels</h2>
<% for (var c = 1; c <= channels; c++) { %>
- <div id="channel<%= c %>" style="border: solid 0px; height: 100px">
+ <div id="channel<%= c %>" style="border: solid 0px; height: 130px">
<input type="checkbox" id="btnchn<%= c %>" class="btnchn"/><label for="btnchn<%= c %>">Channel <%= c %></label>
<div class="wavedisplay" id="wavedisplay<%= c %>">
+ <input type="text" id="tval<%= c %>" style="border:0; color:#f6931f; font-weight:bold;" />
+ <div class="tslider" id="tslider<%= c %>"></div>
<span class="wavetext" id="wavetext<%= c %>">No data yet....</span>
</div>
</div>

0 comments on commit d456c65

Please sign in to comment.