Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Current »

MB_HoldingRegRdFP() is called when a Modbus master sends a Function Code 3 command. MB_HoldingRegRdFP() read the value of a single holding register but, it assumes that you are trying to access a floating-point variable. Floating-point holding registers are numbered from MODBUS_CFG_FP_START_IX to 65535 (or less if you doesn’t have a lot of floating-point registers). MODBUS_CFG_FP_START_IX allows you to specify the start of ‘floating-point’. MB_HoldingRegRdFP() should only be called by µC/Modbus.

Prototype

CPU_FP32 MB_HoldingRegRdFP (CPU_INT16U reg,
                            CPU_INT16U *perr)

Arguments

reg

Is the desired holding register to read and can be a number between MODBUS_CFG_FP_START_IX and 65535 (depending on your product). It is up to you to decide what application variable is assigned to each holding register number. Note that if your product doesn’t have any floating-point registers but a large number of holding registers, you can set MODBUS_CFG_FP_START_IX to 65535.

perr

Is a pointer to a variable that will contain an error code based on the outcome of the call. Your code thus needs to return one of the following error codes:

MODBUS_ERR_NONE

if the holding register number you specified is a valid holding register and you are able to have code access the value of this holding register.

MODBUS_ERR_RANGE

if the holding register number passed as an argument is not a valid holding register number for your product.

Returned Value

MB_HoldingRegRdFP() returns the current value of the specified floating?point holding register as a 32-bit IEEE-754 unsigned value. If an invalid holding register number is specified, you should return (CPU_FP32) 0.

Notes / Warnings

Code is enabled when both MODBUS_CFG_FC03_EN is set to DEF_ENABLED and MODBUS_CFG_FP_EN is set to DEF_ENABLED in your product’s mb_cfg.h file.

Holding registers and input registers are completely different and can be assigned to different variables.

Called By:

MBS_FC03_HoldingRegRd() in mbs_core.c

Example

In this example, our product has 4 floating-point variables that we want to assign to holding registers. Your systems Engineer decided to assign Modbus holding register numbers MODBUS_CFG_FP_START_IX+0, MODBUS_CFG_FP_START_IX+1, MODBUS_CFG_FP_START_IX+2 and MODBUS_CFG_FP_START_IX+3 to the four floating?point values. You will notice that we disable interrupts to access the variables. This is done in case your CPU does not allow atomic access to the 32-bit floating-point values.

  • No labels