modbus_server_misc.c File Reference

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

Go to the source code of this file.

Macros

#define TRACE_LEVEL   MODBUS_TRACE_LEVEL
 

Functions

void modbusServerTick (ModbusServerContext *context)
 Handle periodic operations. More...
 
void modbusServerAcceptConnection (ModbusServerContext *context)
 Accept connection request. More...
 
void modbusServerCloseConnection (ModbusClientConnection *connection)
 Connection event handler. More...
 
void modbusServerProcessConnectionEvents (ModbusServerContext *context, 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 (ModbusServerContext *context)
 Lock Modbus table. More...
 
void modbusServerUnlock (ModbusServerContext *context)
 Unlock Modbus table. More...
 
error_t modbusServerReadCoil (ModbusServerContext *context, uint16_t address, bool_t *state)
 Get coil state. More...
 
error_t modbusServerWriteCoil (ModbusServerContext *context, uint16_t address, bool_t state, bool_t commit)
 Set coil state. More...
 
error_t modbusServerReadReg (ModbusServerContext *context, uint16_t address, uint16_t *value)
 Get register value. More...
 
error_t modbusServerWriteReg (ModbusServerContext *context, uint16_t address, uint16_t value, bool_t commit)
 Set register value. More...
 
ModbusExceptionCode modbusServerTranslateExceptionCode (error_t status)
 Translate exception code. More...
 

Detailed Description

Helper functions for Modbus/TCP server.

License

Copyright (C) 2010-2018 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
1.9.0

Definition in file modbus_server_misc.c.

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   MODBUS_TRACE_LEVEL

Definition at line 30 of file modbus_server_misc.c.

Function Documentation

◆ modbusServerAcceptConnection()

void modbusServerAcceptConnection ( ModbusServerContext context)

Accept connection request.

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

Definition at line 83 of file modbus_server_misc.c.

◆ modbusServerCloseConnection()

void modbusServerCloseConnection ( ModbusClientConnection connection)

Connection event handler.

Parameters
[in]connectionPointer to the client connection

Definition at line 169 of file modbus_server_misc.c.

◆ 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 381 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 432 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 457 of file modbus_server_misc.c.

◆ modbusServerLock()

void modbusServerLock ( ModbusServerContext context)

Lock Modbus table.

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

Definition at line 469 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 323 of file modbus_server_misc.c.

◆ modbusServerProcessConnectionEvents()

void modbusServerProcessConnectionEvents ( ModbusServerContext context,
ModbusClientConnection connection 
)

Connection event handler.

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

Definition at line 197 of file modbus_server_misc.c.

◆ modbusServerReadCoil()

error_t modbusServerReadCoil ( ModbusServerContext context,
uint16_t  address,
bool_t state 
)

Get coil state.

Parameters
[in]contextPointer to the Modbus/TCP server context
[in]addressCoil address
[out]stateCurrent coil state
Returns
Error code

Definition at line 504 of file modbus_server_misc.c.

◆ modbusServerReadReg()

error_t modbusServerReadReg ( ModbusServerContext context,
uint16_t  address,
uint16_t *  value 
)

Get register value.

Parameters
[in]contextPointer to the Modbus/TCP server context
[in]addressRegister address
[out]valueCurrent register value
Returns
Error code

Definition at line 566 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 47 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 626 of file modbus_server_misc.c.

◆ modbusServerUnlock()

void modbusServerUnlock ( ModbusServerContext context)

Unlock Modbus table.

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

Definition at line 485 of file modbus_server_misc.c.

◆ modbusServerWriteCoil()

error_t modbusServerWriteCoil ( ModbusServerContext context,
uint16_t  address,
bool_t  state,
bool_t  commit 
)

Set coil state.

Parameters
[in]contextPointer to the Modbus/TCP server context
[in]addressAddress of the coil
[in]stateDesired coil state
[in]commitThis flag indicates the current phase (validation phase or write phase if the validation was successful)
Returns
Error code

Definition at line 536 of file modbus_server_misc.c.

◆ modbusServerWriteReg()

error_t modbusServerWriteReg ( ModbusServerContext context,
uint16_t  address,
uint16_t  value,
bool_t  commit 
)

Set register value.

Parameters
[in]contextPointer to the Modbus/TCP server context
[in]addressRegister address
[in]valueDesired register value
[in]commitThis flag indicates the current phase (validation phase or write phase if the validation was successful)
Returns
Error code

Definition at line 598 of file modbus_server_misc.c.