is it possible to to communicate with OPC server from multiple threads in same application?

2.4k Views Asked by At

I am working on an automation project where I need to handle 21 fixed mount bar-code scanners in parallel(i.e. all the scanner will be running all the time) to achieve that I am using multi-threading. Here each thread will handle one bar-code scanner.

Now, I want to update the scanned data in P.L.C (DB/Memory Blocks/Tags) by using O.P.C. So, I wanted to know is it possible to update P.L.C values by using O.P.C client in a multi-threaded application.
I am using Siemens P.L.C ( Model :- CPU 315-2 PN/DP, step 7, 300 series).

I would also like to know whether I should go with O.P.C Server or LibNoDave. there will be around 300 tags (Data blocks in P.L.C) which I need to read and check for Data Change event.

2

There are 2 best solutions below

0
On

Better keep your architecture as simple as possible and avoid lots of threads, multithreading can unnecessarily complicate things and there is also a performance price to pay in case the threads need to synchronize. Since you have one OPC server and multiple threads connecting to it you will have to be careful not having the threads interfere with each other. If I were you I would instead have one thread that sets up a subscription to the OPC server with all the barcode scanners. Then another thread to monitor that thread to see if it is still working.

2
On

The short answer is Yes, but there is more to it, the link provided by A Murray is good read. You should also consider whether going multi-threaded can truly bring you any speed benefit. You easily get through many thousands of data changes per second with OPC-DA and just a single thread - do you really need more threads?