06-03-2009 05:58 AM
Hi,
I am working with NI MODBUS Library Vi's.
I want to implement Commands with Function codes as 0*14 (Read File Record), 0*15 (Write File Record) and 0*2B (Read Device Identification) using NI Modbus Library.
Has anybody implemented these commands earlier. If yes, can give the implemented VI's.
Please help.
Thanks & Regards,
Samriddh Sarbalhi.
06-05-2009 07:26 AM
Hi,
Its very strange that no one has replied to this question.
Waiting for the Replies.
Thanks & Regards,
Samriddh Sarbalhi
02-22-2011 05:13 PM
did you find any answer to your questions? I need to use the other functions code in the MODBUS library, but some function codes are missing. For example, I need 20 for read file record and 20 to write file record.
Yik
03-30-2014 07:40 AM
The READ FILE RECORD and WRITE FILE RECORD commands are some of the more obscure commands in the Modbus specification. Where most people get confused is trying to implement the absolutely most complex form of the request possible.
If you stick with the basic single record command request, the packet is much easier to create. Assuming RTU format, the packet isn't much more convoluted than a READ INPUT REGISTERS, or other multi-part request. Here's a very simple request to unit 1 for 8 registers (16 bytes) from 1 record of 1 file --
Field | Size | Offset | Value | Description |
---|---|---|---|---|
unit# | 1 | 0 | 1 | Modbus unit number |
fc# | 1 | 1 | 20 | READ = 20, WRITE = 21 |
size | 1 | 2 | 7 | 7 bytes per read record request |
type | 1 | 3 | 6 | hard-coded value "6" |
file# | 2 | 4 | 0 | File number in range 0 to 65535 (0 to 10 on some devices) |
record# | 2 | 6 | 1 | Record number in the range 0 to 9999 |
count | 2 | 8 | 8 | Number of registers to read in the range 1 to 123 |
CRC | 2 | 9 | xxxx | Calculated CRC value |
For the request, the most confusing parts are the size at offset 2 -- it's 7 times the number of records you want. Stick with just one for a VI, so always put a "7" there. The other confusing point is the type at the start of each request (offset 3). It is always a "6".
If you limit yourself to a single record request, the response is fairly simple to decode.
Field | Size | Offset | Value | Description |
---|---|---|---|---|
unit# | 1 | 0 | 1 | Modbus unit number |
fc# | 1 | 1 | 20 | READ = 20, WRITE = 21 |
size | 1 | 2 | 17 | 1 + 2 times register "count" in request |
type | 1 | 3 | 6 | hard-coded value "6" |
data | 2 x count | 7 | xxxx | "count" 16-bit register values |
CRC | 2 | 7 + 2 x count | xxxx | Calculated CRC value |
Here the confusing part is that you don't get the same parameters (file, record, count) back the way you do with some other Modbus commands. The reason is that the more information is returned in the response PDU, the less data you can get. This is another reason to limit your VI to a single file and record -- decoding the response gets harder faster, and you may lose track of what you're reading, if you try a multi-file, multi-record request.