[英]'ModbusSerialMaster' is inaccessible due to its protection level
I am creating RTU using NModbus. 我正在使用NModbus创建RTU。
Installed NModbus package using following command in Package Manager Console 在Package Manager控制台中使用以下命令安装了NModbus软件包
Install-Package NModbus
Now I am creating RTU by following line. 现在,我通过以下代码创建RTU。
IModbusSerialMaster master = ModbusSerialMaster.CreateRtu(Port);
But I am getting error 但是我得到了错误
'ModbusSerialMaster' is inaccessible due to its protection level 'ModbusSerialMaster'由于其保护级别而无法访问
What is the reason and how can I create Modbus RTU to read and wrtite multiple register. 原因是什么,如何创建Modbus RTU来读取和写入多个寄存器。
Thanks in advance. 提前致谢。
Yes, it's because ModbusSerialMaster
is an internal class, as you can see in the source . 是的,这是因为ModbusSerialMaster
是内部类,如您在源代码中看到的那样。
Browsing around the code, I suspect you want something like this: 浏览代码,我怀疑您想要这样的东西:
IModbusFactory factory = new ModbusFactory();
IModbusSerialMaster = factory.CreateMaster(transport);
... where transport
is something that implements IModbusSerialTransport
. ...其中transport
是什么,实现IModbusSerialTransport
。
Alternatively, if you don't need an IModbusSerialMaster
but an IModbusRtuTransport
you'd call CreateRtuTransport
: 另外,如果您不需要IModbusSerialMaster
而是IModbusRtuTransport
可以调用CreateRtuTransport
:
IModbusFactory factory = new ModbusFactory();
IModbusRtuTransport = factory.CreateRtuTransport(resource);
... where resource
is something that implements IStreamResource
. ...其中resource
是实现IStreamResource
东西。
For anything further, I'd probably just clone the source code and browse around it to work out what you can do and what you need. 进一步讲,我可能只是克隆源代码并浏览它,以了解您可以做什么和需要什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.