Merge pull request #155 from nakarlsson/master

Add check that all slaves are present
This commit is contained in:
nakarlsson 2018-02-01 10:50:02 +01:00 committed by GitHub
commit fc945ba86b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 2 deletions

View File

@ -724,11 +724,19 @@ int ecx_readstate(ecx_contextt *context)
ec_alstatust sl[MAX_FPRD_MULTI]; ec_alstatust sl[MAX_FPRD_MULTI];
uint16 slca[MAX_FPRD_MULTI]; uint16 slca[MAX_FPRD_MULTI];
boolean noerrorflag, allslavessamestate; boolean noerrorflag, allslavessamestate;
boolean allslavespresent = FALSE;
int wkc;
/* Try to establish the state of all slaves sending only one broadcast datargam. /* 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.*/ * This way a number of datagrams equal to the number of slaves will be sent only if needed.*/
rval = 0; 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); rval = etohs(rval);
bitwisestate = (rval & 0x0f); bitwisestate = (rval & 0x0f);
@ -757,7 +765,7 @@ int ecx_readstate(ecx_contextt *context)
break; break;
} }
if (noerrorflag && allslavessamestate) if (noerrorflag && allslavessamestate && allslavespresent)
{ {
/* No slave has toggled the error flag so the alstatuscode /* No slave has toggled the error flag so the alstatuscode
* (even if different from 0) should be ignored and * (even if different from 0) should be ignored and