Skip to content
Snippets Groups Projects
Commit 1a2e8d6f authored by patacongo's avatar patacongo
Browse files

Make serial setup configurale in apps/examples/modbus

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4966 42af7a65-404d-4744-a932-0658087f49c3
parent 29076ea2
No related branches found
No related tags found
No related merge requests found
...@@ -490,6 +490,10 @@ examples/modbus ...@@ -490,6 +490,10 @@ examples/modbus
demos/LINUX directory of the FreeModBus version 1.5.0 (June 6, 2010) demos/LINUX directory of the FreeModBus version 1.5.0 (June 6, 2010)
that can be downloaded in its entirety from http://developer.berlios.de/project/showfiles.php?group_id=6120. that can be downloaded in its entirety from http://developer.berlios.de/project/showfiles.php?group_id=6120.
CONFIG_EXAMPLES_MODBUS_PORT, Default 0 (for /dev/ttyS0)
CONFIG_EXAMPLES_MODBUS_BAUD, Default 38400
CONFIG_EXAMPLES_MODBUS_PARITY, Default MB_PAR_EVEN
CONFIG_EXAMPLES_MODBUS_REG_INPUT_START, Default 1000 CONFIG_EXAMPLES_MODBUS_REG_INPUT_START, Default 1000
CONFIG_EXAMPLES_MODBUS_REG_INPUT_NREGS, Default 4 CONFIG_EXAMPLES_MODBUS_REG_INPUT_NREGS, Default 4
CONFIG_EXAMPLES_MODBUS_REG_HOLDING_START, Default 2000 CONFIG_EXAMPLES_MODBUS_REG_HOLDING_START, Default 2000
......
...@@ -75,6 +75,18 @@ ...@@ -75,6 +75,18 @@
****************************************************************************/ ****************************************************************************/
/* Configuration ************************************************************/ /* Configuration ************************************************************/
#ifndef CONFIG_EXAMPLES_MODBUS_PORT
# define CONFIG_EXAMPLES_MODBUS_PORT 0
#endif
#ifndef CONFIG_EXAMPLES_MODBUS_BAUD
# define CONFIG_EXAMPLES_MODBUS_BAUD 38400
#endif
#ifndef CONFIG_EXAMPLES_MODBUS_PARITY
# define CONFIG_EXAMPLES_MODBUS_PARITY MB_PAR_EVEN
#endif
#ifndef CONFIG_EXAMPLES_MODBUS_REG_INPUT_START #ifndef CONFIG_EXAMPLES_MODBUS_REG_INPUT_START
# define CONFIG_EXAMPLES_MODBUS_REG_INPUT_START 1000 # define CONFIG_EXAMPLES_MODBUS_REG_INPUT_START 1000
#endif #endif
...@@ -175,9 +187,17 @@ static inline int modbus_initialize(void) ...@@ -175,9 +187,17 @@ static inline int modbus_initialize(void)
status = ENODEV; status = ENODEV;
/* Initialize the FreeModBus library */ /* Initialize the FreeModBus library.
*
mberr = eMBInit(MB_RTU, 0X0A, 0, 38400, MB_PAR_EVEN); * MB_RTU = RTU mode
* 0x0a = Slave address
* CONFIG_EXAMPLES_MODBUS_PORT = port, default=0 (i.e., /dev/ttyS0)
* CONFIG_EXAMPLES_MODBUS_BAUD = baud, default=38400
* CONFIG_EXAMPLES_MODBUS_PARITY = parity, default=MB_PAR_EVEN
*/
mberr = eMBInit(MB_RTU, 0x0a, CONFIG_EXAMPLES_MODBUS_PORT,
CONFIG_EXAMPLES_MODBUS_BAUD, CONFIG_EXAMPLES_MODBUS_PARITY);
if (mberr != MB_ENOERR) if (mberr != MB_ENOERR)
{ {
fprintf(stderr, MAIN_NAME_STRING fprintf(stderr, MAIN_NAME_STRING
...@@ -185,9 +205,15 @@ static inline int modbus_initialize(void) ...@@ -185,9 +205,15 @@ static inline int modbus_initialize(void)
goto errout_with_mutex; goto errout_with_mutex;
} }
/* Set the slave ID */ /* Set the slave ID
*
mberr = eMBSetSlaveID(0x34, TRUE, g_slaveid, 3); * 0x34 = Slave ID
* true = Is running (run indicator status = 0xff)
* g_slaveid = Additional values to be returned with the slave ID
* 3 = Length of additional values (in bytes)
*/
mberr = eMBSetSlaveID(0x34, true, g_slaveid, 3);
if (mberr != MB_ENOERR) if (mberr != MB_ENOERR)
{ {
fprintf(stderr, MAIN_NAME_STRING fprintf(stderr, MAIN_NAME_STRING
...@@ -345,7 +371,7 @@ int MAIN_NAME(int argc, char *argv[]) ...@@ -345,7 +371,7 @@ int MAIN_NAME(int argc, char *argv[])
/* Handle command line arguments */ /* Handle command line arguments */
g_modbus.quit = FALSE; g_modbus.quit = false;
while ((option = getopt(argc, argv, "desqh")) != ERROR) while ((option = getopt(argc, argv, "desqh")) != ERROR)
{ {
...@@ -393,7 +419,7 @@ int MAIN_NAME(int argc, char *argv[]) ...@@ -393,7 +419,7 @@ int MAIN_NAME(int argc, char *argv[])
break; break;
case 'q': /* Quit application */ case 'q': /* Quit application */
g_modbus.quit = TRUE; g_modbus.quit = true;
pthread_kill(g_modbus.threadid, 9); pthread_kill(g_modbus.threadid, 9);
break; break;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment