Open NullRefer opened 1 year ago
It occurs when multiple threads use one plc instance with no lock. But the exception did not happen when I use ReadClassAsync
rather than self-defined RetrieveFromPlcAsync
which wraps the method.
It's not thread safe, none of the read/write methods are. You should choose a synchronization method that suits your usage.
It's not thread safe, none of the read/write methods are. You should choose a synchronization method that suits your usage.
I notice that the TaskQueue
was introduced into v0.12.0, and I thought it was designed to solve the concurrency problem.
It's not thread safe, none of the read/write methods are. You should choose a synchronization method that suits your usage.
I notice that the
TaskQueue
was introduced into v0.12.0, and I thought it was designed to solve the concurrency problem.
I'm sorry, you're absolutely correct. I had already forgotten about adding that.
I'll look into this, perhaps from the received message I can deduce something. As far as I can tell the TaskQueue
should prevent concurrent calls to the PLC, but maybe there's something I overlooked.
There is some concurrency problem when I use one plc instance in multiple threads. The typical one that I cannot figure out is that the bytes is out of order. That is, the bytes for Class A was filled in Class B! I'm planning to new one plc for each thread to avoid this.
Looking forward your reply~ Thanks!
S7NetPlus Version: 0.12.0
I have one plc instance in whole application, and open it at start of application. Then, I start to monitor up to 10 plc DataBlocks which is all the same structure with different threads. But sometimes (may be running for a day or two), it will throw exception which indicate the bytes read error as below:
S7.Net.PlcException: Received 38 bytes: '32-03-00-00-00-00-00-02-00-18-00-00-04-01-FF-04-00-A0-04-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00', expected 372 bytes.
And then the
byte[]
tostring
conversion fails with exception threw byS7String.cs
: https://github.com/S7NetPlus/s7netplus/blob/6aa0133081048131aa269d0d5b780ec7fe01028f/S7.Net/Types/S7String.cs#L40 https://github.com/S7NetPlus/s7netplus/blob/6aa0133081048131aa269d0d5b780ec7fe01028f/S7.Net/Types/S7String.cs#L49-L51the application can simplified as the code shows