Ocf Client (OcfApiClient)’s cheat sheet

Welcome on the Ocf Client (Ocf Api)’s Cheat Sheet. This post will help you to get started Ocf Client.

You can also get the PDF here.

Here is the contents:

  1. Ocf Clients for Embedded
    1. Create a client for embedded system (UDP)
    2. Create a client for embedded system (COM)
  2. Ocf Clients for .NET
    1. Create a native client for .NET application
    2. Create a secure native client for .NET application (communication with AES encryption)
  3. Ocf Clients for ADS PLC
    1. Create an ADS client for PLC application
  4. Retrieve data thanks to Ocf
  5. Register the licenses

Let’s begin!

Ocf Clients for Embedded

Create a client for embedded system (UDP)

Prototype :
public static dynamic CreateOcfEmbeddedUdpClient(string hostName, int port, int timeout);

Sample :
dynamic client = OcfApi.CreateOcfWcfClient("127.0.0.1", 10000, 200);

Create a client for embedded system (COM)

Prototype :
public static dynamic CreateOcfEmbeddedComClient(string portName, SerialDataBaudRate rate, int timeout, SerialDataLength length = SerialDataLength.DL8, Handshake handShake = Handshake.None, Parity parity = Parity.None,  StopBits stopBits = StopBits.One);

Sample :
dynamic client = OcfApi.CreateOcfEmbeddedComClient("COM5", SerialDataBaudRate.BR19200, 1000);

Ocf Clients for .NET

Create a native client for .NET application

Prototype (Udp) :
public static dynamic CreateOcfNativeUdpClient(string
   hostName, int port, int timeout);

Prototype (Tcp) :
public static dynamic CreateOcfNativeTcpClient(string
   hostName, int port, int timeout);

Create a secure native client for .NET application (communication with AES encryption)

Prototype (Udp) :
public static dynamic CreateOcfNativeUdpEncryptedClient(
   string hostName, int port, string passphrase, int timeout);

Prototype (Tcp) :
public static dynamic CreateOcfNativeTcpEncryptedClient(
   string hostName, int port, string passphrase, int timeout);

Ocf Clients for ADS PLC

Create an ADS client for PLC application

Prototype (ADS) :
public static dynamic CreateOcfAdsClient(string netId, int port, int timeout = DefaultTimeOut)
Sample :
dynamic client = OcfApi. CreateOcfAdsClient(   "192.168.10.12.1.1", 801);

Retrieve data thanks to Ocf

Get a child of the remote object model

dynamic axisX = client.Robot.AxisX;

Reach a property of the remote object model

In C#:
Console.WriteLine("AxisX :", client.Robot.AxisX.Position);

client.Robot.AxisX.Position = 100;

In Xaml :
<GroupBox Header="{Binding Client.Name}" Margin="5">

Invoke a method of the remote object model

client.PowerEnable();

Manage communication errors with Ocf

Define handler on unhandled exceptions :
Application.Current.DispatcherUnhandledException +=   CurrentDispatcherUnhandledException;

Manage OcfException globally :
private void CurrentDomainUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
   if (e.Exception is OcfException)
       ShowException(e.Exception as Exception);
}

Register the licenses

Register a license to create a server/client Ocf

Prototype :
public static void RegisterLicense(string companyName, string key)

Sample :
OcfApi.RegisterLicense("CompanyName", "XXXX-XXXX-XXXX-XXXX");
Share on LinkedInShare on FacebookTweet about this on TwitterShare on Google+Email this to someone

 

Leave a Reply