Data Access API расширено функциями для чтения/записи регистров
This commit is contained in:
@@ -14,6 +14,65 @@
|
||||
|
||||
#ifdef MODBUS_ENABLE_INPUTS
|
||||
|
||||
|
||||
/**
|
||||
* @brief Записать входной регистр по глобальному адресу.
|
||||
* @param Addr Адрес регистра.
|
||||
* @param WriteVal Число для записи.
|
||||
* @return ExceptionCode Код исключения если регистра по адресу не существует, и NO_ERRORS если все ок.
|
||||
*
|
||||
* @details Позволяет обратиться к любому регистру по его глобальному адрессу.
|
||||
Вне зависимости от того как регистры размещены в памяти.
|
||||
*/
|
||||
MB_ExceptionTypeDef MB_Input_Write_Global(uint16_t Addr, uint16_t WriteVal)
|
||||
{
|
||||
//---------CHECK FOR ERRORS----------
|
||||
MB_ExceptionTypeDef Exception = NO_ERRORS;
|
||||
uint16_t *pInRegs;
|
||||
|
||||
//------------WRITE COIL-------------
|
||||
Exception = MB_DefineRegistersAddress(&pInRegs, Addr, 1, RegisterType_Input);
|
||||
if(Exception == NO_ERRORS)
|
||||
{
|
||||
*(pInRegs) = WriteVal;
|
||||
}
|
||||
return Exception;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Считать входной регистр по глобальному адресу.
|
||||
* @param Addr Адрес регистра.
|
||||
* @param Exception Указатель на переменную для кода исключения, в случае неудачи при чтении.
|
||||
* @return uint16_t Возвращает значение регистра.
|
||||
*
|
||||
* @details Позволяет обратиться к любому регистру по его глобальному адрессу.
|
||||
Вне зависимости от того как регистры размещены в памяти.
|
||||
*/
|
||||
uint16_t MB_Input_Read_Global(uint16_t Addr, MB_ExceptionTypeDef *Exception)
|
||||
{
|
||||
//---------CHECK FOR ERRORS----------
|
||||
MB_ExceptionTypeDef Exception_tmp = 0;
|
||||
|
||||
uint16_t *pInRegs;
|
||||
|
||||
//------------READ COIL--------------
|
||||
Exception_tmp = MB_DefineRegistersAddress(&pInRegs, Addr, 1, RegisterType_Input);
|
||||
|
||||
if(Exception) // if exception is not given to func fill it
|
||||
*Exception = Exception_tmp;
|
||||
|
||||
if(Exception_tmp == NO_ERRORS)
|
||||
{
|
||||
return *(pInRegs);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Обработать функцию Read Input Registers (04 - 0x04).
|
||||
* @param modbus_msg Указатель на структуру собщения modbus.
|
||||
@@ -47,6 +106,8 @@ uint8_t MB_Process_Read_Input_Regs(RS_MsgTypeDef *modbus_msg)
|
||||
|
||||
#else //MODBUS_ENABLE_INPUTS
|
||||
|
||||
MB_ExceptionTypeDef MB_Input_Write_Global(uint16_t Addr, uint16_t WriteVal) {return ILLEGAL_FUNCTION;}
|
||||
uint16_t MB_Input_Read_Global(uint16_t Addr, MB_ExceptionTypeDef *Exception) {return 0;}
|
||||
uint8_t MB_Process_Read_Input_Regs(RS_MsgTypeDef *modbus_msg) {return 0;}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user