Skip to content

A wrapper of the base TcAdsServer class for the Beckhoff PLC ADS .NET assembly (4.2.169.0).

License

Notifications You must be signed in to change notification settings

signver/BeckhoffAdsServer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Overview

This is a wrapper of the Beckhoff TcAdsServer base class, allowing the usage of middlewares to extend the server functionalities.

General usage

namespace Poh.PLC.Beckhoff.ADS

The Server object is the go-to object to be instantiated in the main program. It converts the requests into the AdsContext object. The AdsContext is passed on to the middleware to be handled accordingly.


Server _server = new Server(_port, _name);
// Additional stuffs
// Add middlewares
// ...
_server.Start(); 

Middleware

namespace Poh.PLC.Beckhoff.ADS.Extensions

Extend the abstract MiddlewareBase class or implement the IMiddleware interface.

MiddlewareBase

When implementing the MiddlewareBase class, override the bool Capture(AdsContext) and void Bubble(AdsContext) method. Middlewares can be chained together, and the chain propagation can be stopped by returning true in the Capture method.

Sample middleware implementation


class MyMiddleware : MiddlewareBase {
 public override void Bubble(AdsContext context) { 
  //Do stuff
  //Otherwise
  return;
 }
 public override bool Capture(AdsContext context) { 
  if (context.Request.Command == AdsCommand.Read && context.Request.IndexGroup == 0x1000) {
   if (context.Request.IndexOffset == 0x0001 && context.Request.Length == 0x0003) {
    context.Reponse.Error = Error.ApiError;
   } 
   else {
    context.Reponse.Error = Error.NoError;
    context.Response.Payload = new byte[] {0,1,2};
   }
   return true; //To prevent further propagation down the middleware chain
  }
  return false: 
 }
}

Sample middleware usage


Server _server = new Server(_port, _name);
_server.Use(new MyMiddleware);
// ...
_server.Start();

Middleware Chaining

//...
_server.Use(MiddlewareA);
_server.Use(MiddlewareB);
_server.Use(MiddlewareC);
//...

The AdsContext will be processed MiddlewareA.Capture → MiddlewareB.Capture → MiddlewareC.Capture → MiddlewareC.Bubble → MiddlewareB.Bubble → MiddlewareA.Bubble

About

A wrapper of the base TcAdsServer class for the Beckhoff PLC ADS .NET assembly (4.2.169.0).

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages