modbus_server_misc.h File Reference

Helper functions for Modbus/TCP server. More...

#include "core/net.h"
#include "modbus/modbus_server.h"

Go to the source code of this file.

Functions

void modbusServerTick (ModbusServerContext *context)
 Handle periodic operations. More...
 
void modbusServerRegisterConnectionEvents (ModbusClientConnection *connection, SocketEventDesc *eventDesc)
 Register connection events. More...
 
void modbusServerProcessConnectionEvents (ModbusClientConnection *connection)
 Connection event handler. More...
 
error_t modbusServerParseMbapHeader (ModbusClientConnection *connection)
 Parse request MBAP header. More...
 
error_t modbusServerFormatMbapHeader (ModbusClientConnection *connection, size_t length)
 Format response MBAP header. More...
 
void * modbusServerGetRequestPdu (ModbusClientConnection *connection, size_t *length)
 Retrieve request PDU. More...
 
void * modbusServerGetResponsePdu (ModbusClientConnection *connection)
 Retrieve response PDU. More...
 
void modbusServerLock (ModbusClientConnection *connection)
 Lock Modbus table. More...
 
void modbusServerUnlock (ModbusClientConnection *connection)
 Unlock Modbus table. More...
 
error_t modbusServerReadCoil (ModbusClientConnection *connection, uint16_t address, bool_t *state)
 Read a single coil. More...
 
error_t modbusServerReadDiscreteInput (ModbusClientConnection *connection, uint16_t address, bool_t *state)
 Read a single discrete input. More...
 
error_t modbusServerWriteCoil (ModbusClientConnection *connection, uint16_t address, bool_t state, bool_t commit)
 Write a single coil. More...
 
error_t modbusServerReadHoldingReg (ModbusClientConnection *connection, uint16_t address, uint16_t *value)
 Read a single holding register. More...
 
error_t modbusServerReadInputReg (ModbusClientConnection *connection, uint16_t address, uint16_t *value)
 Read a single input register. More...
 
error_t modbusServerWriteReg (ModbusClientConnection *connection, uint16_t address, uint16_t value, bool_t commit)
 Write a single register. More...
 
ModbusExceptionCode modbusServerTranslateExceptionCode (error_t status)
 Translate exception code. More...
 

Detailed Description

Helper functions for Modbus/TCP server.

License

SPDX-License-Identifier: GPL-2.0-or-later

Copyright (C) 2010-2022 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneTCP Open.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
2.2.0

Definition in file modbus_server_misc.h.

Function Documentation

◆ modbusServerFormatMbapHeader()

error_t modbusServerFormatMbapHeader ( ModbusClientConnection connection,
size_t  length 
)

Format response MBAP header.

Parameters
[in]connectionPointer to the client connection
[in]lengthLength of the PDU, in bytes
Returns
Error code

Definition at line 397 of file modbus_server_misc.c.

◆ modbusServerGetRequestPdu()

void* modbusServerGetRequestPdu ( ModbusClientConnection connection,
size_t *  length 
)

Retrieve request PDU.

Parameters
[in]connectionPointer to the client connection
[out]lengthLength request the request PDU, in bytes
Returns
Pointer to the request PDU

Definition at line 448 of file modbus_server_misc.c.

◆ modbusServerGetResponsePdu()

void* modbusServerGetResponsePdu ( ModbusClientConnection connection)

Retrieve response PDU.

Parameters
[in]connectionPointer to the client connection
Returns
Pointer to the response PDU

Definition at line 473 of file modbus_server_misc.c.

◆ modbusServerLock()

void modbusServerLock ( ModbusClientConnection connection)

Lock Modbus table.

Parameters
[in]connectionPointer to the client connection

Definition at line 485 of file modbus_server_misc.c.

◆ modbusServerParseMbapHeader()

error_t modbusServerParseMbapHeader ( ModbusClientConnection connection)

Parse request MBAP header.

Parameters
[in]connectionPointer to the client connection
Returns
Error code

