writeMyReadOnlyRegs

Top 

writeMyReadOnlyRegs


write Modbus Server Read-only register value

Since R2019b

 

Library: Modbus Server ( Dafulai Electronics) /writeMyReadOnlyRegs

 

writeMyReadOnlyRegs

 

 


 

Description


 

This block writes Read-only register values. Start Address is from Input port "StartAddr" (1-based address without 3x or 4x prefix), write Quantities are decided by Input port "Data" vector's element numbers and parameter "Data type".   For example, if parameter Data type is "uint32", and  Input port "Data" contains 5 elements vector.  Actually the words Quantities will be 5 x 2 =10. (From "StartAddr" to "StartAddr"+9)

 

Those Read-only registers are only readable for "Outside Modbus Master".  Simulator (Our PC) will control these values (writable).

 

If succeed to write, output port "Success" will become true, otherwise false.

 

This is very important block. All simulated data are from this block for words registers.

 

 

Parameters


 

Please double click this block to open parameters dialog below:

 

writeMyReadOnlyRegs_parms

 

 

Let us explain parameters.

 

 

Object ID for multiple Modbus slave Simulator Hardware — In one PC, we may use multiple Modbus slave simulators, this is for identifying each one.

 

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

 

Data type — Specifies the data format of the register being write to on the Modbus server. It is not Data type of input port "Data".  The data type of input port "Data" is always "double".

 

Which device? (Only for RTU/ASCii)  — This is useful for Modbus RTU/ASCii useful.  it denotes which device we write to. For Modbus TCP Server, just ignore it.

 

 

 

Ports


 

Input

 


 

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

 

Data — "double" data type's vector. It is all Data you write to.

 

 

 

Outport


 

Success — "logical" data type's scalar. If succeed to write, it will become true, otherwise false.

 

 

Examples


 

Example:

 

Every 500ms (Wait 0.5 sec block), We set Input registers addressing at 30078 and 30079 (it is address 78 and 79 if no prefix) increase 1 for Modbus RTU Server Device1.

Note:  addressing at 30078 and 30079 combines one "uint32" data with "big-endian"

 

 

example3_writeInputregs

 

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

 

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

 

example3_setup_Parm

 

 

For "write input Regs address 78 to 79" block,  the parameters are set up below:

 

 

example3_writeInputRegs_Parm

 

You can run general Modbus master software such as Modbus Poll or ModScan32 to view input registers values addressing 30078 to 30079. We put ModScan32 result below:

 

example3_writeInputRegs_result

 

 

Notes: Because input port "Data" is "double" type, when increasing 1 causes over 0xFFFFFFFF, although input port "Data" can be over 0xFFFFFFFF,  the register result will be limit to 0xFFFFFFFF due to "uint32" data type of register.   If you want to return to zero when uint32 data is over 0xFFFFFFFF, you must modify Simulink model.