Modbus Protocol Register operation

Source: Internet
Author: User
Tags documentation error code

Modbus Protocol Register Operation

Modbus Registers

Modbus Register detailed Description

Detailed description

The protocol stack does not internally allocate any memory for the registers. This makes the protocol stack very small and also usable on low end targets. In addition the values don ' t has to is in the memory and could for example is stored in a flash.
whenever the protocol stack requires a value it calls one of the callback function with the register address and the N Umber of registers to read as an argument. The application should then read the actual register values (for example the ADC voltage) and should store, the result in t He supplied buffer.
If the protocol stack wants to update a register value because a write register function is received a buffer with th e New register values are passed to the callback function. The function should then use these values to update the application register values.

The protocol stack does not allocate space internally for registers. This makes the protocol stack very small and suitable for low-end target applications. And the value of the Modbus register is not necessarily stored in memory, but can be stored in memory such as Flash. When the protocol stack needs to get the value, it is implemented by invoking a callback function that takes the register address and number as the parameter. The application reads the actual register value (such as the ADC voltage) and stores it in a specific buffer.

If the protocol stack receives a write register command, a register update operation is performed, and a buffer containing the new register value is passed to the callback function. This callback function will use these values to update the application register value.

functions function function

Emberrorcode

EMBREGINPUTCB (UCHAR *pucregbuffer, USHORT usaddress, USHORT usnregs)

Input Register callback function

Emberrorcode

EMBREGHOLDINGCB (UCHAR *pucregbuffer, USHORT usaddress, USHORT usnregs, embregistermode emode)

Hold Register callback function

Emberrorcode

EMBREGCOILSCB (UCHAR *pucregbuffer, USHORT usaddress, USHORT usncoils, embregistermode emode)

Coil Status Register callback function

Emberrorcode

EMBREGDISCRETECB (UCHAR *pucregbuffer, USHORT usaddress, USHORT usndiscrete)

Discrete Register callback function

function documentation functional function Documentation

Emberrorcode EMBREGCOILSCB

(       

 

UCHAR *

Pucregbuffer ,

 

 

USHORT

usaddress ,

 

 

USHORT

usncoils ,

 

 

Embregistermode

Emode

 

 

Callback function used if a Coil Register value is read or written by the protocol stack. If you is going to use this function you might use the Functions xmbutilsetbits ( ) and xmbutilgetbits () for working with Bitfields.

If the protocol stack needs to read and write to the coil status register, the callback function needs to be called. If the user uses this feature, the user may use xmbutilsetbits () and xmbutilgetbits () to handle bit fields.

Parameters: parameters

Pucregbuffer

The bits was packed in bytes where the first coil starting at address usaddress was stored in the LSB of the first byte in The buffer pucregbuffer. If the buffer should be written by the callback function unused coil values (i.e. if not a multiple of eight coils ) should is set to zero.

Bits make up one byte, and the corresponding bits of the starting register are in the lowest bit lsb of the byte pucregbuffer. If the callback function is to write this buffer, the number of bits that are not used in the coil (for example, the coil state of the 8 group) must be set to bit 0.

USAddress

The first coil number.

First Coil Address

Usncoils

Number of coil values requested.

Number of coils requested

Emode

If embregistermode::mb_reg_write The application values should is updated from the values supplied in the buffer Pucregbuffer. If Embregistermode::mb_reg_read The application should store the current values in the buffer pucregbuffer.

If this parameter is embregistermode::mb_reg_write, the user's app value will be updated from Pucregbuffer. If the parameter is embregistermode::mb_reg_read, the user needs to store the current app data in Pucregbuffer.

Returns: back

The function must return one of the following error codes:

This function will return the following error code:

· Emberrorcode::mb_enoerr If no error occurred. In this case a normal Modbus response is sent.

Emberrorcode::mb_enoerr If no error occurs. In this case, send a normal modbus response.

· Emberrorcode::mb_enoreg If the application does not a map an coils within the requested address range. A illegal DATA ADDRESS is sent as a response.

Emberrorcode::mb_enoreg If there is no coil status register in the requested address range, in this case a illegal DATA address response is sent.

· Emberrorcode::mb_etimedout If The requested register block is currently isn't available and the application dependent response timeout would be violate D. In the case a SLAVE DEVICE BUSY exception is sent as a response.

Emberrorcode::mb_etimedout If the requested register area is currently invalid and the application related should time out. In this case, send a SLAVE DEVICE BUSY answer.

· Emberrorcode::mb_eio If an unrecoverable error occurred. In the case a SLAVE DEVICE FAILURE exception is sent as a response.

Emberrorcode::mb_eio

If a different error occurs. In this case, send a SLAVE DEVICE FAILURE answer.

Examples: Example

at91sam7x_rowley/demo.c, avr/demo.c, linux/demo.c,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.