writeMyDiscreteRegs | Top

writeMyDiscreteRegs write Modbus Server discrete register value Since R2019b Library: Modbus Server ( Dafulai Electronics) /writeMyDiscreteRegs Description This block writes Discrete register values. Start Address is from Input port "StartAddr" (1-based address without 1X prefix), write Quantities are decided by Input port "Data" vector's element numbers. Those discrete 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 bit registers. Parameters Please double click this block to open parameters dialog below: 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.
• | 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 Discrete Regs start address (1 based without 1X prefix) you want to write.
• | Data — "logical" 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 800ms (Wait 0.8 sec block), We toggle discrete registers address from 78 to 79 of Modbus TCP Server. Please open "your Modbus Server library folder"/examples/example4_writeDiscrete.slx (You must change USB serial Port number in CAN_setup block according to your physical USB port number). For "Modbus Server Setup" block, the parameters are set up below: For "write my discretes addresing 78 & 79 " block, the parameters are set up below: You can run general Modbus master software such as Modbus Poll or ModScan32 to view discrete registers values addressing 10078 to 10079. We put ModScan32 result below (it will toggle every 0.8 sec):