OpenEtherCATsociety / SOES

Simple Open Source EtherCAT Slave
Other
587 stars 251 forks source link

Issue with Changing Variable Type in seos-demo RaspberryPi-lan9252 Application #155

Closed Amir7RN closed 1 year ago

Amir7RN commented 1 year ago

I am encountering an issue while attempting to modify the variable type of an input in the seos-demo application for the raspberry_lan9252demo. The original application features six inputs (button0 to button5) and six outputs (LED0 to LED5), all of which are boolean data types. However, I would like to assign an integer value to one of the inputs, specifically button0, and monitor it in TwinCAT.

To achieve this, I manually made changes to the slave.xml file as follows:

In the "DataType>" section:

<DataType>
    <Name>DT6000</Name>
    <BitSize>64</BitSize>
    <SubItem>
        <SubIdx>0</SubIdx>
        <Name>Max SubIndex</Name>
        <Type>USINT</Type>
        <BitSize>8</BitSize>
        <BitOffs>0</BitOffs>
        <Flags>
            <Access>ro</Access>
        </Flags>
    </SubItem>
    <SubItem>
        <SubIdx>1</SubIdx>
        <Name>Button0</Name>
        <Type>INT</Type> <!-- Changed from BOOL to INT -->
        <BitSize>16</BitSize> <!-- Changed from 1 to 16 -->
        <BitOffs>0</BitOffs> <!-- Changed from 16 to 0 -->
        <Flags>
            <Access>ro</Access>
            <PdoMapping>T</PdoMapping>
        </Flags>
    </SubItem>
</DataType>

In the section:

<TxPdo Fixed="true" Mandatory="true" Sm="3">
    <Index>#x1A00</Index>
    <Name>Buttons</Name>
    <Entry>
        <Index>#x6000</Index>
        <SubIndex>#x1</SubIndex>
        <BitLen>16</BitLen> <!-- Changed from 1 to 16 -->
        <Name>Button0</Name>
        <DataType>INT</DataType> <!-- Changed from BOOL to INT -->
    </Entry>
</TxPdo>

I also change the slave_ObjectList.c as follows:

const _objd SDO6000[] =
{
  {0x00, DTYPE_UNSIGNED8, 8, ATYPE_RO, acName6000_00, 6, NULL},
  {0x01, DTYPE_BOOLEAN, 1, ATYPE_RO | ATYPE_TXPDO, acName6000_01, 0, &Obj.Buttons.Button0}, Cahnged to  {0x01, DTYPE_INTEGER16, 16, ATYPE_RO | ATYPE_TXPDO, acName6000_01, 0, &Obj.Buttons.Button0}
  {0x02, DTYPE_BOOLEAN, 1, ATYPE_RO | ATYPE_TXPDO, acName6000_02, 0, &Obj.Buttons.Button1},
  {0x03, DTYPE_BOOLEAN, 1, ATYPE_RO | ATYPE_TXPDO, acName6000_03, 0, &Obj.Buttons.Button2},
  {0x04, DTYPE_BOOLEAN, 1, ATYPE_RO | ATYPE_TXPDO, acName6000_04, 0, &Obj.Buttons.Button3},
  {0x05, DTYPE_BOOLEAN, 1, ATYPE_RO | ATYPE_TXPDO, acName6000_05, 0, &Obj.Buttons.Button4},
  {0x06, DTYPE_BOOLEAN, 1, ATYPE_RO | ATYPE_TXPDO, acName6000_06, 0, &Obj.Buttons.Button5},
};

and utypes.h

struct
   {
      uint8_t Button0; changed to int16_t Button0;
      uint8_t Button1;
      uint8_t Button2;
      uint8_t Button3;
      uint8_t Button4;
      uint8_t Button5;
   } Buttons;

However, after making these manual changes, I encountered an error preventing the slave from entering the operating mode (ERR PREOP). I am seeking assistance to resolve this issue. Could you please provide guidance on changing the variable type correctly? Should I make any additional modifications, or is updating the XML file sufficient?

Thank you for your support.

nakarlsson commented 1 year ago

I never do this manually, it is an a tedious job that is very error prone. For starter the PDO object length is not updated, se below. Update that and see, might be more issues lurking.

Basically, you need to keep the XML (ESI), objectlist (ObjectDictionary) and EEPROM (SII) aligned for the SOES stack to accept the changes. So, if the above is not enough you need to check all entries that described the "same thing" so they are updated.

const _objd SDO1A00[] =
{
  {0x00, DTYPE_UNSIGNED8, 8, ATYPE_RO, acName1A00_00, 7, NULL},
  {0x01, DTYPE_UNSIGNED32, 32, ATYPE_RO, acName1A00_01, 0x60000101, NULL},  <-  0x60000101 is not correct any more, it will result in erroneous length.   0x60000110 does add the 16 bit instead of a single bit
  {0x02, DTYPE_UNSIGNED32, 32, ATYPE_RO, acName1A00_02, 0x60000201, NULL},
  {0x03, DTYPE_UNSIGNED32, 32, ATYPE_RO, acName1A00_03, 0x60000301, NULL},
  {0x04, DTYPE_UNSIGNED32, 32, ATYPE_RO, acName1A00_04, 0x60000401, NULL},
  {0x05, DTYPE_UNSIGNED32, 32, ATYPE_RO, acName1A00_05, 0x60000501, NULL},
  {0x06, DTYPE_UNSIGNED32, 32, ATYPE_RO, acName1A00_06, 0x60000601, NULL},
  {0x07, DTYPE_UNSIGNED32, 32, ATYPE_RO, acName1A00_07, 0x00000002, NULL},
};
Amir7RN commented 1 year ago

@nakarlsson, your awesome comment resolved my issue. Thanks!