Use a state machine:
- Step 1: Configure the FUB for the first index, go to step 2
- Step 2: Check if the status output is ERR_OK, do so until you either get ERR_OK (that’s success) - go to the next step - or anything other than ERR_FUB_BUSY (that would then be an errror) - go to error handling step
- Step 3: With the data received, do what you want to do; Increment the subindex of the FUB by 1, check if it’s already higher than 0x0A, if so, make it 1 again; Go back to step 2
1:
// insert SDOread config here
SDOread.enable := TRUE;
SDOread.index := 16#1203;
SDOread.subindex := 1;
step := 2;
2:
IF SDOread.status == ERR_OK THEN
// We have finished reading
SDOread.enable := FALSE;
step := 3;
ELIF SDOread.status <> ERR_FUB_BUSY THEN
// Error Handling
END_IF
3:
// Do whatever you like to do with the data here
// increment subindex, check for "overflow" (> 0x0A), makeit subindex 1 if so
// return to step 2
step := 2;
END_CASE
// Call the FUB here
CANopenSDORead8();
Just like you would call every other function block that’s marked that way.
Reminder: The code is already run cyclically, which is why you use that as your loop
Reminder: Give the steps proper names using an enum, don’t use magic numbers!