Skip to content
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

Closed
acassis opened this issue Feb 6, 2024 · 2 comments · Fixed by apache/nuttx-apps#2288
Closed

Modbus Master example was broken by PR #6038 #11666

acassis opened this issue Feb 6, 2024 · 2 comments · Fixed by apache/nuttx-apps#2288

Comments

@acassis
Copy link
Contributor

acassis commented Feb 6, 2024

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

@JorgeGzm
Copy link
Contributor

JorgeGzm commented Feb 7, 2024

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++;
    }

@xiaoxiang781216
Copy link
Contributor

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
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants