Creating a Custom Instrument

We create a virtual instrument with a single user callable activity, HelloWorld, that sends an email to a prespecified address.

This instrument is written in C#, but any Common Language Infrastructure language could be used (


using System;
using System.Net;
using System.Net.Mail;


All virtual instrument interfaces have to be members of BaseInstrumentClass:

namespace Clarity {
  public class HelloInstrument : BaseInstrumentClass

SMTP Client

Our instrument will need to connect to an SMTP server to send email, here we’ll use gmail:

var smtp = new SmtpClient
  Host = "",
  Port = 587,
  EnableSsl = true,
  DeliveryMethod = SmtpDeliveryMethod.Network,
  UseDefaultCredentials = false,
  Credentials = new NetworkCredential(fromAddress.Address, fromPassword)

Mail Details

var fromAddress = new MailAddress("", "From Name");
var toAddress = new MailAddress("", "To Name");
const string fromPassword = "fromPassword";
const string subject = "Saying Hello       ";
const string body = "Hello World!";

Sending a Message

Now we create a method to define the activity of sending the email.

It needs to be tagged with the UserCallableMethod attribute, so that protocols can use it:

public void HelloWorld()
  var message = new MailMessage(fromAddress, toAddress)
      Subject = subject,
      Body = body

Finally, we close some brackets:



To finish we just compile the class:

csc /target:library HelloInstrument.cs


mcs -target:library HelloInstrument.cs

And place the resulting executable, HelloInstrument.dll, into the directory containing Clarity’s instrument manager.

The activity HelloWorld can then be included in protocols.