(9条消息) freemodbus工具函数

Detailed Description详细描述This module contains some utility functions which can be used by the application. It includes some special functions for working with bitfields backed by a character array buffer.这个模块包括应用中使用的一些功能函数。这些功能函数包括一些特殊的通过字符数组缓冲方式对位域进行处理的功能FunctionsvoidxMBUtilSetBits (UCHAR *ucByteBuf, USHORT usBitOffset, UCHAR ucNBits, UCHAR ucValues)UCHARxMBUtilGetBits (UCHAR *ucByteBuf, USHORT usBitOffset, UCHAR ucNBits)Function Documentation函数文档UCHAR xMBUtilGetBits(UCHAR *ucByteBuf,USHORTusBitOffset,UCHARucNBits)Function to read bits in a byte buffer.在字节缓冲中读取位This function is used to extract up bit values from an array. Up to eight bit values can be extracted in one step.这个函数从一个字节中来获取一个位的值。一步最多可以获取8个位的值。Parameters:参数ucByteBufA buffer where the bit values are stored.存储位的缓冲字节usBitOffsetThe starting address of the bits to set. The first bit has the offset 0.位的起始地址,第一个位的地址偏移量是0ucNBitsNumber of bits to modify. The value must always be smaller than 8.需要修改的位的数量。该值要小于8。UCHAR ucBits[2] = {0, 0};  UCHAR ucResult;// Extract the bits 3 - 10.  ucResult = xMBUtilGetBits( ucBits, 3, 8 );void xMBUtilSetBits(UCHAR *ucByteBuf,USHORTusBitOffset,UCHARucNBits,UCHARucValues)Function to set bits in a byte buffer.设置一个字节缓冲的位This function allows the efficient use of an array to implement bitfields. The array used for storing the bits must always be a multiple of two bytes. Up to eight bits can be set or cleared in one operation.这个函数可以实现有效处理位域的功能。存储位域的数值必须是两个字节。一次操作最多可处理8位。Parameters:ucByteBufA buffer where the bit values are stored. Must be a multiple of 2 bytes. No length checking is performed and if usBitOffset / 8 is greater than the size of the buffer memory contents is overwritten.位存储的缓冲区。必须是2个字节。usBitOffsetThe starting address of the bits to set. The first bit has the offset 0.位设置的起始地址,第一个位的偏移为0。ucNBitsNumber of bits to modify. The value must always be smaller than 8.需要修改的位的数量。该值必须小于8。ucValuesThew new values for the bits. The value for the first bit starting at usBitOffset is the LSB of the value ucValues位的新值。在usBitOffset中的第一位的值是ucValues的最低有效位。ucBits[2] = {0, 0};// Set bit 4 to 1 (read: set 1 bit starting at bit offset 4 to value 1)xMBUtilSetBits( ucBits, 4, 1, 1 ); -->// Set bit 7 to 1 and bit 8 to 0.xMBUtilSetBits( ucBits, 7, 2, 0x01 );// Set bits 8 - 11 to 0x05 and bits 12 - 15 to 0x0A;xMBUtilSetBits( ucBits, 8, 8, 0x5A);

(0)

相关推荐