Learning Remote Control Framework ADD-ON for LabVIEW TOOLS for SMART MINDS Abstract This document introduces the RCF (Remote Control Framework) ADD-ON for LabVIEW. Purpose of this article and the documents that will follow, is introducing developers to the use of RCF to create their own remote controls to manage LabVIEW based systems. In this document the following points are covered: creating a Remote Control (RC), creating commands, adding parameters to a command, implementing LabVIEW code associated to a command. Keywords RCF, LabVIEW, remote control, client server, OOP with LabVIEW, design pattern with LabVIEW Document type TUTORIAL 1
Learning Remote Control Framework ADD-ON for LabVIEW Introduction The purpose of this document is help LabVIEW developers to integrate RCF in their own applications. RCF is a powerful ADD-ON for LabVIEW that creates a system interface of a LabVIEW based system, similar to a remote control, on different platforms such iphone, Android phones, web browsers. LabVIEW programs play the role of servers while RCF clients act as clients. In the follow I use the term server to refer to the LabVIEW program and the term client to refer to an RCF client. Requirements RCF ADD-ON for LabVIEW is based on SCCT primitives. SCCT is a communication library available for different programming languages and platforms. SCCT for LabVIEW rel. 2.5.x is required. LabVIEW development system 2010 or higher (32 bit or 64 bit) SCCT (Smartphone & Cross-platform Communication Toolkit) Remote Control Framework ADD-ON for LabVIEW SCCT (Smartphone & Cross-platform Communication Toolkit) Refer to Resource paragraph at the end of this document to find useful link and download evaluation copies. Overview RCF publishes the interface of your system to clients, when they successfully connect to the server. Authentication and all communication details are managed by RCF and SCCT so you don t have to. The interface you define for your system, is named CATALOG. A Catalog is a collection of Remote Controls devoted to different users or activities. For complex systems you can define multiple remote controls each with multiple commands, while simple systems generally have only one remote control. Every Remote Control is composed by a list of commands which extend the basic Command class, provided by RCF. A command is associated to one or many buttons of your remote control. Every command can includes some parameters that user has to fill before firing the command. Firing a command means sending to server a request with some parameters. Simplest command has no parameters. Reserved commands can be associated to a password so that only authorized users can use them. Commands (i.e. user requests) can return one or more results to user. In this case RCF is responsible to gather information and format them properly before returning them to the user. Clients are in charge to display properly results according to their definition specified at server side. Available result types are: Text Table Chart Histogram Piechart X-Y Chart 2
Tutorial TOOLS for SMART MINDS 2013 The following UML diagram explains the relation between classes. Catalog Remote Control Command Parameter 1..N Has (many) Is a My first command My second command My third command Catalog can be changed at runtime. When a catalog is update, RCF notifies to clients the new catalog, with more or less commands. Catalogs can be created programmatically with LabVIEW code or can be loaded from disk. How RCF interacts with LabVIEW main app Apart from basic applications without loops, generally a LabVIEW based system has one or main loops devoted to different tasks: acquiring, controlling, processing, etc. RCF interacts with them passing user requests if it cannot manages the request by itself. Command results have to be retrieved by one of the loops in the main application, for instance the acquired signal values. Interaction, i.e. data exchange among RCF and loops can be implemented in your favorite method: queues, notifiers, Global variables, etc. LabVIEW application, with one or more loops devoted to different tasks. RCF creates a background loop with manages users requests and all communication details. Adding RCF to a LabVIEW program The following Example illustrates how RCF is added to an existing LabVIEW program. Notice that when The main loop ends, you need to notify to RCF that its loop has to terminate otherwise LabVIEW program never stops. 3
Learning Remote Control Framework ADD-ON for LabVIEW RCF needs only three elements to work: TCP port where it has to listen to incoming connections, password to authenticate users a catalog to create remote control(s) The above example includes stopmanager.vi that stops RCF background task. STEP 1 - Creating a simple remote control In the following, we create a simple remote control composed by 5 commands. Follow the tutorial step by to create your own LabVIEW code or download the example at the following link: Specifications We create a Remote Control to manage some simple operation on server disk. Command title Get Free disk space Create Folder Get file List Command description Returns the FREE disk space in MB Creates a subfolder in folder where LabVIEW program is saved Returns a table that describes files or folders available in folder where LabVIEW program is saved First of all, we choose a title for our Remote Control and a brief description displayed on clients as RC help. Below, is shown the code to add a RC to a catalog. RC title is Disk management, RC layout is Remote control. RC can be displayed with different layouts by clients. Most popular layout is Remote Control so we use that in this example. The function build array is required because write RemoteControlList.vi requires an array of RCs as input parameter. 4
Tutorial TOOLS for SMART MINDS 2013 Creating the first command Since RCF is based on OOP programming, you need to create specific classes for your commands. To add create a Class, choose New form LabVIEW file menu and select Class in the left side of the window: LabVIEW asks the name of the new class, type CmdGetFreeDiskSpace, as indicated below. Take care to create a subfolder named CmdGetFreeDiskSpace into your project folder. This is necessary because multiple classes implement the same method so many Vis require the same file name. At this point you have to link your new class with a Command class included into RCF. Right click on class name in project window and select the last menu item Properties as indicated below: 5
Learning Remote Control Framework ADD-ON for LabVIEW Class property window allows to edit many features of your LabVIEW class. To change its inheritance, select Inheritance form left panel and press Change Inheritance button in the right side 6
Tutorial TOOLS for SMART MINDS 2013 From left list. Select Command.lvclass and press Inherit from selected button. RCF includes Command class to this purpose, use always this class to create your own commands. Close Class property window with Ok button and return to project window. Right click of your class in project window and select New >> Vi for Override item. This allow to override abstract methods defined in ancestor class. 7
Learning Remote Control Framework ADD-ON for LabVIEW In New Override window, Select first row * execute. LabVIEW places an asterisk at the left of abstract methods that required to be implemented in concrete classes. The only method you have to override i You can create all methods and properties you need to implement your command. Save created VI into class folder with execute.vi name. Do not override other class methods otherwise RCF won t be able to run your command properly. RCF uses execute method in response to user requests, so remember to implement always this method. By default, LabVIEW placed a call to ancestor method. As indicated in the following figure: You need to substitute that code with your own LabVIEW code. For this method we place the following code, to return the free disk space to user. 8
Tutorial TOOLS for SMART MINDS 2013 The code returns a message with the free disk space, in MB. Every command returns a result object. RCF allows different types of result. You can find result classes and methods in RCF palette. Do not change these classes otherwise RCF clients become unstable and can crash. In this example, a TextResult object is returned to the client. Creating the second command Add a new class name CmdCreateFolder to your project, change its inheritance and override execute method, as done for the first command. The project window will result as follow: On disk you have the following structure: This command creates a new folder with name indicated by user. This command contains a single parameter we call Folder. Parametric commands display a form created at runtime on client interface and users fill the form BEFORE send the request to RCF. In this execute method, we use Read filedvalues.vi to retrieve the field values typed by user. We know that this command has only one parameter so we take the first element of fieldvalues array. Fields are always 9
Learning Remote Control Framework ADD-ON for LabVIEW returned as string values, regardless of their type. The suggested code checks is folder exists, then creates it. This command returns a TextResult object as we did for the first command. Note: How can we create command that do not return results? If your command doesn t need to return result, simply do not connect result indicator. Creating the third command Add a new class name CmdGetFileList to your project, change its inheritance and override execute method, as done for the previous commands. The project window will result as follow: On disk you have the following structure: This command requires two parameters: Folder name List type that indicates the subfolder to be analyzed. If this name is not specified, command uses default folder A listbox with three values: Files only Folders only Files and Folders 10
Tutorial TOOLS for SMART MINDS 2013 The code of execute method is illustrated in figure below: This execute.vi uses two subvis to list file and folder attributes. These Vis are part of command class and saved in class folder. This command returns a table result to user. Table is fully described by a four elements cluster. Read fieldvalues returns two values: the first is the folder name while the second one is the list type. 11
Learning Remote Control Framework ADD-ON for LabVIEW Composing the remote control With the three commands created above, we compose a remote control. Use three times quickcreate.vi, to create three commands with all their parameters. Notice that: Commands in RC are displayed in the same order you add them in your array of command objects. Every command requires a title, displayed on command buttons of client interface Every command requires a TAG: a unique string used by RCF to identify user requests. A TAG can be any nonempty string. 12
Tutorial TOOLS for SMART MINDS 2013 Since commands CreateFolder and GetFileList require user input, we add fields to those commands as indicated in figure below: Before starting the server, we add some useful details: welcome message and help URL. Adding a welcome message It s important to welcome users when they successfully connect to the system. Connect a string message to welcomemessage connector of RCF manager, as indicated in the following figure: 13
Learning Remote Control Framework ADD-ON for LabVIEW Adding a help URL When users connect to a complex system, like automatic machine or similar, it s important providing a detailed help of that system enriched with images and technical details: RCF allows associating a URL to every catalog. Clients display a specific info button linked to help URL. To do so, connect helpurl with the proper page address, as indicated in figure below: Some clients require prefix http:// to properly open the web page: always add http:// to help URL. When designing Execute.vi pay attention to the following points: Execute.vi has to be executed in short time, Inside an execute.vi, never requests user interaction at server side (such messagebox, alerts, etc.) never include never-ending loops. Remember that multiple users can be connected at the same time and request the same command. Debugging your application One of the main advantages of RCF over web services, is the easiness of debugging your LabVIEW code. When you run a RCF client and request the execution of analyzed VI, you can take full advantage of LabVIEW debugging tools such probes and breakpoints. 14
Tutorial TOOLS for SMART MINDS 2013 Testing your RCF Now it s time to run your first RCF. Take note of IP address of your PC and connect your smartphone to that PC. Clients for Android and iphone/ipad allow to save connection info on their local disk so you don t need to type credentials every time. The following screenshots have been taken form RCF client for ios. 15
Learning Remote Control Framework ADD-ON for LabVIEW Resources RCF clients are available for the following platforms: RCF ADD-ON for LabVIEW is available for evaluation at http://www.toolsforsmartminds.com/products/remote_control_for_labview.php For Android devices, visit Google Play at https://play.google.com/store/apps/details?id=scct.console For iphone/ipad devices, visit Apple store at https://itunes.apple.com/en/app/remote-control-for-labview/id595313230?mt=8&ign-mpt=uo%3d4 For HTML5 compliant browsers, at http://www.toolsforsmartminds.com/remote_control_html5/ For Windows based systems, a FREE RCF client is available at http://www.toolsforsmartminds.com/products/remote_control_for_labview.php This client has some limitation to the number of commands and parameters you can add to a remote control. This client has been created to help developers to test their LabVIEW based systems and learn how to create simple remote controls. SCCT is available at http://www.toolsforsmartminds.com/products/labview_communication_library.php LabVIEW and related National Instruments products (such device drivers and other ADD-ONs) are available at www.ni.com 16