WEB API in PLC Next

Hi everybody! I have a question in connection with a request from a client. And yes, I know that I’m getting ahead a bit with this question before the final release in November but I like to be prepared. The client wants to read barcodes on its products. Not a big problem normally. I would run it via a SQL DB and done with the job. I have always tried to have a clear border between the PLC and IT side. Now time have changed and we will see the lines between the PLC and IT side blur. But here is the interesting part for me - he wants the data via an Web API (REST base). That is something new for me and I would like to get your input. Has someone tried that before or is working on a solution and would like to share some info about it? Peter

Hello Peter, Lucky that your customer has come to you, since PLCnext is the best choice for industrial communications via a REST interface. :wink: Can I ask - do you need to provide the REST interface from your PLC, or does your PLC need to use the REST interface from an external provider? In another post, Marcel recommended using the C+±REST-SDK (Codename “Casablanca”) from Microsoft. If you’re able to give more details about your customer’s requirements, I can check if we have any suitable samples. - Martin.

Hi Martin, we have to scan products via a barcode scanner. The code is then sent to the providers WEB API (warehouse management). But internally we have read a part of the barcode that defines the location in the warehouse. That will say, if the communication is interrupted, we still can bring the products to the right location. Also is it important, that we can save scanning’s in case the communication is down and send those scanning’s when the communication is up again. And yes, when I got the request, I did think on the PLC Next system. I would use an AXC 2152 controller for the job. But like I mentioned before, WEB API is not something I have been working with before. But with PLC Next, the lines between the PLC and IT programming get blurred. I could imagine, that we will see more and more of those application and requests in the future. We just have to make sure, we are ready for the job. If that means, we have to go to school again - so be it. Personally I find it interesting and gives us more options. But the start is always a struggle. I was thinking that we may have some people on the forum that have some applications like this in the planning and could give me a hint on how to start. And I will contact our local support here in Denmark to. I think Dan would like to have a look at this too. He wasn’t in the office the last few days but I will have a chat with him when he is back. For the C++ option: No go, we work only in C#. If you have to handle to many programming languages, things get interesting in a hurry. We have used C# before for our SQL database systems and that worked well. Always better to stick to what you know. Peter

Hi Martin, is it possible to give you a call today?

Answered privately, but the Community may be interested in this answer: A common way of accessing REST services from C# is by using the HttpClient class in the System.Net.Http namespace. However, unfortunately this class is not supported in the current version of the eCLR. There are at least two other options: a) Because HTTP is built on TCP, it should be possible to send HTTP requests to the REST service using raw TCP sockets, either directly from IEC 61131 code, or from a C# function. b) An external “service” could be developed to run on the non-real-time part of the PLC, and then the real-time program could use this as a gateway to the REST service. If C# must be used for this external component, then .NET Core would also need to be installed.