-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Modbus Master example was broken by PR #6038 #11666
Comments
Hi, Testing the modbus master example: nuttx-apps/examples/modbusmaster/mbmaster_main.c Whe check, if we add a delay before call the function eMBMasterReqReadHoldingRegister the problem stop and the the aplication back to work. printf("Sending %d requests to slave %d\n",
MBMASTER_REQUESTS_COUNT, SLAVE_ID);
usleep(1000); // Delay ADD
/* modbus is initialized and polling thread is running */
while (reqcounter < MBMASTER_REQUESTS_COUNT)
{
g_mbmaster.statistics.reqcount++;
mberr = eMBMasterReqReadHoldingRegister(SLAVE_ID,
SLAVE_STATUS_REG, 1, 1000);
if (mberr != MB_MRE_NO_ERR)
{
fprintf(stderr, "mbmaster_main: "
"ERROR: holding reg %d read failed: %d\n",
SLAVE_STATUS_REG, mberr);
g_mbmaster.statistics.errcount++;
}
reqcounter++;
} |
look like eMBMasterPoll can't be called before eMBMasterReqReadHoldingRegister? #6038 optimize the speed of thread creation, the new thread may run before pthread_create return. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
While helping @JorgeGzm to get Modbus Master working on his board we discovered that the mailing example was not working. Then I did some tests with different release versions and discovered it was broken between 10.3 and 11.0!
Then we did a git bisect and discovered that this PR #6038 was responsible for generating the issue.
Jorge discovered that adding a usleep() before acquiring the semaphore on FreeModbus helped to fix the issue, but we still investigation why that commit cause this issue. Hi @anjiahao1 could you please take a look? Maybe you can have some idea why this issue is happening. If you want to test the Modbus Example, I have a tutorial here: https://www.youtube.com/watch?v=FmJLrG4Ldow
The text was updated successfully, but these errors were encountered: