The EpicsSharp project provides a C# implementation of the channel access protocol. This is the client part of the communication.
The client library is available in the following ways:
In Visual Studio, add the reference of the EpicsClient2 assembly to your project.
We try very hard to keep the client facing API simple. We sincerely hope you appreciate that effort and the brevity of the examples. (Really, that is all the code you need.)
This example will read the EPICS PV MY-EPICS-CHANNEL:VALUE, requesting it as a string, and print out the received value on the console. Please note, that for the client program, the call to channel.Get() is synchronous (i.e. blocking).
EpicsClient client = new EpicsClient();
var channel = client.CreateChannel<string>("MY-EPICS-CHANNEL:VALUE");
Console.WriteLine(channel.Get());
To use EPICS monitors (called events in channel access) use the event MonitorChanged:
class Program
{
static EpicsChannel<string> channel;
static void Main(string[] args)
{
EpicsClient client = new EpicsClient();
channel = client.CreateChannel<string>("MY-EPICS-CHANNEL:VALUE");
channel.StatusChanged += new EpicsStatusDelegate(channel_StatusChanged);
channel.MonitorChanged += new EpicsDelegate<string>(channel_MonitorChanged);
Console.ReadKey();
}
static void channel_MonitorChanged(EpicsChannel<string> sender, string newValue)
{
Console.WriteLine("Value: " + newValue);
}
static void channel_StatusChanged(EpicsChannel sender, ChannelStatus newStatus)
{
Console.WriteLine("Status: " + newStatus.ToString());
}
}
Tip: In Visual Studio, type += followed by 2 tabs. This will generate the skeleton callback function for you.
If your client needs to be on a different network than your server(s), e.g. if your office and machine networks are separated by firewalls, the EPICS default behaviour (a broadcast on the local network) will not work. You will have to use a channel access gateway. (Isn't it handy, the EpicsSharp project provides such a [gateway]?)
With our client library, using a gateway is easy. In fact, it is even possible (and not really any harder) use multiple gateways, in case you need to communicate with several networks.
For quick tests you can provide the gateway(s) in the code like this:
EpicsClient client = new EpicsClient();
client.Configuration.SearchAddress = "192.168.1.50";
Please note that you have to specify the gateway, before you create a channel.
You can also specify the gateway(s) to use via the .NET configuration mechanism, i.e. in you App.config or web.config XML files. Just add the key e#ServerList to your appSettings like this, and the client library will pick it up:
<appSettings>
<add key="e#ServerList" value="192.168.1.50"/>
</appSettings>
Using this approach has the following advantages, that if the address(es) of the gateways change, you do not need to rebuild your software and redistribute it.
The gateway to be used can be specified in the following ways (you're probably familiar with these already):
192.168.1.50:1234)192.168.1.50).mygateway.example.org:1234).mygateway.example.org).gw1.example.org:1234;gw2.example.org:9876;192.168.1.50).