Due to a worldwide Microsoft outage, various services on our website are currently experiencing disruptions or limited availability. We are monitoring the situation.

FAQ 326: How to create a custom instrument using HTML in Controldesk

Question

How do I create a custom instrument with a string display or graphics in Controldesk?

Solution

You can create custom instruments using Browser instruments, HTML, and JavaScript

Example of creating a browser instrument

In this example,  display the value of the variable assigned to the instrument as a string and a circular gauge.It is written in an HTML file containing JavaScript.

  1. Place the Browser instrument in the ControlDesk Layout
  2. Specify the following HTML file in Browser Properties>Browser>URL of the browser instrument.
  3. Variables Connection nodes... Click Add, add variable, and change Connection Info>Unique name to Node0.
  4. Drag and drop the variable you want to display to the Browser and select Node0.
ControlDesk_browser_example.html

<!DOCTYPE html>
<html>
 
<head>
      <title>ControlDesk browser instruments HTML</title>
</head>
 
<body>
<script>
Counter = 0;
function write_text(val) {
      str = "Node0 = " + String(val) + "<br>"+"Counter = "+String(Counter);
      document.getElementById("text").innerHTML = str;
}
 
function draw(val) {
      var ctx = document.getElementById("canvas").getContext("2d");
      startAngle = 180 * (Math.PI / 180);
      endAngle = startAngle + val * 180 * (Math.PI / 180);
      ctx.clearRect(0, 0, 200, 200);
      ctx.beginPath();
      ctx.fillStyle = 'blue';
      ctx.moveTo(100, 100);
      ctx.arc(100, 100, 80, startAngle, endAngle, false);
      ctx.fill();
      ctx.beginPath();
      ctx.moveTo(100, 100);
      ctx.fillStyle = 'white';
      ctx.arc(100, 100, 40, startAngle, endAngle + 1, false);
      ctx.fill();
}
 
function valueChanged(jsonData) { //ControlDesk Value change event
      data = JSON.parse(jsonData); //Get connection nodes value
      Val = {};
      data.Variables.forEach(function (variable) {
            if (Array.isArray(variable.Value)) { //Array
                  if (!Array.isArray(variable.Value[0])) { //1D Array
                        v = [];
                        for (i = 0; i < variable.Value.length; i++) {
                              v[i] = parseFloat(variable.Value[i]);
                        }
                  } else {
                        v = [];
                        for (i = 0; i < variable.Value.length; i++) { //2D Array
                              tmp = []
                              for (j = 0; j < variable.Value[0].length; j++) {
                                    tmp[j] = parseFloat(variable.Value[i][j]);
                              }
                              v[i] = tmp;
                        }
                  }
            } else {
                  v = parseFloat(variable.Value);//Scalar
            }
            Val[variable.UniqueName] = v;
      });
 
      Counter = Counter + 1;
      write_text(Val.Node0);
      draw(Val.Node0);
}
 
</script>
</head>
 
<body>
 
      ControlDesk Browser Demo<br>
      Text<br>
      <div id="text"></div><br>
      Graphic<br>
      <canvas id="canvas" width="200" height="200">
      </canvas>
 
</body>
 
</html>

Tags

产品 ControlDesk
资料信息 常见问答
信息类别 常规使用

通过 dSPACE时事通讯服务了解最新信息。

通过 dSPACE 时事通讯服务,我们将随时向您通报当前的使用案例、新解决方案和产品以及培训和活动。在此注册,免费订阅。

Enable form call

At this point, an input form from Click Dimensions is integrated. This enables us to process your newsletter subscription. The form is currently hidden due to your privacy settings for our website.

External input form

By activating the input form, you consent to personal data being transmitted to Click Dimensions within the EU, in the USA, Canada or Australia. More on this in our privacy policy.