This example is a simple 4-bit calculator using the JavaScript Library Interface (JSLI). The math functions and Log to Console button illustrate different methods of using the JSLI. Add (JSLI) and Multiply (JSLI) use external JavaScript files to implement their functions. The Log to Console button logs text to the browser debug console using the browser-supported console.log
function. After building and deploying the WebVI to a browser, open the browser developer tools (Press F12 in most browsers) and select the Console tab to view the console log.
On the panel, this WebVI has X and Y binary inputs. The user clicks these to change the numerical values of the inputs. The Outputs of X+Y and X*Y are updated with binary and numerical indicators.
CallJavaScriptFromAWebVI\CallJavaScriptFromAWebVI.gwebproject
index.gviweb
and click the Run button.WebApp.gcomp
.You can manually the move the build output found at \CallJavaScriptFromAWebVI\Builds
to any web server. This project also includes a Distribution (WebApp.lvdist
) that can be used to build a package (.nipkg). Packages utilize NI Package Manager to automated the process of installing, upgrading, or removing the web app. A package is also a requirement for hosting a Web application on SystemLink Cloud.
The following steps can be used to host the web app on SystemLink Cloud
CallJavaScriptFromAWebVI.gwebproject
.WebApp.lvdist
.The following steps can be used to host the web app on a local web server
CallJavaScriptFromAWebVI.gwebproject
WebApp.lvdist
.http://localhost:9090/CallJavaScriptFromAWebVI/
C:\Program Files\National Instruments\Shared\Web Server\htdocs
WebApp_Default Web Server
directory into the htdocs
directoryhttp://localhost:9090/WebApp_Default%20Web%20Server/
C:\Program Files (x86)\National Instruments\Shared\NI WebServer\www
WebApp_Default Web Server
directory into the www
directoryhttp://localhost:8080/WebApp_Default%20Web%20Server/
This WebVI uses the JSLI to interface with simple functions defined in Add.js
and Multiply.js
, and compares the results with the G Web Development Software built-in functions.
A single JSLI wraps JavaScript functions in the two external JavaScript files.
The external functions are referenced by using the Function prototype symbol, or name, used in the JavaScript file.
For example, AddWithJSLI
is a function defined in Add.js
.
The corresponding JSLI function references the Symbol AddWithJSLI
to link the JavaScript function to the JSLI function.
The Add and Multiply nodes output the JSLI and built-in function results to the index WebVI.
The Multiply.js
file demonstrates a simple, external JavaScript function, and the Add.js
file demonstrates a more complex JavaScript function.
See these files for comments about the functions themselves.
The Log to Console button logs text to the browser debug console using the browser-supported console.log
function.
After building and deploying the WebVI to a browser, open the browser developer tools (Press F12 in most browsers) and select the Console tab to view the console log.
The log allows the user to see messages that can potentially help debug their application.