Definition at line 339 of file modbus_server_misc.c.

◆ modbusServerProcessConnectionEvents()

void modbusServerProcessConnectionEvents ( ModbusClientConnection connection)

Connection event handler.

Parameters
[in]connectionPointer to the client connection

Definition at line 174 of file modbus_server_misc.c.

◆ modbusServerReadCoil()

error_t modbusServerReadCoil ( ModbusClientConnection connection,
uint16_t  address,
bool_t state 
)

Read a single coil.

Parameters
[in]connectionPointer to the client connection
[in]addressAddress of the coil
[out]stateCurrent state of the coil
Returns
Error code

Definition at line 530 of file modbus_server_misc.c.

◆ modbusServerReadDiscreteInput()

error_t modbusServerReadDiscreteInput ( ModbusClientConnection connection,
uint16_t  address,
bool_t state 
)

Read a single discrete input.

Parameters
[in]connectionPointer to the client connection
[in]addressAddress of the discrete input
[out]stateCurrent state of the discrete input
Returns
Error code

Definition at line 565 of file modbus_server_misc.c.

◆ modbusServerReadHoldingReg()

error_t modbusServerReadHoldingReg ( ModbusClientConnection connection,
uint16_t  address,
uint16_t *  value 
)

Read a single holding register.

Parameters
[in]connectionPointer to the client connection
[in]addressAddress of the holding register
[out]valueCurrent value of the holding register
Returns
Error code

Definition at line 643 of file modbus_server_misc.c.

◆ modbusServerReadInputReg()

error_t modbusServerReadInputReg ( ModbusClientConnection connection,
uint16_t  address,
uint16_t *  value 
)

Read a single input register.

Parameters
[in]connectionPointer to the client connection
[in]addressAddress of the input register
[out]valueCurrent value of the input register
Returns
Error code

Definition at line 684 of file modbus_server_misc.c.

◆ modbusServerRegisterConnectionEvents()

void modbusServerRegisterConnectionEvents ( ModbusClientConnection connection,
SocketEventDesc eventDesc 
)

Register connection events.

Parameters
[in]connectionPointer to the client connection
[in]eventDescSocket events to be registered

Definition at line 103 of file modbus_server_misc.c.

◆ modbusServerTick()

void modbusServerTick ( ModbusServerContext context)

Handle periodic operations.

Parameters
[in]contextPointer to the Modbus/TCP server context

Definition at line 51 of file modbus_server_misc.c.

◆ modbusServerTranslateExceptionCode()

ModbusExceptionCode modbusServerTranslateExceptionCode ( error_t  status)

Translate exception code.

Parameters
[in]statusStatus code
Returns
Exception code

Definition at line 760 of file modbus_server_misc.c.

◆ modbusServerUnlock()

void modbusServerUnlock ( ModbusClientConnection connection)

Unlock Modbus table.

Parameters
[in]connectionPointer to the client connection

Definition at line 506 of file modbus_server_misc.c.

◆ modbusServerWriteCoil()

error_t modbusServerWriteCoil ( ModbusClientConnection connection,
uint16_t  address,
bool_t  state,
bool_t  commit 
)

Write a single coil.

Parameters
[in]connectionPointer to the client connection
[in]addressAddress of the coil
[in]stateDesired state of the coil
[in]commitThis flag indicates the current phase (validation phase or write phase if the validation was successful)
Returns
Error code

Definition at line 608 of file modbus_server_misc.c.

◆ modbusServerWriteReg()

error_t modbusServerWriteReg ( ModbusClientConnection connection,
uint16_t  address,
uint16_t  value,
bool_t  commit 
)

Write a single register.

Parameters
[in]connectionPointer to the client connection
[in]addressAddress of the register
[in]valueDesired value of the register
[in]commitThis flag indicates the current phase (validation phase or write phase if the validation was successful)
Returns
Error code

Definition at line 727 of file modbus_server_misc.c.