In this blog, we will look at how developing ‘web monitor and control application’ is made easier through NI SystemLink API. There are many ways to build this, we have talked about how to build this using LabVIEW Web Service here. The trouble with LabVIEW web service for this use case is, the developer needs to create the brokering between desktop and web application as shown below,
Now using the latest NI Web Server and LabVIEW NXG Web Module, the developer can quickly set up a server and exchange data between the applications using NI SystemLink API, this bypasses developing an intermediate web service as shown below,
By this method, the LabVIEW web service (middle) is replaced by the NI Web Server and SystemLink service. Now, All we want to do is,
- Server: Setup the NI Web server
- Desktop application: Connect to the server and publish any data (to a topic) using SystemLink message APIs
- Web application: Connect to server, subscribe and read the data from the topic using SystemLink message APIs
This saves a whole lot of development time spent on API service and helps to build the control applications easily. Also, it makes the life of the novice developer easier as he doesn’t want to learn about the API services and rules behind how to develop them.
Example: Monitor and Control a simple Temperature Controller
This is the example of a simple temperature controller that turns ON\OFF the heater to keep the temperature within the set point range. The temperature, limits and heater state data from LabVIEW VI is being continuously published to the Web page built using WebVI. I have embedded the quick demo of application through a GIF
Source Code is available on GitHub – Download / Contribute / provide feedback
Below steps explains how to build this using SystemLink API’s
Setup NI Web Server
- Open ‘NI Web Server Configuration’ application
- Go to the ‘Summary’ tab.
- If you want to configure the server. Click on ‘Run guided setup to select preset settings’
- Choose one of the settings that you want and proceed to set up the server
- After setting up the server, note down the server URL from the ‘Summary’ tab
- To restart the Web Server, Go to ‘Control’ tab and click on ‘Restart’
How to publish and subscribe to data?
NI SystemLink contains message API’s using which application can publish and subscribe to a topic.
Below example code snapshot shows how to Publish and Subscribe to a topic using SystemLink API (in LabVIEW as well as WebVI)
- Use the URL of you NI Web Server to configure the HTTP and open SystemLink connection
- Use the SystemLink reference created to subscribe to a topic, read, publish to a topic or unsubscribe from the topic
- Based on the application, use the APIs in LabVIEW VI as well as WebVI
- Close the connection and destroy the HTTP configuration at the end
Note: A same SystemLink connection can subscribe and publish to many topics at the same time.
As shown above, use the Publish API to push the result to a specific topic. Then in any application that is connected to the same server, use Subscribe API to subscribe to the topic and Read API to read the results. This is as simple as reading and writing to a variable in LabVIEW and now data can be transferred between two desktop applications or between desktop and web applications seamlessly.
User Authentication for Web Access:
If you want to authenticate on who can control your application, then NI Web Server provides you an authentication system through which you can configure user permission. This is quite handy if you want to have a secure system.
Hope this is helpful!
Share and Subscribe to my future blogs
Leave a Reply