Now viewing draft 3.
CompactRIOdeployment.zip, attached below, contains the reference design and example described in this tutorial. Unzip the file in an empty folder on your computer and open the LabVIEW project.
Software
Application Software: LabVIEW Full Development System 2012
Driver: NI-RIO 5.0
Toolkits and Add-Ons: LabVIEW Real-Time Module 2012
Language(s): LabVIEW
Hardware
Hardware Group: CompactRIO
The process of updating or deploying a new application image from a memory device to a CompactRIO controller is based on a simple file copy operation which replaces the files on the hard drive of the CompactRIO controller with files stored on a memory device. This file copy operation is added as a VI to the main LabVIEW Real-Time application deployed to the controller. When the controller powers up the Real-Time application launches this VI which performs the copy operation after it determines whether a memory device containing updated files is present.
A LabVIEW Real-Time application and Real-Time OS once loaded and running on the controller is stored completely in the active memory (RAM) of the controller. This allows an application to delete and replace any files stored on the controller hard drive while the application is running in memory. The new application becomes active by performing a reboot operation on the controller and loading the new application during the boot process.
Note that a Real-Time system running Pharlap is not completely loaded into memory which limits write-access to the hard drive. This limits the deployment of full images to VxWorks targets. The deployment of a plug-in can still be performed on any target as long as the destination folder is not write-protected.
Below are the main steps to generating an application and supporting the deployment from a memory device:
Initial Application Deployment
Developing and Deploying an Updated Application Plug-In
Developing and Deploying an Updated Controller Image and Application
The CompactRIO controllers in the 901X and 902X line contain a USB port that can be used to deploy an update using a USB memory device. All CompactRIO controllers can use the NI-9802 C-Series module to deploy an update using a SD memory device.
The update process requires the main application to run properly in order to recognize the memory device and copy files from the device to the controller hard drive. Therefore, if the main application is not running successfully, such as may be the case if the hard drive of the controller has been corrupted, then this method of deploying a new application will not work. For this reason this method cannot be used to re-image, recover, or repair a corrupted controller hard drive.
This section focuses on the steps required to setup a CompactRIO for updates via a memory device. The startup application that accommodates deployment via memory devices must be initially deployed using an Ethernet connection. Deployment of the plug-in application need not accompany the initial deployment of the startup application, though it is convenient to do so during initial deployment if desired.
Once the code provided in this tutorial has been downloaded launch the .lvproj file and open the Main Application highlighted in Figure 1. Two Main Applications are provided in this code depending on the type of memory device that will be used. This tutorial uses the USB deployment example but an example demonstrating the use of an SD card is also provided.
Figure 1: LabVIEW Real-Time Application
Figure 2: USB Main Application block diagram
Figure 3: USB Main Application build specification
Figure 4: LabVIEW Real-Time Plug-in Application
Figure 5: LabVIEW Real-Time Plug-in Application Build Specification
The deployed application and executable together with all of the other files on the CompactRIO controller hard drive becomes the application image. If the initial application image needs to be deployed to multiple embedded controllers you can use the Replication and Deployment (RAD) utility. It is good practice to keep an image of a controller even if it is not being replicated on other controllers to assist the creation of a blacklist for future updates. In the next two sections we will discuss how to deploy an updated plug-in application and an updated controller image respectively.
After developing and deploying the initial application, we are now at the point where we want to develop an updated application and deploy it from a memory device to a CompactRIO system that is running the initial application.
Figure 6: Updated LabVIEW Real-Time Application
Figure 7: Packed Library Build Specification Properties
Figure 8: Copy Utility
Figure 9: Memory Device Select Dialog
Figure 10: Plug-in Application Select Dialog
Figure 11: Plug-in Application Controller Directory
Figure 12: Plug-in Application lvappimage.info File Configuration
During the application startup process the Deploy Image VI will detect the memory device, compare the key and version number between the lvappimage.info files on the controller and memory device, and if necessary will copy the application from the memory device to the controller. It will copy the application if the .info files contain a different key or version number or if there is no info file located on the controller. After placing the new application on the controller it will archive the controller’s old info file and copy over the info file that was on the memory device. If specified in the original application, the Deploy Image VI will reboot the controller after updating the application image to load the updated application. Depending on the size of the application image and the type and speed of memory used, this process can take several minutes to complete.
It may be necessary to update several drivers or upgrade the version of LabVIEW Real-Time on a deployed CompactRIO to accommodate an updated version of an application. This is accomplished by imaging a CompactRIO of the same model with the desired updates and upgrades installed. The image is placed on a memory device and used to replace the existing image on the deployed CompactRIO. Deployment of a full image is considered riskier than deployment of a plug-in application since an error in the copy process may exclude necessary components of the OS or the startup application which would require an Ethernet connection to remedy.
Figure 13: Replication and Deployment Utility
Figure 14: Copy Utility
Figure 15: Memory Device Select Dialog
Figure 16: CompactRIO Image Select Dialog
Figure 17: Image lvappimage.info file configuration
The provided code included examples of a Main Application that can be built into a startup application for either USB or an SD memory device. Though the steps to deploy a plug-in application or image update are the same regardless of memory device, the steps for the initial configuration will be slightly different. The initial setup steps will require that an FPGA VI has been compiled that includes information on which slot the 9802 is in. In the example provided a 9802 has been added to the chassis in slot 1. If desired, a 9802 could be added to every slot of the chassis and then compiled to accommodate the ability to deploy from any slot in the chassis. This would require modification of Main_Application_SD.vi since it checks a single slot before continuing to the Deploy Image.vi.
Once it has been decided which slot the 9802 will be compiled in, the FPGA VI must be recompiled for the specific target that application will be deployed to. Changing the slot the the 9802 will be deployed to will require a recompile of the VI. Note that the included FPGA VI contains code that blinks the FPGA LED on the CompactRIO while it is running.
Figure 18: VI Compiled for FPGA Target
Once the FPGA vi has been compiled the NI 9802 RT Access (Host).vi which resides within the Main_Application_SD.vi must be pointed towards the compiled VI or the bitfile associated with the VI. The code seen in Figure 18 first loads this bitfile, then once it has been loaded it mounts the 9802 and passes the enumerated drive letter into the Deploy Image.vi which then executes the same code that it would use if a USB memory device were present. The only difference between a startup application that detects a USB memory device and a SD memory device is the code in the NI 9802 RT Access (Host).vi loads the bitfile and mounts the drive before it calls the Deploy Image.vi.
Figure 19: Main_Application_SD.vi and NI 9802 RT Access (Host).vi Block Diagram
This section will describe the code implemented within the Deploy Image.vi that is responsible for detecting a memory device, determining if there is an image present, and performing the copy operation. This VI is organized as a simple state machine in a sequence of steps managed in a Case structure. The steps are:
The names of the different folders and files used by the VI are specified by constants on the diagram. These may be changed for your specific application, but you must make sure that they match to the folder and file names used in the Deploy Image VI.
During the copy process the VI maintains a log file on the USB device to store the progress of the operation and record any errors.
In this first step the VI checks for the presence of a USB memory device. If the device is present and detected by LabVIEW it will appear as a hard drive with the letter U: designation (the RT OS will always enumerate the first external volume detected with the letter U). Using the Get Volume Info function the VI checks for the presence of a drive at U:.
In this step the replicationlog.txt file is created or opened and an initial entry is made on both the controller and memory device.
If a memory device is not detected the VI proceeds to Exit. Otherwise, it proceeds on to Compare Keys.
The case checks to see if there are lvappimage.info files on the controller or the memory device. It then checks for the Version and Key tokens and compares the values between the two files. The result of transition code then depends on whether the Disable Image Retrieval has been left by default to true (true meaning that image retrieval is disabled) or if has been changed to false via the input terminal or a different default value.
If image retrieval remains disabled, then the VI proceeds to the Calculate List case if the memory has a .info and the controller does not have an .info file or if the keys in both .info files do not match. Otherwise the VI proceeds to the Exit case.
If image retrieval is enabled, then the VI will proceed to Retrieve Image only if there is an .info file on the controller and there is not an .info file on the memory device. Otherwise it uses the same logic as image retrieval disabled to determine whether to move into Calculate List or Exit.
If image retrieval is enabled and a .info file was detected on the controller but not the memory device then the Retrieve Image case will execute. This case contains the Retrieve Image.vi which copies all files and folders from the controller onto the memory device. The files and folders are copied into the an appimage folder on the root directory of the memory device. Once copying has completed the memory device can be used to image other controllers running the requisite startup application.
The VI proceeds to Exit once Retrieve Image.vi has completed.
The case retrieves the blacklist from the lvappimage.info file on the memory device to determine which files and folders will not be overwritten or deleted during the copy process.
The copy list is generated by comparing a list of files on the memory device against the black list. If a file is not on the black list or within a sub directory of a folder on the black list but is within the appimage folder on the memory device, it will be placed in the copy list.
The delete list is generated by comparing a list of files on the controller to the copy list and the black list. If a file is not on the black list or within a sub directory of a folder on the black list or on the copy list but it is on the controller, it will be placed in the delete list.
Note that replicationlog.txt files, lvappiamge.info files, and c:\image_history on the memory device and controller are hard coded into the black list. These will never be deleted or copied unless the code is manually modified to remove these from the blacklist. It should also be noted the lvappimage.info files are manually inserted at the end of the copy list to ensure that they are the last files copied over.
Once the lists have been calculated the VI proceeds to Copy Files.
This step copies all of the files and folders on the copy list from the appimage folder on the memory device over to its respective directory on the CompactRIO controller.
The last files to be copied will be the lvappimge.info files. Before the .info file from the memory device overwrites the controllers .info file, the old controller .info file will be copied into the c:\image_history directory.
If there is an error detected at any point during the copy process, copying halts, the error is logged, and the VI proceeds to Reboot Controller. Since the lvappiamge.info file is the last file copied over the controller should be able to begin the copying process again when restarted assuming the files being copied were part of a plug-in application and not the RT OS.
Once copying has completed the VI proceeds to Delete.
The step deletes all files and folders on the delete list off of the controller.
This step reboots the controller unless the Reboot on Update input has been changed to false.
The last step places a final comment in the log file and closes it.
This example and tutorial present a basic implementation for deploying a plug-in application or a full image from a memory device to a CompactRIO controller. It may not satisfy all of the requirements or needs of a particular application. For example, in some instance it may be necessary to accommodate an update from either a USB or SD device. Without any changes to the provided Main Applications there would not be a way to accommodate both options from a single cRIO. Modifications would need to be made that would first check to see if one was present then check to see if the other is present and continue on with the deployment code if either turns up with a device present. Customization would also be required to accommodate SD deployment from any slot in a cRIO. The current invocation requires a bitfile that has been compiled with the 9802 in a predefined slot. A system could be configured that used a bitfile that was precompiled with a 9802 in every slot so that the startup application could check every slot for a memory device. Another possible custom feature would be the examination of multiple memory devices rather than the first device detected. The current startup application checks only the first enumerated drive (which will always be a /U/ drive) and does not continue on to look for additional memory devices.
In the example the Deploy Image VI is run during the application startup process before the plug-in application VI is started. To update the application image on the controller the memory device is plugged into the controller and the controller is reset. During the following startup sequence the memory device will be detected and the new application image copied to the controller, followed by another software-initiated reboot operation which will load and run the new application. In some cases it may not be desirable to reset the controller to copy a new application image. In this case the Deploy Image VI can be integrated differently into an application so that it can run at any point in time and detect a memory device inserted into the controller. This could be done in a parallel loop running periodically (e.g. every 5 seconds) to check for the presence of a new application image. After the application image is updated the VI can send a message to the rest of the application to stop any ongoing process gracefully before resetting the controller to load and run the new application image.
As was mentioned earlier, the basic requirement for this deployment process to work is that the Deploy Image VI must run on the controller in order to detect the memory device and copy the new application to the controller hard drive. If for any reason the controller is in a state where this VI cannot run or if it is missing from the current application on the controller then this method will not work. If the controller's hard drive is corrupted or if the deployed application will not run then the controller needs to be recovered or updated using an Ethernet connection from a system containing the Measurement & Automation Explorer (MAX) and the LabVIEW development environment.
This reference design was created by the NI Systems Engineering group.
Please post your questions and comments for this reference design in the USB Deployment Discussion Forum.
Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.