Posts tagged with 'Interfaces'

Analyse Interfaces

All Plugins have the following two Interfaces for direct calls from the outside.

///<summary
  /// Analysis interface for scripts and plugins.
 ///</summary

→ The Header from the first Interface.

public interface IPCBIAnalysis {
   ///<summary
  /// The name of this analysis to identify it with the settings.
  ///</summary
  string Name { get; }

///<summary
  /// The readable name of this analysis
  ///</summary
  string Title { get; }

///<summary
  /// The path to the results directory of this analysis relative to the job path
  ///</summary
  string ResultsFolderName { get; }

///<summary
  /// The preview icon for this analysis
  ///</summary
  Icon PreviewIcon { get; }

///<summary
  /// Set if the file preview should show if results are available
  ///</summary
 Set if the file preview should show if results are available

///<summary
  /// Create a instance of rules to define the default standard rules.
 ///</summary
 PCBI.Automation.Rules.RulesContainer GetStandardRules();
 // void AddToUpdateProgress(PCB_Investigator.PCBIWindows.PCBIWorkingDialog working, int minValue, int maxValue);
 // bool Execute(string ResultFilePath);

 
For more comfort there is the IPluginAnalysis, which provides even more functions:

public interface IPluginAnalysis: IPlugin, IPCBIAnalysis{

 ///<summary
   /// 
  ///</summary
  ///
void AddToUpdateProgress(PCB_Investigator.PCBIWindows.PCBIWorkingDialog working, int minValue, int maxValue);


bool Execute(IAnalysisParams analysisParams);
bool Execute(string resultFilePath); }

The script is allowed to increment

values between minValue and maxValue.

Remote Control

The Remote Control Server gives you options to create your own Routs, Instructions and scripts to control PCB-Investigator from outside.

In PCB-Investigator you have three buttons:

Remote Controls Server Menu in PCB-Investigator

"Start Server" activate the remote control 

"Stop Server" deactivate the remote control

"Server Settings" shows the settings dialog:

remote control settings dialog

Here you can configurate the comunication port and timeout, you can also manage the available scripts.

 

 

How to Add an Instruction

What are instructions?

Instructions are commands for PCB-Investigator that are queued and executed sequentially. This means they will be executed in the order that they were sent in.
Instructions can be used to automate tasks, such as loading a file, running a script, or exporting data. They are especially useful for automating long-running tasks, because you can queue them and check the status later.

How do I add an instruction?

Adding new available instructions

To add an instruction using the PCBI_RemoteControlServer.PCBI_Connection.AddInstruction method, follow these steps:

  1. Understand the Method Signature:
    public void AddInstruction(string name, Func<Entities.RequestDto, Task<Entities.InstructionResult>> handler, string description = "")
    • name: A string representing the name of the instruction.
    • handler: A Func delegate that takes an Entities.RequestDto and returns a Task<Entities.InstructionResult>. This is the function that will be executed when the instruction is called.
    • description: An optional string providing a description of the instruction.
  2. Create the Handler Function:

    The handler function should match the signature Func<Entities.RequestDto, Task<Entities.InstructionResult>>. Here is an example of how to create such a function:

    public async Task<Entities.InstructionResult> MyInstructionHandler(Entities.RequestDto request)
    {
        // Your logic here
        var result = new Entities.InstructionResult();
        // Populate result based on the request
        return await Task.FromResult(result);
    }
  3. Add the Instruction:

    Use the AddInstruction method to register your new instruction. Here is an example:

    
                        PCBI_RemoteControlServer.PCBI_Connection connection; // This is a placeholder. Get the currenly loaded Plugin instance.
                        connection.AddInstruction("MyInstruction", MyInstructionHandler, "This is a sample instruction.");
  4. Example Usage:

    Here is a complete example that demonstrates how to add an instruction:

    
    using System;
    using System.Threading.Tasks;
    using PCBI_RemoteControlServer;
    
    public async Task<Entities.InstructionResult> MyInstructionHandler(Entities.RequestDto request)
    {
        var result = new Entities.InstructionResult();
        // Implement your logic here
        return await Task.FromResult(result);
    }
    
    public void RegisterInstruction()
    {
        PCBI_RemoteControlServer.PCBI_Connection connection; // This is a placeholder. Get the currenly loaded Plugin instance.
        connection.AddInstruction("MyInstruction", MyInstructionHandler, "This is a sample instruction.");
    }
                    

Adding an instruction to the queue

Once an instruction is made available, it can be queued with the HTTP request POST /instructions described on the homepage.

How to Add a Script

What are scripts?

Scripts are sequences of instructions that automate tasks in PCB-Investigator. They can be used to perform complex operations, such as data analysis, file manipulation, and more.

How do I add a script?

Scripts can be added in PCB-Investigator in the `URI Editor` of this plugin.
There you will also find an example script.

Executing a script

Once a script is registered, it can be executed with the script-instruction.