External functions

A SPEL+ program can use Declare statements to invoke external functions defined in a DLL. This mechanism has existed since earlier versions of RC+ and is subject to the constraint that DLLs must be 32-bit native.

The Extension Development Kit provides a bridge DLL that enables SPEL+ programs to call internal functions of the 64-bit extension assembly. This is the "External functions" extension point.

This "External functions" is invoked using the following format.

  • Insert the following Declare statement into your SPEL+ program.

    Declare CallExternal, "C:\EpsonRC80\ExternalFunctionBridge.dll", "CallExternal",(commandLine$ As String, ByRef output$ As String) As Int32
    
    • commandLine$ is a string containing the command line, which is the function name and arguments delimited by spaces.

    • output$ is a string variable that stores the output of the function

    • The return value is the result code of the function execution.

      • Zero (0) indicates normal completion (success)
      • Non-zero indicates an error
    • (Example)

      Int32 ret
      String output$
      ret = CallExternal("CubeRoot 10.0", ByRef output$)
      Print output$
      
      • 2.154434690031884 is displayed in the Run window.

To use this extension point, implement and export the delegate RCXExternalFunction and export the function name as metadata.

[Export(typeof(RCXExternalFunction))]
[ExportMetadata("Name", "CubeRoot")]
public RCXExternalFunction CubeRoot = (command, parameters) =>
{
    if (parameters.Count == 0 || !double.TryParse(parameters[0], out var input))
    {
        return ValueTuple.Create(RCXResult.BadArgument, string.Empty);
    }

    double output = Math.Cbrt(input);

    return ValueTuple.Create(RCXResult.Success, output.ToString());
};

This extension point allows SPEL+ programs to invoke various functions that can be implemented in an extension.

The following are built-in "External functions" that are always available in RC+ editions that support extensions.

  1. Execute external program (waits for completion and returns the first line of output)
    ret = CallExternal("Execute program [arg(s)]", output$)
    
  2. Start external program (does not wait for completion)
    ret = CallExternal("ExecuteNoWait program [arg(s)]", output$)
    
  3. Acquire the string corresponding to the CallExternal result code
    ret = CallExternal("ErrorStr Str$(retCode)" output$)
    
    • Int32 ret
      String output$
      ret = CallExternal("ErrorStr 0", ByRef output$)
      Print output$
      
      • "Success" is displayed in the Run window.

(For advanced users)

In addition, the bridge DLL provides functions for controlling the operation of external functions. (Requires a Declare statement similar to CallExternal)

  1. GetTimeout(ByRef timeout As Int32) As Int32
    • Acquires the CallExternal timeout period. The unit is milliseconds, and the initial value is 30,000.
  2. SetTimeout(timeout As Int32) As Int32
    • Sets the CallExternal timeout period. The unit is milliseconds.