/InsightCM-Console-in-LabVIEW

Running InsightCM Console commands from LabVIEW

Primary LanguageLabVIEWMIT LicenseMIT

InsightCM-Console-in-LabVIEW

Running InsightCM Console commands from LabVIEW

Introduction

The main goal of this project is to make it easier to run InsightCM Console commands and automate a sequence of commands for the specific purpose of adding a new custom device to InsightCM. In addition to that, this project allows the user to export Data Sets as TDMS Files.

State Machine FTW ❤️

I strongly believe that State Machine can solve a huge amount of the application needs and is sometimes underestimated when people start working with more complex architectures, such as QHM or even Actor Framework. I still believe we can stress out the features of our loved State Machine before jumping into more complex design patterns and frameworks (although it is important to have a good understanding of each one of them).


I know the state machine is not a silver bullet. It is indeed underestimated, though.


If you are an enthusiast of State Machines, keep reading this article for a non-standard implementation of it and also check out the JKI State Machine for LabVIEW by JKI which is another super powerful variation of this awesome LabVIEW Design Pattern. 😃👍

The Project

Project Goal 🎯

In this project, I wanted to help a customer by giving them a more easy-to-use interface to incorporate a new device into the InsightCM server. It is a very detailed and complex task, with a lot of steps to do files to export, import, edit, etc. In addition to that, the interaction with the server should be done by command line. My goal was to help them upload a base version of this device and they will contract a developer to do the rest (i.e., they are not software developers and are not so proficient with those tricky steps). To lower their effort - and mine as a consequence - I built a state machine that automates the more complicated parts.

Design 📓

The diagram below represents the general structure of the State Machine.

State Machine

In the diagram above, the steps in red are the steps related with the command line interface. For each command we want to send, we have to build the command string, run the command using the System Exec.vi, and Processing the String response. The steps Build Command and Process Standard Output will not be actually implemented, but they represent the general task.

States Overridden

The Build Command will have different implementations as states in the code.

Build Command Implementations

Same thing for the Process Command Output.

Process Standard Output

The Open File State will exclusively open the TDMS file we pull from the server.

Implementation 💻

The implementation relied on the LabVIEW State Machine Sample Project.

SM_SampleProject

And this is how I structured the project files

Project

Running Multiple Commands in sequence

During the development I found the need for running more than one command in sequence before going back to wait for an event. For example, I wanted to Run both Import Definitions and List Definitions in a row and transition back to Wait for an Event. Thinking on the standard State Machine, we can only decide the next state and not a sequence of states. To address that, I made use of the managing the Enum of states in an array of states.

Array of States

When a user clicks the Import Definition button, the Event Case will determine the next set of states to be executed.

Next States

The State Machine then starts to remove elements from the top of the list of states and the removed element is the state to be executed.

Next State


Note: If you want to ignore the following states, put another state at the top of the list, or put another state at any position of the list, you can do it by using the array manipulation functions. For this project, I just passed the array of states through the other states, that is, the Wait on Event is the only state who determines the next set of states.

Conclusion 🏁

State machine is probably the first design patter you learn in LabVIEW, but sometimes we stick to this belief that it is just step sequencer and you cannot make it more flexible and scalable than the version of the LabVIEW sample project, but that is not true. Go ahead and open your mind to the possibilities with this simple, but powerful, LabIVEW Design Pattern. 😉


Next Steps and Improvements

  • Make it more scalable. More projects could benefit of this Build -> Run -> Process structure.
  • Improve Console output processing and Eror Handling

📧 Feel free to send me comments and improvement suggestions on flores.felipegomes@gmail.com