readHoldingRegs

Top 

readHoldingRegs


read Modbus Server holding registers values (Hardware: Modbus dual Masters Adaptor from Dafulai Electronic Inc )

Since R2019b

 

Library: Modbus Client ( Dafulai Electronics) /readHoldingRegs

 

readHoldingRegs

 

 


 

Description


 

This block reads holding registers values. Start Address is from Input port "StartAddr" (1-based address without 4x prefix), Read Quantities are from the dimension of Input port "Data Var" . However this Quantities is in unit of Destination Data type.  For example, if Destination  Data type (parameter: Register data type) is "uint32", and  Input port "Data Var" is 5 elements's vector.  Actually the words Quantities will be 5 x 2 =10. (From "StartAddr" to "StartAddr"+9).  Why do we use the dimension of Input port "Data Var" instead of "holding Data QTY" scalar?  The reason is for "Embedded Code generator", in this way, embedded code will know variable 's holding register address easily.

 

 

If any error (CRC, Timeout, Not supported FC, address range,....) occurs,  Outport "Data" will keep previous value, and Outport "Success" will be false.

 

Parameters


 

Please double click this block to open parameters dialog below:

 

readHoldingRegs_param

 

 

Let us explain parameters.

 

 

Object ID for multiple masters — In one PC, we may use multiple "Modbus dual masters adaptor" hardware, this is for identifying each one.

 

Modbus Server ID or node address —  The address of the server to send this "read holding registers" command to.

 

Register data type — Specifies the data format of the register being read from on the Modbus server. It is not Data type of output port "Data".  The data type of output port "Data" is always "double".

 

Word Order —  It denote the words order when register data type is "uint32/int32/single/uint64/int64/double".

 

 

 

Ports


 

Input

 


 

StartAddr — "double" data type's scalar. It is holding Regs start address (1 based without 3X prefix) you want to read.

 

Data Var — "double" data type's vector.  The dimension of vector is holding Regs QTY you want to read in specified data type in parameter "Register data type".

 

 

Outport


 

Success — "logical" data type's scalar. true means read out successfully. false means that failure in reading out data.

 

Data — "double" data type's vector. It is all Data you read out. If  we didn't read out any data, the output port Data will keep previous values. Initial value is zero vector.

 

 

Examples


 

Example:

 

Every 500ms (Wait 0.5 sec block), We are reading holding registers address from 1 to 3 of Modbus RTU/ASCii Server with Server ID=2.

 

 

Example2_readHoldingRegs

 

Please open "your Modbus Client library folder"/examples/example2_readHoldingregs.slx  (You must change USB serial Port number in Modbus Setup block according to your physical USB port number).

 

For "Modbus Setup" block,  the parameters are set up below:

 

Example1_readInputRegs_Setup

 

 

For "readHoldingRegs" block,  the parameters are set up below:

 

 

Example2_readHoldingRegs_param

 

Our example can access both Modbus RTU and Modbus ASCii. RTU or ASCii is decided by ConfigTool.exe software.

You can run general Modbus Slave Simulator software such as "Modbus Salve"  to change holding registers values addressing 40001 to 40004, you will see its result in our Simulink example.

 

Example2_readHoldingRegs_result