Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Read File Record Command in MODBUS Library

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.

 

0 Kudos
Message 1 of 4
(7,774 Views)

Hi,

 

Its very strange that no one has replied to this question.

 

Waiting for the Replies.

 

Thanks & Regards,

Samriddh Sarbalhi

0 Kudos
Message 2 of 4
(7,750 Views)

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

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 3 of 4
(7,205 Views)

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 --

 

 

FieldSizeOffsetValueDescription
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.

 

FieldSizeOffsetValueDescription
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.

greenHouse Gas and Electric // jfh@ghgande.com
0 Kudos
Message 4 of 4
(6,732 Views)