RMCLink.Interop .NET Assembly

RMCLink.WriteImageFromFile Method

Loads the controller image from the specified file, writes it to the controller and applies it. By default, the image will be saved to flash and the controller will be restarted. The controller image file must have been created using the ReadImageToFile method. For saving and restoring the controller image using an array in memory instead of using a file, use the ReadImage and WriteImage methods. This method is only supported on the RMC75E, RMC150E, and RMC200 controllers.

Syntax

Visual Basic (Declaration)

Public Sub WriteImageFromFile ( _

    flags As Integer _

)

 

Visual Basic (Usage)

Dim instance As RMCLink

Dim flags As Integer

Dim fileName As String

 

instance.WriteImageFromFile(flags, fileName)

 

C#

public void WriteImageFromFile (

    int flags,

    string fileName

)

 

Visual C++/CLI

public:

void WriteImageFromFile (

    int flags

    String^ fileName

)

Parameters

flags

Options to use when applying the image. Refer to the RMCTools documentation on the Image Area for a current list of options. As of this writing, a single option has been defined. Specify zero (0) to use default options.

+0

Save Image to Flash, and Restart Controller to Apply

+16

Apply Image Immediately and Save To Flash (not supported by RMC200)

fileName

File name and path to load the controller image from.

Remarks

This method is synchronous, which means that it will not return until the write is completed, which may take several seconds. If this method is called on the main thread, then the application will likely be unresponsive until this method completes. For applications where this is not acceptable, this and other synchronous methods should be called from a worker thread, and may use the CancelRequest method to cancel an in progress request.

Exceptions

Exception Type

Condition

ArgumentNullException

The fileName parameter refers to a null (Nothing in Visual Basic) object.

ArgumentOutOfRangeException

The flags parameter is out of range, or the fileName parameter is blank.

CancelledException

This read was cancelled by a call on another thread to one of the Disconnect and CancelRequest methods.

InvalidOperationException

One of the following circumstances occurred:

  • The link is not currently connected. The Connect method must be called before attempting to read from the controller.

  • The Image Area is not supported by this controller. The controller must be an RMC75E, RMC150E, or RMC200 with firmware supporting the image read/write.

  • The image is corrupt or not a recognized version.

  • The Do Not Restart Controller (+16) option was selected, but the image requires restarting the controller.

  • The Do Not Restart Controller (+16) option was selected, but the controller is not in PROGRAM mode.

  • The image downloaded is intended for a different physical controller.

ReadWriteFailedException

The read failed due to a communication failure. Check that the remote device is powered up, check the communication wiring, and check the communication configuration of both the local and remote devices. Check the Message property of the exception for a description of the communication failure.

System.IO.PathTooLongException

 

The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.

System.IO.DirectoryNotFoundException

The specified path is invalid, (for example, it is on an unmapped drive).

System.UnauthorizedAccessException

fileName specified a directory -or- The caller does not have the required permission.

System.IO.FileNotFoundException

The file specified in fileName was not found.

System.NotSupportedException

fileName is in an invalid format.

System.IO.EndOfStreamException

The end of the stream was reached unexpectedly.

System.IO.IOException

An I/O error occurred while creating or writing to the file.

Example

The following code example illustrates the use of the WriteImageFromFile method.

Visual Basic

Imports RMCLinkNET
Module Example
    Sub Main()
        Dim image() As Integer
 
        ' Create a new RMCLink object for the first controller.
        Dim rmc As RMCLink = RMCLink.CreateEthernetLink(DeviceType.RMC70, "192.168.0.22")
 
        ' Connect to the controller.
        rmc.Connect()
 
        ' Load the image from 'RMCImage.bin' and apply it to the controller.
        rmc.WriteImageFromFile(0, "RMCImage.bin")
 
        ' Disconnect from the controller.
        rmc.Disconnect()
    End Sub
End Module

 

C#

using System;
using RMCLinkNET;
 
namespace Example
{
    public class Program
    {
        static void Main()
        {
            int[] image;
 
            // Create a new RMCLink object for the first controller.
            RMCLink rmc = RMCLink.CreateEthernetLink(DeviceType.RMC70, "192.168.0.22");
 
            // Connect to the controller.
            rmc.Connect();
 
            // Load the image from 'RMCImage.bin' and apply it to the controller.
            rmc.WriteImageFromFile(0, "RMCImage.bin");
 
            // Disconnect from the controller.
            rmc.Disconnect();
        }
    }
}

 

Visual C++/CLI

using namespace System;
using namespace RMCLinkNET;
 
int main()
{
    array <int>^ image;
    // Create a new RMCLink object for the first controller.
    RMCLink^ rmc = RMCLink::CreateEthernetLink(DeviceType::RMC70, "192.168.0.22");
 
    // Connect to the controller.
    rmc->Connect();
 
    // Load the image from 'RMCImage.bin' and apply it to the controller.
    rmc->WriteImageFromFile(0, "RMCImage.bin");
 
    // Disconnect from the controller.
    rmc->Disconnect();
 
    return 0;
}

 

See Also

RMCLink.Interop .NET Assembly | RMCLinkNET Namespace | RMCLink Class | ReadImageToFile | ReadImage| WriteImage


Send comments on this topic.

Copyright (c) 2024 Delta Computer Systems, Inc. dba Delta Motion