readInputRegs

Top 

readInputRegs


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

Since R2019b

 

Library: Modbus Client ( Dafulai Electronics) /readInputRegs

 

readInputRegs

 

 


 

Description


 

This block reads input registers values. Start Address is from Input port "StartAddr" (1-based address without 3x 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 "Input Data QTY" scalar?  The reason is for "Embedded Code generator", in this way, embedded code will know variable 's input 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:

 

readInputRegs_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 input 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 input Regs start address (1 based without 3X prefix) you want to read.

 

Data Var — "double" data type's vector.  The dimension of vector is input 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 input registers address from 1 to 3 of Modbus RTU/ASCii Server with Server ID=10.

 

 

Example1_readInputRegs

 

Please open "your Modbus Client library folder"/examples/example1_readinputregs.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 "readInputRegs" block,  the parameters are set up below:

 

 

Example1_readInputRegs_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 Input registers values addressing 30001 to 30003, you will see its result in our Simulink example.

 

Example1_readInputRegs_result