
Deavis (Customer) asked a question.
I am trying to read from the SDO in a ST program and keep getting a STAT error code of 9 but that error code isn't listed in the XPM function documentation. The documentation for this command is poor and contains no example like many others. I believe the syntax to be correct for reading the homing method parameter from axis 1 (i.e. slave 1) that is connected to the PN04B.
INST_XPM_READSDO(REQ:=(1), BASE:=(ETHERCAT_MODULE_1.Base_Address), SLOT:=(ETHERCAT_MODULE_1.Slot_Address), SLAVE:=(1), INDEX:=(16#6098), SUBINDEX:=(16#00), LENGTH:=(2), DONE=>(INST_XPM_READSDO.DONE), STAT=>(INST_XPM_READSDO.STAT), DATA=>(INST_XPM_READSDO.DATA));
where the base address and slot address are 0 and 2, which is where the PN04B is located. I have no issues issuing other commands and them being accepted and working.
monitoring in debug mode shows the following after execution:
INST_XPM_READSDO.DONE = 0; INST_XPM_READSDO.STAT = 9; INST_XPM_READSDO.DATA = 0
I've tried the command in LD as well and each time it returns a STAT error of 9 no matter that index, subindex, or length that I attempt to read. The address from the positioning tool for slave 1 and the value I expect returned
Any ideas where I am going wrong with this command?
The XPM_READSDO function block is used for I/O that would be slave number 17-32.
To read the Homing Method for a servo drive that is axis 1, you should use XPM_SVPRD. I have tried it with an iX7 and it works as expected. Screenshot of the function block is attached. It is similar to XPM_READSDO.
Yes, I have connected to the network using that command prior to calling any other functions, including this one. I am able to execute movement and homing commands but not this one.
I updated my post to include the XPM function block that should be used. Use XPM_SVPRD instead.
I see the mistake in the function choice, however I still get some odd behavior in my code. I can execute and get values now using a series of IF-THEN statements but I can't make it work within a CASE statement which seems strange
This code works as expected and gathers the correct values
data_holder := 16#0000;
index_var := 16#607D;
subindex_var := 16#02;
INST_XPM_ECON(REQ:=(1), BASE:=(0), SLOT:=(2), DONE=>(INST_XPM_ECON.DONE), STAT=>(INST_XPM_ECON.STAT));
IF (INST_XPM_ECON.DONE) THEN
INST_XPM_SVPRD1(REQ:=(1), BASE:=(0), SLOT:=(2), AXIS:=(1), INDEX:=(index_var), SUBINDEX:=(subindex_var), LENGTH:=(4),
DONE=>(INST_XPM_SVPRD1.DONE), STAT=>(INST_XPM_SVPRD1.STAT), DATA=>(INST_XPM_SVPRD1.DATA));
END_IF;
IF (INST_XPM_SVPRD1.DONE) THEN
data_holder := INST_XPM_SVPRD1.DATA;
END_IF;
Placing this inside a case statement however does not work, which should be the equivalent control structure.
CASE Machine_State OF
0: INST_XPM_ECON(REQ:=(1), BASE:=(0), SLOT:=(2), DONE=>(INST_XPM_ECON.DONE), STAT=>(INST_XPM_ECON.STAT));
Machine_State := 1;
1: IF (INST_XPM_ECON.DONE) THEN
INST_XPM_SVPRD1(REQ:=(1), BASE:=(0), SLOT:=(2), AXIS:=(1), INDEX:=(index_var), SUBINDEX:=(subindex_var), LENGTH:=(4),
DONE=>(INST_XPM_SVPRD1.DONE), STAT=>(INST_XPM_SVPRD1.STAT), DATA=>(INST_XPM_SVPRD1.DATA));
Machine_State := 2;
END_IF;
2: IF (INST_XPM_SVPRD1.DONE) THEN
data_holder := INST_XPM_SVPRD1.DATA;
Machine_State := 3;
END_IF;
3: ;
I'm sure it is something small but I can't see why these commands don't work within the confines of a CASE statement that is similar to the examples for motion control.
I would recommend putting the function calls outside of the CASE state machine. Use variables to enable/disable the function blocks inside of the State machine.
Thank you, I determined that you cannot execute a function in a single cycle within the case statement. For whatever reason functions do not properly update their output variables unless the function block is seen on multiple scan cycles. They are not fire and forget as one would expect in normal programming environments. Simply moving the IF statement that monitors the .DONE variable into the same state and gating the next state transition solves this behavior. It is a very frustrating thing to learn that functions are not single scan cycle capable and that they must be "maintained" before moving within a CASE structure.