AN IND 1 017 - PanelControlPlugIn
AN IND 1 017 - PanelControlPlugIn
Version 1.4
2018-02-28
Application Note AN-IND-1-017
Table of Contents
1.0 Overview
The use of Vector's own controls is described in the online help of the Panel Designer. This document
expands the description to include the integration of the customer's own plug-in controls in the Panel
Designer.
The following sections describe the integration of the customer's own plug-in controls in the Panel
Designer.
Many examples are given as source text in the descriptions and in the appendix. The locations in
these source texts that require adaptation (because they are user-specific) are marked with =====>
and <=====.
2.0 Requirements
CANoe/CANalyzer since version 8.1 SP4 or CANape since version 14 is installed.
A development environment for .NET is present.
In this document, the procedure is described using Microsoft Visual Studio 2010® with C#
programming language.
3.0 Instructions
2. Use the Add Reference… shortcut menu command in the Solution Explorer (References) to
add a reference to the DLL Vector.PanelControlPlugin.dll in
directoryExec32\Components\Vector.PanelControlPlugin\. Select the subdirectory with the
current version number, e.g., 1.0.0.0.
3. Configure Copy Local to False and Specific Version to True.
4. The following References are also needed for creating the plug-in control library and the plug-
in controls:
> System
> System.Data
> System.Drawing
> System.Windows.Forms
// =====>
supportedProperties.Add("MyTitle");
supportedProperties.Add("MyBorderStyle");
// <=====
return supportedProperties;
}
}
A plug-in control that supports one or both of these properties returns true in the associated properties
SupportsPropertyBackColor and. SupportsPropertyForeColor and implements the corresponding
property for setting the background or foreground color.
/// <summary>
/// Property to set or get the background color of the plugin control.
/// This method can called via CAPL, to control the display of controls.
/// </summary>
public Color ControlBackColor
{
// =====>
get
{
return mMyUserControl.BackColor;
}
set
{
mMyUserControl.BackColor = value;
}
// <=====
}
A plug-in control that does not support one or both of these properties returns false in the associated
properties SupportsPropertyBackColor and. SupportsPropertyForeColor and makes available a
dummy implementation of the properties in ControlBackColor andControlForeColor:
public Color ControlBackColor
{
// dummy implementation, if the plugin control does not support changing the
// background color:
get; set;
}
…
}
/// <summary>
/// Actions which are necessary, when a new value is received from CANoe.
/// The received value is in this-value and must be sent to the plugin control.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void OnRxValue(object sender, EventArgs e)
{
try
{
// Value.SymbolDataType depends on the symbol data type of the assigned
// symbol. It is given from the CANoe database and must not be changed.
switch (SymbolValue.SymbolDataType)
{
case ExchangeSymbolDataType.Long:
// =====>
// display Value.LongValue in the plugin control
mMyControl.OnRxValue(SymbolValue.LongValue);
// <=====
break;
case ExchangeSymbolDataType.Double:
// =====>
// display Value.DoubleValue in the plugin control
mMyControl.OnRxValue(SymbolValue.DoubleValue);
// <=====
break;
default:
break;
}
}
catch (System.Exception)
{
}
}
// =====> ONLY FOR TX: necessary only, if the plugin control shall send values
/// <summary>
/// Actions which are necessary, when a new value shall be sent to CANoe.
/// The sent value must be written to this.Value.
/// </summary>
3.3.5 Serialization/deserialization
The properties of a plug-in control are serialized in the Panel file and are thereby available for loading
in CANoe or in the Panel Designer. The serializing of the properties of a plug-in control must be
implemented in the SerializeSupportedProperties method. The deserialization is implemented in the
DeserializeSupportedProperties method.
Ensure that these methods are compatible with each other and that additions are downward
compatible, i.e., that new properties are always added at the end and, if necessary, ignored.
The toolbox bitmap of the plug-in control is set via the ToolboxBitmap attribute of the class. A very
specific syntax is required for this so that the bitmap is also found later in the resource. Integrate the
bitmap in the following way:
// The file must be found in the subdirectory "Resources" of the project
// Set Build Action of the bmp-file to "Embedded Resource"
[ToolboxBitmap(typeof(resxfinder), "Demo.Resources.ToolBox_ControlA.bmp")]
public class MyControlImplA : IPluginPanelControl
The resxfinder class that is used in the ToolboxBitmap attribute must exist once outside any
namespace in the project:
public class resxfinder
{
// This is a dirty workaround for a bug in 'GetImageFromResource'.
// Use the type of this this class in the 'ToolboxBitmap' Attribute and
// NOT the Control class. The second parameter is the bmp name with
// the DEFAULT(!) namespace of the assembly (see project settings) and the
// relative directory
// where the bitmap can be found.
// Class 'resxfinder' must be within this assembly.
You can then use the plug-in controls for the design of your panel. If you want to edit the properties of
the plug-in controls in the Properties Window, you may not see everything at first. This is because only
the most important properties of a plug-in control are displayed at first. If you want to see all
properties, select in the toolbar of the Properties Window.
You can link the plug-in control with a signal, variable, or diagnostic parameter, as usual. Integer- and
Float-type symbols are supported at present.
3.6 Exceptions
An unclean implementation of the plug-in control can cause CANoe to crash. This is the case if
uncaught exceptions occur in event handlers (e.g., OnLoad or OnPaint) or in the properties. For this
reason, it must be ensured that all exceptions are caught within the plug-in control DLL with a try-catch
block.
4.0 Attachment
4.1.1 IPanelControlPluginLibrary
public interface IPanelControlPluginLibrary
{
/// <summary>
/// Returns the name of the plugin control library as it shall be shown in the
/// toolbox of the Panel Designer
/// </summary>
string LibraryName { get; }
/// <summary>
/// Returns a bitmap (16x16), which shall be shown in the toolbox of the
/// Panel Designer.
/// Return null, if no image shall be shown. In this case, the name of the
/// library is shown.
/// </summary>
Image LibraryImage { get; }
}
4.1.2 IPluginPanelControl
public interface IPluginPanelControl
{
/// <summary>
/// This method is called, when the panel is loaded in CANoe/CANalyzer.
/// </summary>
/// <param name="value">Object, which is used to transmit a symbol value during
/// the measurement. </param>
void Initialize(IExchangeSymbolValue value);
/// <summary>
/// Returns the name of the plugin control, which is shown in the toolbox of
/// the Panel Designer.
/// </summary>
string ControlName { get; }
/// <summary>
/// Returns the control, which actually shall be shown in the panel.
/// </summary>
Control ExternalControl { get; }
/// <summary>
/// This property is for exchanging the symbol value.
/// </summary>
IExchangeSymbolValue SymbolValue { get; set; }
/// <summary>
/// Returns the list of property names, which are supported by the plugin
/// control, i.e. the list of properties, which can be configured in the
/// property grid of the Panel Designer.
/// </summary>
IList<string> SupportedProperties { get; }
/// <summary>
/// Returns true, if the plugin control can change the background color,
/// otherwise false.
/// </summary>
bool SupportsPropertyBackColor { get; }
/// <summary>
/// Returns true, if the plugin control can change the foreground color,
/// otherwise false.
/// </summary>
bool SupportsPropertyForeColor { get; }
// if the following properties are not needed, they may have a dummy
// implementation (doing nothing)
/// <summary>
/// Property to set or get the background color of the plugin control.
/// This method can called via CAPL, to control the display of controls.
/// Provide a dummy implementation (do nothing), if the plugin control cannot
/// change its background color.
/// </summary>
Color ControlBackColor { get; set; }
/// <summary>
/// Property to set or get the foreground color of the plugin control.
/// This method can called via CAPL, to control the display of controls.
/// Provide a dummy implementation (do nothing), if the plugin control cannot
/// change its foreground color.
/// </summary>
Color ControlForeColor { get; set; }
/// <summary>
/// Property to enable or disable the plugin control.
/// This property is called, when the DisplayOnly property is set in the
/// property grid of the Panel Designer.
/// This method can called via CAPL, to control the display/behavior of
/// controls.
/// Provide a dummy implementation (do nothing), if the plugin control cannot
/// be disabled/enabled, e.g, when the plugin control is a display-only
/// control.
/// </summary>
bool Enabled { get; set; }
/// <summary>
/// Property to set the plugin control visible or invisible.
/// This method can called via CAPL, to control the display of controls.
/// Provide a dummy implementation (do nothing), if the plugin control cannot
/// be hidden.
/// </summary>
bool Visible { get; set; }
/// <summary>
/// Serializes all supported properties and returns the serialization string in
/// the out parameter.
/// </summary>
/// <param name="serializationString">serialized properties</param>
/// <returns>true, if serialization was successful, otherwise false</returns>
bool SerializeSupportedProperties(out string serializationString);
/// <summary>
/// Deserializes the supported properties from the given string.
/// </summary>
/// <param name="serializationString">serialized properties</param>
/// <returns>true, if deserialization was successful, otherwise false</returns>
bool DeserializeSupportedProperties(string serializationString);
4.1.3 IProvidesSupportedDataTypes
4.1.4 IExchangeSymbolValue
/// <summary>
/// Enumeration contains the data types, which are supported for plugin
/// controls
/// </summary>
[Flags]
public enum ExchangeSymbolDataType
{
ByteArray = 8,
Double = 2,
DoubleArray = 0x20,
DoubleArray2D = 0x40,
DoubleArray3D = 0x80,
Long = 1,
LongArray = 0x10,
LongLong = 0x200,
String = 4,
Struct = 0x100,
Unknown = 0
}
/// <summary>
/// Class for the exchange of a symbol value from and to CANoe/CANalyzer.
/// </summary>
public interface IExchangeSymbolValue
{
/// <summary>
/// data type of the assigned symbol (i.e. of the signal, variable,...)
/// </summary>
ExchangeSymbolDataType SymbolDataType { get; }
long LongValue { get; set; }
double DoubleValue { get; set; }
byte[] ByteArray { get; set; }
string StringValue { get; set; }
int[] LongArray { get; set; }
double[] DoubleArray { get; set; }
namespace Demo
{
public class ControlLibraryImpl : IPanelControlPluginLibrary
{
#region IPanelControlPluginLibrary Members
/// <summary>
/// Returns the name of the plugin control library as it shall be shown in
/// the toolbox of the Panel Designer.
/// </summary>
public string LibraryName
{
get
{
// =====>
return "Demo Library Name";
// <=====
}
}
/// <summary>
/// Returns a bitmap (16x16), which shall be shown in the toolbox of the
/// Panel Designer.
/// Return null, if no image shall be shown. In this case, the name of the
/// library is shown.
/// </summary>
public System.Drawing.Image LibraryImage
{
get
{
// =====>
return Properties.Resources.LibraryImage;
// <=====
}
}
#endregion
}
}
5.0 Trademarks
All mentioned names are either registered or unregistered trademarks of their respective owners.
6.0 Contacts
For a full list with all Vector locations and addresses worldwide, please visit http://vector.com/contact/.