我将ModbusClient 用于多线程环境的时候,调用ModbusClient 的ReadHoldingRegisters 方法时,获取到的值有时候是错误的。
(en:When I use ModbusClient in a multi-threaded environment, I sometimes get the wrong value by calling ModbusClient's ReadHoldingRegisters method.)
错误的(The wrong):
正确的(The correct):
当我的代码里对ModbusClient 使用lock关键字,才确保了每次结果是正确的。(en: When I use the 'lock' keyword on ModbusClient in my code, I make sure the result is correct every time.)
Modbus is client/server communication and doesn't require multithreading, as multiple master threads will end up trying reading or writing concurrently.
我将ModbusClient 用于多线程环境的时候,调用ModbusClient 的ReadHoldingRegisters 方法时,获取到的值有时候是错误的。 (en:When I use ModbusClient in a multi-threaded environment, I sometimes get the wrong value by calling ModbusClient's ReadHoldingRegisters method.) 错误的(The wrong):
正确的(The correct):
![image](https://user-images.githubusercontent.com/56746942/150936756-bfb2c811-503e-4aa3-828d-c194ebb80ef6.png)
当我的代码里对ModbusClient 使用![image](https://user-images.githubusercontent.com/56746942/150939731-337e24f7-9d81-444a-bba6-a44aa698982c.png)
lock
关键字,才确保了每次结果是正确的。(en: When I use the 'lock' keyword on ModbusClient in my code, I make sure the result is correct every time.)