writeHoldingRegs

Top 

writeHoldingRegs


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

Since R2019b

 

Library: Modbus Client ( Dafulai Electronics) /writeHoldingRegs

 

writeHoldingRegs

 

 


 

Description


 

This block writes holding registers. Start Address is from Input port "StartAddr" (1-based address without 4x prefix), Write Quantities are from the dimension of Input port "DataIn" . 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 "DataIn" is 5 elements's vector.  Actually the words Quantities will be 5 x 2 =10. (From "StartAddr" to "StartAddr"+9).

 

 

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

Otherwise, write successfully, Outport "DataOut" will be input port "DataIn", and Outport "Success" will be true.

 

Parameters


 

Please double click this block to open parameters dialog below:

 

writeHoldingRegs_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 "write holding registers" command to.

 

Register data type — Specifies the data format of the register being written to on the Modbus server. It is not Data type of input port "DataIn".  The data type of input port "DataIn" is always "double", the data type of output port "DataOut" is always "double" too.

 

Force to use single Write (FC=06) —  true means that we we will use multiple single writings (FC=06) to replace one multiple writing (FC=16).

 

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 4X prefix) you want to write.

 

DataIn — "double" data type's vector.  It is data values you want to write, but it will be changed to data type in parameter "Register data type" from double when writing to registers.

 

 

Outport


 

Success — "logical" data type's scalar. true means write successfully. false means that failure in writing.

 

DataOut — "double" data type's vector. It is input port "DataIn" values when write successfully.  The output port "DataOut" will keep previous values if fail in writing. Initial value is zero vector.

 

 

Examples


 

Example:

 

Every 500ms (Wait 0.5 sec block), We are writing holding registers address from 1 to 2 of Modbus TCP Server (ip address: 127.0.0.1, port=502) with Server ID=1.

 

 

Example3_writeHoldingRegs

 

Please open "your Modbus Client library folder"/examples/example3_writeHoldingregs.slx  (You must change "Hardware USB or BT Serial Port" in Modbus Setup block according to your physical USB port number).

 

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

 

Example3_writeHoldingRegs_setup

 

 

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

 

 

Example3_writeHoldingRegs_param

 

 

You can run general Modbus Slave Simulator software such as "Modbus Salve"  to see holding registers values addressing 40001 to 40002 when we modify values we write to holdings.

 

Example3_writeHoldingRegs_result