mirror of
https://github.com/apache/nuttx-apps.git
synced 2025-10-19 02:17:37 +08:00
@@ -1,5 +1,5 @@
|
||||
/****************************************************************************
|
||||
* apps/examples/modbus/main.c
|
||||
* apps/examples/modbus/modbus_main.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
@@ -140,7 +140,10 @@ static void modbus_showusage(FAR const char *progname, int exitcode);
|
||||
****************************************************************************/
|
||||
|
||||
static struct modbus_state_s g_modbus;
|
||||
static const uint8_t g_slaveid[] = { 0xaa, 0xbb, 0xcc };
|
||||
static const uint8_t g_slaveid[] =
|
||||
{
|
||||
0xaa, 0xbb, 0xcc
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
@@ -191,7 +194,8 @@ static inline int modbus_initialize(void)
|
||||
*/
|
||||
|
||||
mberr = eMBInit(MB_RTU, 0x0a, CONFIG_EXAMPLES_MODBUS_PORT,
|
||||
CONFIG_EXAMPLES_MODBUS_BAUD, CONFIG_EXAMPLES_MODBUS_PARITY);
|
||||
CONFIG_EXAMPLES_MODBUS_BAUD,
|
||||
CONFIG_EXAMPLES_MODBUS_PARITY);
|
||||
if (mberr != MB_ENOERR)
|
||||
{
|
||||
fprintf(stderr, "modbus_main: "
|
||||
@@ -231,6 +235,7 @@ static inline int modbus_initialize(void)
|
||||
return OK;
|
||||
|
||||
errout_with_modbus:
|
||||
|
||||
/* Release hardware resources. */
|
||||
|
||||
eMBClose();
|
||||
@@ -376,7 +381,8 @@ static inline int modbus_create_pollthread(void)
|
||||
|
||||
if (g_modbus.threadstate == STOPPED)
|
||||
{
|
||||
ret = pthread_create(&g_modbus.threadid, NULL, modbus_pollthread, NULL);
|
||||
ret = pthread_create(&g_modbus.threadid, NULL,
|
||||
modbus_pollthread, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -444,7 +450,8 @@ int main(int argc, FAR char *argv[])
|
||||
if (ret != OK)
|
||||
{
|
||||
fprintf(stderr, "modbus_main: "
|
||||
"ERROR: modbus_create_pollthread failed: %d\n", ret);
|
||||
"ERROR: modbus_create_pollthread failed: %d\n",
|
||||
ret);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
@@ -536,8 +543,8 @@ eMBErrorCode eMBRegInputCB(uint8_t *buffer, uint16_t address, uint16_t nregs)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
eMBErrorCode eMBRegHoldingCB(uint8_t *buffer, uint16_t address, uint16_t nregs,
|
||||
eMBRegisterMode mode)
|
||||
eMBErrorCode eMBRegHoldingCB(uint8_t *buffer, uint16_t address,
|
||||
uint16_t nregs, eMBRegisterMode mode)
|
||||
{
|
||||
eMBErrorCode mberr = MB_ENOERR;
|
||||
int index;
|
||||
@@ -551,6 +558,7 @@ eMBErrorCode eMBRegHoldingCB(uint8_t *buffer, uint16_t address, uint16_t nregs,
|
||||
switch (mode)
|
||||
{
|
||||
/* Pass current register values to the protocol stack. */
|
||||
|
||||
case MB_REG_READ:
|
||||
while (nregs > 0)
|
||||
{
|
||||
@@ -592,8 +600,8 @@ eMBErrorCode eMBRegHoldingCB(uint8_t *buffer, uint16_t address, uint16_t nregs,
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
eMBErrorCode eMBRegCoilsCB(uint8_t *buffer, uint16_t address, uint16_t ncoils,
|
||||
eMBRegisterMode mode)
|
||||
eMBErrorCode eMBRegCoilsCB(uint8_t *buffer, uint16_t address,
|
||||
uint16_t ncoils, eMBRegisterMode mode)
|
||||
{
|
||||
eMBErrorCode mberr = MB_ENOERR;
|
||||
int index;
|
||||
@@ -649,7 +657,8 @@ eMBErrorCode eMBRegCoilsCB(uint8_t *buffer, uint16_t address, uint16_t ncoils,
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
eMBErrorCode eMBRegDiscreteCB(uint8_t *buffer, uint16_t address, uint16_t ndiscrete)
|
||||
eMBErrorCode eMBRegDiscreteCB(uint8_t *buffer, uint16_t address,
|
||||
uint16_t ndiscrete)
|
||||
{
|
||||
return MB_ENOREG;
|
||||
}
|
||||
|
Reference in New Issue
Block a user