Working with Atlas Copco Open Protocol
Tags: csharp, protocol, atlas, copco
Published: 2020-04-20 02:25:39

### Open protocol is a communication protocol created by Atlas Copco which defines the way we have to communicate with Atlas Copco tightening controllers
---
Years ago I had the opportunity to work with Atlas Copco Open Protocol and it was cool and funny to create and manipulate the controllers with it.
I could create applications that exchanges TCP/IP packages to operate it, such as **setting up a Job/Parameter Set, retrieving old tightenings or receiving them in real time**, as many other functions that are available inside these tightening controllers which Open Protocol help us to interact with them.

Although it was funny, it was a little troublesome too. Parsing all those dozens or even hundreds of bytes was a pain in the *** (head 😂), a bit stressful I should say.

By that time, I’ve noticed the packages structure and that could exists a library that does all the parsing, such as a .jar or .dll. And someday, while I was at home, I asked myself:

> Have someone ever thought about creating a library to handle all these packages?

So I started searching if there was a library out there in any programming language. For my surprise, **I have found NONE**.
All I had was the docs and a Power Focus tightening controller…

Few days later I committed to build one! I knew it would be a big effort, but why not build something to help me and other people out there??

# **The Open Protocol Interpreter**

> Then the open protocol interpreter was born!

What I’ve done was to take their documentation and try compile into a single **C# library** which I called **“Open Protocol Interpreter”** _(currently on version 3.0.0)_.

In a few words: **It takes the received package and translates/”beautifies” it to an object which is better to work with. The inverse can be done too!**

It took a lot of effort to build and test it, but it’s done and working!!

---

Well, there is much about it but I won’t write how it fully works at it’s core, since it is already written on [my article at CodeProject](https://www.codeproject.com/Articles/1190932/The-Atlas-Copco-Open-Protocol-Interpreter). Please check it out for more information.
Also the project is open source and available at [GitHub](https://github.com/Rickedb/OpenProtocolInterpreter).

# **Working with Open Protocol**

Cool, we now have a lib to make our life easier, but how does open protocol works? How do I communicate with my controller without the lib?

We should start by sending a **MID 0001** to our controller, which will be an **ASCII** string like this: 00200001003_________
> Consider “_” as a blank space

But what does that package means? If you haven’t take a look at their documentation I will explain a little of it to you, first of all, this is only our header data, our Data Field section is right after the 20 characters.
For Mid 0001 there is no Data Field section, so there is only the header.

Understanding it:

* 0020 : Package total size (consider blank spaces);
* 0001 : Mid number, this means you’re sending a MID 0001;
* 003 : Revision, this means you’re saying to the controller you want to work with them using revision 3.

The blank spaces does have a meaning, but they can be filled or not, depending if the MID needs it specified or not, which I recommend you to take a look at their [docs here](https://github.com/Rickedb/OpenProtocolInterpreter/blob/master/docs/OpenProtocol_Specification.pdf).

The controller can respond you with a **MID 0002** or **MID 0004**.
**MID 0004 means that some error has occurred while processing the received mid**, in case of Mid 0001 we have 2 possible errors: “Client already connected” or “Mid revision unsupported”. Otherwise it will respond you with a MID 0002, Acknowledging you that he accepted your connection.

This is the very beginning of a communication with a controller, from now on you can send any other mid.

# **A real example**

A real sequence of package exchanging would be like:
{% gist https://gist.github.com/Rickedb/ec67ed7d6fe36faee81f206a91405e73 %}

_Consider **C** as the controller and **I** as integrator/you._