Modbus Custom Message&子功能(NModbus,子功能) [英] Modbus Custom Message & Sub function (NModbus, Sub-function)

查看:213
本文介绍了Modbus Custom Message&子功能(NModbus,子功能)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我在C#项目中使用NModbus,阅读&从/向许多I / O设备写入Modbus数据。我在程序中使用Modbus TCP / IP协议(ModbusIpMaster等..)。



我已成功与设备通信(通过Modbus网关)并且可以使用默认方法(例如,常见的Modbus函数,如ReadHoldingRegisters,WriteCoils),从设备访问数据,并可以回写它们。目前,我能做的只是默认的NModbus方法,它暴露了常用的Modbus代码(1,2,3,4等......)。



我有两个困难:



1) I / O设备的设置和额外信息可以在Modbus代码为70(0x46),有子功能,我需要使用这些功能来读取和/或写入设置。



例如,Func 07(0x46),Sub func 6(0x06)可用于设置模块的通信设置。在这个例子中,有7个字节的信息要发送,它们带有设置(例如波特率等......)



NModbus没有特定的方法对于这个''自定义''功能代码(70)。因此,根据我的理解,需要使用NModbus的CustomMessage功能。我尝试过执行CustomMessage,当使用常见的Modbus功能代码(例如1或2)时,我可以获得与使用NModbus默认方法相同的结果(即CustomMessage到目前为止工作)。



当我尝试除一般功能代码以外的功能代码(例如1,2,3 ......)时,我会遇到各种异常。此外,我不知道如何发送带有消息的子功能!



当我在功能代码之后添加子功能时(例如70后跟06),数据通过I get,例外发送。我真的需要这个领域专家的帮助。



这是一个更明显的例外:



抛出类型''Modbus.SlaveException''的异常。

函数代码:198异常代码:3 - 查询数据字段中包含的值不是服务器允许的值(或从属)。这表示复杂请求的其余部分的结构中存在错误,例如隐含长度不正确。具体而言并不意味着提交存储在寄存器中的数据项具有超出预期的值应用程序,因为MODBUS协议不知道任何特定寄存器的任何特定值的重要性。






2)第二个问题是通过Modbus发送ASCII RS-232 消息,以便控制连接到模块的COM1的RS-232设备转换Modbus消息的能力。换句话说,我打算与Modbus网关通信,将ASCII数据发送到COM1,然后COM1将数据转换为RS-232,然后与RS-232设备通信。翻译意味着在网关内部发生,所以我需要知道的是我在地球上如何发送这些消息,其长度各不相同。我不知道怎么可能,以及从哪里开始。





我将不胜感激任何有用的建议或反馈。谢谢你,新年快乐,提前。

解决方案

关于第一个问题,可以限制访问设备的设置,使用标准的HoldingRegisters和Coils!这些设置没有很好的记录,需要对哪个位进行一些调查。



关于第二个问题,没有简单的方法。我考虑使用他们提供的另一种基于文本的协议,并提供类似的功能,但它更全面地记录。



感谢您的关注和兴趣。

Hi,

I am using NModbus in a C# project, to read & write Modbus data from/to a number of I/O devices. I am using the Modbus TCP/IP protocol (ModbusIpMaster etc..) in the program.

I have successfully communicated with the devices (through a Modbus gateway) and can use the default methods (e.g. common Modbus functions such as ReadHoldingRegisters, WriteCoils ), to access the data from the devices, and can write back to them. At the moment, all I can do are the default NModbus methods which expose commonly used Modbus codes (1, 2, 3, 4 etc..).

I have two difficulties:

1) The I/O devices'' settings and extra information can be accessed under the Modbus code of 70 (0x46), and there are sub functions which I will need to use in order to read and/or write the settings.

For example, Func 07 (0x46), Sub func 6 (0x06), can be used to set the communications settings of a module. In this example, there are 7 bytes of information to be sent, which carry the settings (e.g. baud rate etc...)

NModbus does not have a specific method for this ''custom'' function code (70). So, from what I understand, one needs to use the CustomMessage feature of NModbus. I have tried executing CustomMessage, and when using the common Modbus function codes (e.g. 1 or 2) I can achieve the same result as if I were using the default methods of NModbus (i.e. the CustomMessage is working so far).

When I try function codes other than the general ones (e.g. 1, 2, 3...) I do get all sorts of exceptions. Furthermore, I do not know how I should send the sub-function with the message!

When I added the subfunction just after the function code (e.g. 70 followed by 06), and the data is send through I get, exceptions. I really need help from experts in this field, please.

Here is a more obvious exception:

" Exception of type ''Modbus.SlaveException'' was thrown.
Function Code: 198 Exception Code: 3 - A value contained in the query data field is not an allowable value for server (or slave). This indicates a fault in the structure of the remainder of a complex request, such as that the implied length is incorrect. It specifically does NOT mean that a data item submitted for storage in a register has a value outside the expectation of the application program, since the MODBUS protocol is unaware of the significance of any particular value of any particular register."



2) The second problem is sending ASCII RS-232 messages through Modbus, in order to control an RS-232 device which is connected to COM1 of a module which has the ability to convert Modbus messages. In other words, I am planning to communicate with a Modbus gateway, to send ASCII data to its COM1, which in turn translates data to RS-232 and then communicates with the RS-232 device. The translation is meant to occur internal to the gateway, so all I need to know is how on Earth I can send these messages through, which vary in length. I have no idea how that is possible, and where to start from.


I would appreciate any useful suggestions or feedback. Thank you, and Happy New Year, in advance.

解决方案

With regards to the first question, it is possible to have limited access to the device''s settings, using the standard HoldingRegisters and Coils! These settings are not documented very well, and one needs to do a bit of investigation as to which bit is which.

With regards to the second question, there is no easy way of doing it. I have considered to use another protocol that they offer which is text based, and does provide similar features, but it is documented more comprehensively.

Thank you for your attention and interest.


这篇关于Modbus Custom Message&子功能(NModbus,子功能)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