One of the tools that comes with K2 blackpearl is SmartObjects, and they have a brilliant feature: they can talk to endpoint assemblies (DLLs). That opens K2 up to a whole world of possibilities.
So I spent an afternoon searching the internet for APIs, starting with .NET APIs to make things easier, and came across an excellent community project on CodePlex, the Lego Mindstorms .NET API. With that in hand I started building an endpoint assembly that would let K2 talk to Lego. How cool is that?
Creating endpoint assemblies is easy enough. Your methods need to be public and static, like in the example below. (I’ll publish a step-by-step guide on how to do this.)
public async static void MoveBackwards(int Power)
{
try
{
brick.BatchCommand.TurnMotorAtSpeedForTime(OutputPort.B, Power, 1000, false);
brick.BatchCommand.TurnMotorAtPowerForTime(OutputPort.C, Power, 1000, false);
brick.BatchCommand.PlayTone(50, 1000, 500);
await brick.BatchCommand.SendCommandAsync();
}
catch (Exception ex)
{ }
}All you need to do is build the project, drop any third-party DLLs into the service broker folder on your K2 server, and register your project’s DLL with the ServiceObject Tester. This exposes your methods as service objects, which you can use to build SmartObjects for your SmartForms and workflows.
The source code for the endpoint assembly (K2 Lego Robot) was linked from the original post, along with a video of K2D2 in action at DevWeek 2014.