Auto Run your own plugin (.net dll) in Comm Operator

Comm Operator v4.5 supports plug-in (.net dll) in Auto Send function. You can write your own plug-in and add it to Auto Send Rule.

Download Comm Operator v4.5 

Comm Operator Interface

Here are the steps to add Plug-in (.net dll) to Auto Send Rule in Comm Operator.

1. Click menu [Edit]->[Auto Send] to open the “Auto Send Rule Setting” dialog.

Auto Send Rul Setting Dialog

2. Click “New” button to open “Select Rule Type” dialog.

Select Rule Type_Plugin

3. Select “Plug-in (.net dll)” and Click “OK”. The “Auto Send Plugin” setting dialog will be shown.

Auto Send Plugin Dialog 

4. Select the path of your plugin dll and plugin name in that dll.

Tip:

  • If the checkbox”Always” is selected, the plugin will be called again and again. Otherwise, it won’t be called once it is matched.
  • Comm Operator comes with a demo plugin called “EchoPlugin.exe”. The file can be find in Comm Operator’s install folder. The default folder is “C:\Program Files\Serial Port Tool\Comm Operator\” or “C:\Program Files(x86)\Serial Port Tool\Comm Operator\” for 64 bits OS.

5. Click OK to finish adding plugin to Auto Send Rule.

How does it work?

Comm Operator process the “Auto Send” in a seperate thread. The plugin will be called in auto send thread loop. The plugin has to be the type of IAutoSendPlugin. The IAutoSendPlugin type is defined in IAutoSendPlugin.dll, which can be found in Comm Operator’s install folder. The plugin is load dynamically. User need implement the ProcessEvent method to process the data. The method is called by Comm Operator in auto send thread loop. It passes the event type and data. The event type are defined in IAutoSendPlugin too.

Here is the sample code of EchoPlugin. Down the EchoPlugin File here.

/// <summary>
/// EchoPlugin is a sample of implement IAutoSendPlugin.
/// EchoPlugin will send the same data back
/// </summary>
public class EchoPlugin : IAutoSendPlugin
{
    /// <summary>
    /// Implement the interface of processEvent
    /// </summary>
    /// <param name="eventType">Event type</param>
    /// <param name="data">data for that event. Only ReceivedData event has data</param>
    /// <returns></returns>
    public byte[] ProcessEvent(EventType eventType, byte[] data)
    {
        byte[] returnData = null;
        if (eventType == EventType.DataReceived)
        {
            if(data != null)
            {
                if (data.Length > 0)
                {
                    returnData = new byte[data.Length];
                    Array.Copy(data, returnData, data.Length);
                    return returnData;
                }
            }
        }
        return returnData;
    }

    /// <summary>
    /// Implement this interface if there is setting dialog needed for this
    /// for future usage
    /// </summary>
    /// <param name="parent"></param>
    /// <returns></returns>
    public bool Setting(Form parent)     // call setting dialog
    {
        return false;
    }

    /// <summary>
    /// method of if the setting dialog available, for future usage
    /// </summary>
    /// <returns></returns>
    public bool IsSettingAvailable()      // if setting is available
    {
        return false;
    }

}

See Also

Run Perl Script in Auto Send

Run Python Script in Auto Send

Run Ruby Script in Auto Send

Run User Exe in Auto Send