Conversation
|
here two scripts in python that can be used for testing: |
|
Whoah! Amazing work BIG THANK YOU @raiden00pl !! =) Can we put the python test scripts under nuttx/tools/modbus? These are very handy for testing and I created something like that myself too. Would be nice to have them in the repo :-) Very popular GUI open-source modbus client application is https://sourceforge.net/projects/qmodmaster/. |
NxModbus is a lightweight Modbus protocol stack implementation for NuttX RTOS. This commit adds: - nxmodbus stack - nxmbserver - Modbus Server (Slave) example - nxmbclient - Modbus Client (Master) tool Supported Modbus transports: - ASCII - RTU over serial port - TCP - RAW (ADU) for custom transport implementations Signed-off-by: raiden00pl <raiden00@railab.me>
acassis
left a comment
There was a problem hiding this comment.
@raiden00pl Amazing work! Kudos!
|
|
||
| pthread_mutex_lock(&ctx->lock); | ||
|
|
||
| ctx->server_id_len = 0; |
There was a problem hiding this comment.
Please fix alignment, just one space or put all at the same column
| * | ||
| * Description: | ||
| * Build a Modbus exception response in ctx->adu in place. | ||
| * |
There was a problem hiding this comment.
Please include the Input Parameters
| * Description: | ||
| * Handle FC08 Diagnostics request. Only sub-function 0x0000 (Return Query | ||
| * Data) is supported — it echoes the request data back unchanged. | ||
| * |
There was a problem hiding this comment.
Please include Input Parameter and Return type
| * Private Data | ||
| ****************************************************************************/ | ||
|
|
||
| static const uint16_t g_crc16_table[256] = |
There was a problem hiding this comment.
I think CRC implementation could come from include/nuttx/crc16.h or a new header file there
masc2008
left a comment
There was a problem hiding this comment.
Overall, this is a great feature!
| nxmb_util_put_u16_be(&ctx->adu.data[0], addr); | ||
| nxmb_util_put_u16_be(&ctx->adu.data[2], count); | ||
| ctx->adu.data[4] = nbytes; | ||
| memcpy(&ctx->adu.data[5], buf, nbytes); |
There was a problem hiding this comment.
it's better to do a sanity check.
in adu structure: data[NXMB_ADU_DATA_MAX]; this is an array that size can be configured.
it can overflow ctx->adu.data[] if "count > NXMB_ADU_DATA_MAX".
similar check needed nxmb_write_holdings and nxmb_readwrite_holdings.
Summary
NxModbus is a lightweight Modbus protocol stack implementation for NuttX RTOS.
This commit adds:
Supported Modbus transports:
It takes some concepts from FreeModBus and some from Zephyr Modbus implementation.
Impact
new modbus stack
Testing
simulator for RTU, qemu-intel64 for TCP, nucleo-c071rb for RTU.
response time on nucleo-c071rb is 10-20ms so it fixes my main issue with freemodbus #3037:
