Advertisement
nikmaster

Yoctopuce demo

Mar 18th, 2012
470
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <HTML>
  2. <HEAD>
  3.  <TITLE>Hello World</TITLE>
  4.  <SCRIPT type="text/javascript" src="../../Sources/yocto_api.js"></SCRIPT>
  5.  <SCRIPT type="text/javascript" src="../../Sources/yocto_led.js"></SCRIPT>
  6.  <SCRIPT language='javascript1.5' type='text/JavaScript'>
  7.  <!--
  8.  // Use explicit error handling rather than exceptions
  9.  yDisableExceptions();
  10.  
  11.  // Setup the API to use the VirtualHub on local machine
  12.  if(yRegisterHub('http://127.0.0.1:4444/') != YAPI_SUCCESS) {
  13.      alert("Cannot contact VirtualHub on 127.0.0.1");
  14.  }
  15.  
  16.  var led;
  17.  
  18.  function refresh()
  19.  {
  20.      var serial = document.getElementById('serial').value;
  21.      if(serial == '') {
  22.          // Detect any conected module suitable for the demo
  23.          led = yFirstLed();
  24.          if(led) {
  25.              serial = led.module().get_serialNumber();
  26.              document.getElementById('serial').value = serial;
  27.          }
  28.      }
  29.  
  30.      led = yFindLed(serial+".led");
  31.      if(led.isOnline()) {
  32.          document.getElementById('msg').value = '';
  33.      } else {
  34.          document.getElementById('msg').value = 'Module not connected';        
  35.      }
  36.      setTimeout('refresh()',500);
  37.  }
  38.  
  39.  function switchIt(state)
  40.  {
  41.      if (state) led.set_power(Y_POWER_ON);
  42.            else led.set_power(Y_POWER_OFF);
  43.  }
  44.  -->
  45.  </SCRIPT>
  46. </HEAD>  
  47. <BODY onload='refresh();'>
  48.  Module to use: <input id='serial'>
  49.  <input id='msg' style='color:red;border:none;' readonly><br>
  50.  <a href='javascript:switchIt(true);'>ON</a><br>
  51.  <a href='javascript:switchIt(false);'>OFF</a>
  52. </BODY>
  53. </HTML>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement