# 接続確立時の処理
ws.onopen do
puts "WebSocket connection open"
- ws.send("init")
end
# メッセージ受信時の処理
- ws.onmessage do |message|
+ ws.onmessage do |recBuf|
+ puts recBuf
+ puts recBuf.type
+
if(message=="acq")
# 画像配列の取得
result = @@vem.acquisition
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script src="img.js"></script>
<canvas id="test" width="256" height="256"></canvas>
+ <button>start</button>
</body>
</html>
-var ws = new WebSocket("ws://192.168.4.145:3000");
-var i = 0;
+var ws // WebSocket
+var i = 0; // 画像取得回数カウント用
+
+
+$( function(){
+ $( "button" ).toggle( startAcq, stopAcq );
+} );
+
+
+function startAcq(){
+ $( "button" ).text( "stop" );
+
+ // サーバーとWebSocket接続
+ ws = new WebSocket( "ws://192.168.4.145:3000" );
+
+ // メッセージ受信時の処理
+ ws.onmessage = function( event ){
+ if( event.data = "init" ){
+ ws.send( "acq" );
+ }else{
+ ws.send( "acq" );
+ draw( JSON.parse(event.data) );
+ console.log(i);
+ i = i + 1;
+ }
+ }
+
+}
+
+
+function stopAcq(){
+ $( "button" ).text( "start" );
+
+ // サーバーとの通信を切断
+ ws.close( 1000, "close");
+
+ console.log("stop");
+}
+
function draw(data){
var ctx;
// CanvasのコンテキストにImageDataを設定
ctx.putImageData(imgData, 0, 0);
}
-
-// メッセージ受信時の処理
-ws.onmessage = function(event){
- if(event.data=="init"){
- ws.send("acq")
- }else{
- ws.send("acq");
- draw(event.data);
- console.log(i);
- i = i + 1;
- }
-};
-
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script src="img.js"></script>
+
<canvas id="test" width="512" height="512"></canvas>
- <button>start</button>
+
+ <select id="size" name="size">
+ <option value="0">full</option>
+ <option value="1">half</option>
+ <option value="2">quarter</option>
+ </select>
+
+ <select id="binning" name="binning">
+ <option value="1">1</option>
+ <option value="2">2</option>
+ <option value="4">4</option>
+ </select>
+
+ <button id="acqButton">start</button>
</body>
</html>
-var ws // WebSocket
-var i = 0; // 画像取得回数カウント用
+var ws // WebSocket
+var i = 0; // 画像取得回数カウント用
+var settings = {
+ size : 0, // 画像サイズ
+ binning : 1 // ビニング
+};
+var sendBuf = {
+ "type" : 0,
+ "msg" : 0
+};
$(function(){
- $("button").toggle(startAcq, stopAcq);
+
+ $( "#acqButton" ).toggle( startAcq, stopAcq) ;
+
+ $( "#size" ).change( changeSize ) ;
+
+ $( "#binning" ).change( changeBinning );
+
});
function startAcq(){
- $("button").text("stop");
+ $( "#acqButton" ).text( "stop" );
+
// サーバーとWebSocket接続
- ws = new WebSocket("ws://localhost:3000");
- // メッセージ受信時の処理
- ws.onmessage = function(event){
- if(event.data=="init"){
- ws.send("acq");
- }else{
- ws.send("acq");
- draw(JSON.parse(event.data));
- console.log(i);
- i = i + 1;
- }
- };
+ ws = new WebSocket( "ws://localhost:3000" );
+
+ sendSettings();
+
+ // serialAcq;
}
function stopAcq(){
- $("button").text("start");
+ $( "#acqButton" ).text( "start" );
console.log("stop");
ws.close(1000, "close");
}
+function changeSize(){
+ settings[size] = $( "#size option:selected" ).val();
+ console.log(settings[size]);
+}
+
+
+function changeBinning(){
+ settings[binning] = $( "#binning option:selected" ).val();
+ console.log(settings[binning]);
+}
+
+
+function sendSettings(){
+ sendBuf["type"] = "settings";
+ sendBuf["msg"] = settings;
+ ws.send("aaa");
+ console.log( "send " + JSON.stringify(sendBuf) ); }
+
+
+function serialAcq(){
+ // メッセージ受信時の処理
+ ws.onmessage = function( event ){
+ if( event.data == "init" ){
+ ws.send( "acq" );
+ }else{
+ ws.send( "acq" );
+ draw( JSON.parse(event.data ));
+ console.log(i);
+ i = i + 1;
+ }
+ }
+}
+
+
+
// 描画
function draw(data){
var ctx;