Download the client library here (client directory):
https://sourceforge.net/p/epicssharp/code/
Add the reference of the EpicsClient2 assembly to your project.
To use it:
EpicsClient client = new EpicsClient(); client.Configuration.SearchAddress = "255.255.255.255:5064"; channel = client.CreateChannel<string>("MY-EPICS-CHANNEL:VALUE"); Console.WriteLine(channel.Get());
the client.Configuration.SearchAddress can be left out and it will then use the default EPICS search port on the local broadcast address. You can however specify one or more search addresses separated by semi-colons.
To use monitors instead of get use the event MonitorChanged:
class Program { static EpicsChannel<string> channel; static void Main(string[] args) { EpicsClient client = new EpicsClient(); client.Configuration.SearchAddress = "129.129.130.87:5432"; channel = client.CreateChannel<string>("ADG1:IST1:2"); 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()); } }
type += and then 2 tabs which will generate for you the skeleton callback function.
Download the server library here (server directory):
https://sourceforge.net/p/epicssharp/code/
Add the reference of the CaSharpServer assembly to your project.
To use it:
class Program { static int counter = 0; static CAIntRecord intRecord; static CAIntArrayRecord intArray; static CAStringRecord strRecord; static void Main(string[] args) { CAServer server = new CAServer(IPAddress.Parse("127.0.0.1"), 5064, 5064); intRecord = server.CreateRecord<CAIntRecord>("PCTOTO2:INT"); intRecord.PrepareRecord += new EventHandler(intRecord_PrepareRecord); intRecord.Scan = CaSharpServer.Constants.ScanAlgorithm.HZ10; intArray = server.CreateArrayRecord<CAIntArrayRecord>("PCTOTO2:ARR",1000); for (int i = 0; i < intArray.Length; i++) intArray.Value[i] = i; strRecord = server.CreateRecord<CAStringRecord>("PCTOTO2:STR"); strRecord.Value = "Default"; Console.ReadLine(); } static void intRecord_PrepareRecord(object sender, EventArgs e) { counter++; intRecord.Value = counter; } }
The constructor defines on which IP and on which ports the CA server must listen. You may run multiple servers on the same machine as long as the TCP port is different each time while sharing the same UDP port. However in this configuration you will reach the servers only while broadcasting the search request.
After the creation of the server object, simply instantiate any number of epics variables you want through the call of server.CreateRecord("channel-name")
TType must be derived of CARecord.
You can either set the values directly to the epics variables or on callback at the refresh rate you define.