>> Artikelansicht

GPIB/IEEE-488 Befehle mit JavaScript senden

gpib.js
  1. function do_gpib(string) {
  2. // send ajax response to server
  3. $('#results').html('');
  4. $('#cmd').html(string);
  5. var bef;
  6. $.ajax({
  7. type: 'GET',
  8. url: 'http://192.168.178.200/dataserver.php',
  9. crossDomain: true,
  10. dataType: 'json',
  11. data: ''+string,
  12. success: function (data) {
  13. if(data.bef) {
  14. bef=data.bef;
  15. if(bef.length>80) {bef=bef.substr(0,80)+"...";}
  16. $('#results').html(bef);}
  17. else {$('#results').html(''+data.status)+' ';}
  18. return true;
  19. }
  20. });
  21. }
index.html
  1. <html>
  2. <head>
  3. <script type="text/javascript" src="./jquery-1.7.1.min.js"></script>
  4. <script src="./gpib.js" type="text/javascript"></script>
  5. </head>
  6. <body>
  7. <h3>PM 5150[21]</h3>
  8. <a href="javascript:do_gpib('befw=*RST;*IDN?&dev=21&type=gpib');">RESET_DEV</a>
  9. <a href="javascript:do_gpib('befr=100&dev=21&type=gpib&bef=');">READ_DEV</a>
  10. <div id="results"></div>
  11. <div id="cmd"></div>
  12. </body>
  13. </html>