-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
ASCII support #275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
ASCII support #275
Conversation
First review: good work! |
Hi,
static int _modbus_ascii_build_response_basis(sft_t *sft, uint8_t *rsp)
{
rsp[0] = ':';
rsp[1] = sft->slave;
rsp[2] = sft->function;
return _MODBUS_ASCII_PRESET_RSP_LENGTH;
} Redefining _MODBUS_ASCII_PRESET_RSP_LENGTH macro as follows _MODBUS_ASCII_PRESET_RSP_LENGTH 3
static ssize_t _modbus_ascii_send(modbus_t *ctx, const uint8_t *req, int req_length)
{
uint8_t ascii_req[3 + (MODBUS_ASCII_MAX_ADU_LENGTH * 2)];
ssize_t i, j = 0;
for (i = 0; i < req_length; i++) {
if ((i == 0 && req[i] == ':') ||
((i == req_length - 2) && (req[i] == '\r')) ||
((i == req_length - 1) && (req[i] == '\n')))
{
ascii_req[j++] = req[i];
} else {
ascii_req[j++] = nibble_to_hex_ascii(req[i] >> 4);
ascii_req[j++] = nibble_to_hex_ascii(req[i] & 0x0f);
}
}
ascii_req[j] = '\0';
ssize_t size = _modbus_serial_send(ctx, ascii_req, j);
return ((size - 3) / 2) +3;
} |
Thank you @jbysewski and @AlexLonardi . I created a new branch called https://github.com/stephane/libmodbus/tree/ascii-support to work on that, I need help to work on:
|
I am looking to use the ascii-support in libmodbus. What is the current working status for the branch? Is it stable enough to work with? |
hi |
good job |
ascii-support branch has a double free bug in rtu mode, this line needs to be deleted, Line 185 in 787e6ba
|
This patch extracts common serial driver functionality into modbus-serial*.c/h and adds modbus-ascii upon this common serial driver. I was able to test the implementation against a chain of RS485/Modbus ASCII pressure sensors.
The setting of serial mode and rts is done via a forward to the modbus-serial module which keeps the current API but is not very clean IMHO.
Heads-up:
Some of the ascii implementation is based upon patches/pull-requests surrounding this project.
Google groups thread: https://groups.google.com/forum/#!topic/libmodbus/2A-ocabMhrE