|
@@ -0,0 +1,92 @@
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+function init() {
|
|
|
|
+
|
|
|
|
+ script.log("hello VISCA");
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+function setZoom(ID, position){
|
|
|
|
+
|
|
|
|
+ var idHex = (parseInt("0x80") + ID);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ var pos = Math.round(4000 * position);
|
|
|
|
+ var posString = ""+pos;
|
|
|
|
+ var pad = "0000";
|
|
|
|
+ posString = pad.substring(0, pad.length - posString.length) + posString;
|
|
|
|
+ script.log(posString);
|
|
|
|
+
|
|
|
|
+ var posCommand = [parseInt("0x0"+posString.charAt(0)),
|
|
|
|
+ parseInt("0x0"+posString.charAt(1)),
|
|
|
|
+ parseInt("0x0"+posString.charAt(2)),
|
|
|
|
+ parseInt("0x0"+posString.charAt(3))
|
|
|
|
+ ];
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ local.sendBytes(idHex, 1, 4, 71,
|
|
|
|
+ posCommand, 255);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+var buffer=[];
|
|
|
|
+var bufferIndex = 0 ;
|
|
|
|
+function dataReceived(data)
|
|
|
|
+{
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ for (var i = 0 ; i<data.length ; i++){
|
|
|
|
+ if (data[i]!=255){
|
|
|
|
+ buffer[bufferIndex]=data[i];
|
|
|
|
+ bufferIndex += 1;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ else{
|
|
|
|
+ if(buffer[0]==144){
|
|
|
|
+ if (buffer[1]==65){script.log("received command");}
|
|
|
|
+ if (buffer[1]==81){script.log("complete command");}
|
|
|
|
+ if (buffer[1]==97){
|
|
|
|
+ var msg = "error :";
|
|
|
|
+ if(buffer[2]==1){msg=msg+"message length";}
|
|
|
|
+ if(buffer[2]==2){msg=msg+"syntax";}
|
|
|
|
+ if(buffer[2]==3){msg=msg+"command buffer full";}
|
|
|
|
+ if(buffer[2]==4){msg=msg+"command cancelled";}
|
|
|
|
+ if(buffer[2]==5){msg=msg+"no socket";}
|
|
|
|
+ if(buffer[2]==65){msg=msg+"command not executable";}
|
|
|
|
+ else{
|
|
|
|
+ msg=msg+"unknow error";
|
|
|
|
+ for(var j=2; j < buffer.length; j++)
|
|
|
|
+ {
|
|
|
|
+ script.log(" > " +data[i]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ script.log(msg);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ bufferIndex = 0;
|
|
|
|
+ buffer=[];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|