ISISComputingGroup / lewis-ess

Let's write intricate simulators!
GNU General Public License v3.0
21 stars 19 forks source link

Create an adapter which communicates with API's #287

Closed dheeraj539 closed 3 years ago

dheeraj539 commented 3 years ago

We have many devices that communicate using the vendor specific API's. lewisa Is there a best way to do simulation of this type of devices using LEWIS?

mattclarke commented 3 years ago

Hi and welcome,

Interesting question, I think we need a bit more information:

Cheers,

Matt

dheeraj539 commented 3 years ago

Are you linking against the vendor's libraries in your code? Yes, I am linking the vendor libraries in my code. Do you know how the vendor libraries communication with the device? For example, via ethernet, COM etc? They communicate using the USB serial ports.

mattclarke commented 3 years ago

I assume the vendor library is closed source?

One way might be to wrap the vendor's API so that it could be communicated with over a network using a protocol like EPICS (https://epics.anl.gov/) and have your code call that. That should be possible with LeWIS as it supports EPICS; however, it would require you to wrap the vendor's library with pybind11 or to use ctypes. Then LeWIS could be swapped between talking to the real device and a simulator.

This might be a lot of work though as you would have to also make changes to your "client" code to communicate with EPICS.

dheeraj539 commented 3 years ago

I assume the vendor library is closed source? - Yes, it is.

Thank you for the suggestion. Could you please elaborate bit more(may be some sort of flowchart)? I also didn't get "vendor API(which works on USB interface) to communicate over network". The said device is a spectrometer. Thanks in advance

mattclarke commented 3 years ago

Screenshot 2020-09-25 at 09 08 43

Basically what you have now is a thick client, i.e. one program that has all the code in. My suggestion is to make it a client server application where the server consists of the Vendor API plus a wrapper that allows communication via TCP/IP. The client would have the rest of your code in it and would send commands and receive information from the server via TCP/IP.

This could be done just using plain network sockets or by making the server a webserver, or using EPICS.

mattclarke commented 3 years ago

LeWIS could be the server if you use EPICS and the wrapper could be written using pybind11 or ctypes. The client can remain as C++, but you would have to link against the EPICS libraries.