Skip to content

Commit

Permalink
Add check that all slaves are present
Browse files Browse the repository at this point in the history
  • Loading branch information
rtlaka committed Jan 31, 2018
1 parent cd243de commit f329d2f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions soem/ethercatmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -724,11 +724,19 @@ int ecx_readstate(ecx_contextt *context)
ec_alstatust sl[MAX_FPRD_MULTI];
uint16 slca[MAX_FPRD_MULTI];
boolean noerrorflag, allslavessamestate;
boolean allslavespresent = FALSE;
int wkc;

/* Try to establish the state of all slaves sending only one broadcast datargam.
* This way a number of datagrams equal to the number of slaves will be sent only if needed.*/
rval = 0;
ecx_BRD(context->port, 0, ECT_REG_ALSTAT, sizeof(rval), &rval, EC_TIMEOUTRET);
wkc = ecx_BRD(context->port, 0, ECT_REG_ALSTAT, sizeof(rval), &rval, EC_TIMEOUTRET);

if(wkc == *(context->slavecount))
{
allslavespresent = TRUE;
}

rval = etohs(rval);
bitwisestate = (rval & 0x0f);

Expand Down Expand Up @@ -757,7 +765,7 @@ int ecx_readstate(ecx_contextt *context)
break;
}

if (noerrorflag && allslavessamestate)
if (noerrorflag && allslavessamestate && allslavespresent)
{
/* No slave has toggled the error flag so the alstatuscode
* (even if different from 0) should be ignored and
Expand Down

0 comments on commit f329d2f

Please sign in to comment.