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.

这个模块包括应用中使用的一些功能函数。这些功能函数包括一些特殊的通过字符数组缓冲方式对位域进行处理的功能

 

 

Functions

void 

xMBUtilSetBits (UCHAR *ucByteBuf, USHORT usBitOffset, UCHAR ucNBits, UCHAR ucValues)

UCHAR 

xMBUtilGetBits (UCHAR *ucByteBuf, USHORT usBitOffset, UCHAR ucNBits)

Function Documentation

函数文档

UCHAR xMBUtilGetBits

UCHAR * 

ucByteBuf,

 

 

USHORT 

usBitOffset,

 

 

UCHAR 

ucNBits

 

 

 

 

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:

参数

 

ucByteBuf 

A buffer where the bit values are stored.

存储位的缓冲字节

 

usBitOffset 

The starting address of the bits to set. The first bit has the offset 0.

位的起始地址,第一个位的地址偏移量是0

 

ucNBits 

Number 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,

 

 

USHORT 

usBitOffset,

 

 

UCHAR 

ucNBits,

 

 

UCHAR 

ucValues

 

 

 

 

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:

 

ucByteBuf 

A 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个字节。

 

usBitOffset 

The starting address of the bits to set. The first bit has the offset 0.

位设置的起始地址,第一个位的偏移为0

 

ucNBits 

Number of bits to modify. The value must always be smaller than 8.

需要修改的位的数量。该值必须小于8

 

ucValues 

Thew 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);

你可能感兴趣的:(freemodbus工具函数)