fbarresi / Sharp7

Nuget package for Sharp7
MIT License
215 stars 75 forks source link

Is it possible to listen the PLC instead to have to read the data from it? #31

Closed ComptonAlvaro closed 1 year ago

ComptonAlvaro commented 1 year ago

Hello.

I would like to ask if this is possible. Perhaps I am wrong, but the examples that i have read in the documentation is that from the PC application that uses Sharp7, it can read data and write data, but it is this PC application which has to do it explicitly.

In my case, I would like the contrary, I would like that the PC application is listening the PLC and when the PLC decides to send data to the PC, then the PC could do something.

For example, if the an alarm happens, the PLC could notify to the PC and then, the PC receives the alarm and can do things like send an email to notify, save the alarm in a database and so on.

If this option it is not possible, then the PC has to read data from PLC periodically, that I guess it is a worse solution.

So, is it possible to send data from PLC to PC?

Thanks.

somapatrik commented 1 year ago

Not sure about Sharp7, but I would recommend Snap7 library which contains PLC server. When the server is running another PLC can send data to it like to any other PLC, you can subscribe events to that.

fbarresi commented 1 year ago

Hi Alvaro,

Please apologise my delayed answer.

The scenario you describe is actually not feasible under the plc get/put protocol (rfc1006). This is the protocol Sharp7 and all other similar plc libraries use.

For notification capabilities in the plc world you should better make use of opc ua or further event driven implementations.

For Sharp7 there is an additional library that make the polling transparent for you so that you can you can get a notification whenever data on a data block changes: visit Sharp7.Reactive for details.

Hope that helps.

Best regards, FB

ComptonAlvaro commented 1 year ago

Hello, Federico:

Never it is late to get an asnwer that let me learn more.

OPC UA seems a good alternative to explore, so I appreciate so much your comments.