Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Isn't ModbusClient thread safe?(ModbusClient 不是线程安全的吗?) #76

Open
jkh404 opened this issue Jan 25, 2022 · 1 comment
Open

Comments

@jkh404
Copy link

jkh404 commented Jan 25, 2022

我将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):
image
image
image
正确的(The correct):
image

当我的代码里对ModbusClient 使用lock关键字,才确保了每次结果是正确的。(en: When I use the 'lock' keyword on ModbusClient in my code, I make sure the result is correct every time.)
image

@Padanian
Copy link

Modbus is client/server communication and doesn't require multithreading, as multiple master threads will end up trying reading or writing concurrently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants