Using enumerations in XML file with Connector for Python

6 posts / 0 new
Last post
Offline
Joined: 01/03/2018
Posts: 4
Using enumerations in XML file with Connector for Python

I have installed the rticonnextdds-connector-master for Python script support and successfully ran the simple ShapeExample demo.  I then tried to modify the XML based on some IDL->XML generated code from rtiddsgen that we are using, as follows:

<enum name="TestEnum">
      <enumerator name="FIRST_THING"/>
      <enumerator name="SECOND_THING"/>
 </enum>
         

<struct name= "TestOnly" nested="true">
      <member name="string_member" type="string" stringMaxLength="TestEnum::SECOND_THING"/>
</struct>

The python call to rti.Connector fails with the message:

DDS_XMLTypeCode_get_const_value:constant 'TestEnum::SECOND_THING' not found

Any help in how to use enumerations here would be appreciated.

 

Organization:
isabel's picture
Offline
Joined: 02/13/2017
Posts: 5

Hi sourcebug,

In the GitHub of connector you can find a type with an enum:

https://github.com/rticommunity/rticonnextdds-connector/blob/master/examples/python/ShapeExample.xml

I think that the issue you are facing is related to using "TestEnum::SECOND_THING" as stringMaxLength.
Could you please change this length to the following?

<member name="string_member" type="string" stringMaxLength="TestEnum"/>

Let us know if this helps.

Regards,
Isabel

Offline
Joined: 01/03/2018
Posts: 4

Thank you for your response.  It does quiet the interpreter.  Two issues:

1.  Using the name of the enum "TestEnum" does not set a value for stringMaxLength.

2.  When generating with rtiddsgen, the IDL->XML transformation produceds the name::value construct.  Using IDL:

enum MainStatusIndex
{
    MAIN_STATUS_INDEX_NONE = 0xFF,
    MAIN_STATUS_INDEX_1 = 0,
    MAIN_STATUS_INDEX_2,
    MAIN_STATUS_INDEX_3,
    MAIN_STATUS_INDEX_4,
    MAIN_STATUS_INDEX_COUNT
};

enum SecondStatusIndex
{
    SECOND_STATUS_INDEX_NONE = 0xFF,
    SECOND_STATUS_INDEX_1 = 0,
    SECOND_STATUS_INDEX_2,
    SECOND_STATUS_INDEX_COUNT
};

struct AllThingsState
{
    unsigned short main_statuses[MAIN_STATUS_INDEX_COUNT];
    unsigned short second_statuses[SECOND_STATUS_INDEX_COUNT];
};

Produces XML:
<struct name= "AllThingsState">
  <member name="main_statuses" type="unsignedShort" arrayDimensions="(MainStatusIndex::MAIN_STATUS_INDEX_COUNT)"/>
  <member name="second_statuses" type="unsignedShort" arrayDimensions="(SecondStatusIndex::SECOND_STATUS_INDEX_COUNT)"/>
</struct>

which is not parsed by the rti.Connector call.

isabel's picture
Offline
Joined: 02/13/2017
Posts: 5

Hi sourcebug,

Using enums as a size of an array is not currently supported.
Right now you need to use a constant int for this, either explicitly or creating a constant in your IDL.

Regards,
Isabel

Offline
Joined: 01/03/2018
Posts: 4

Another enum question.  The example doesn't show how you write an enum in python.  Can you tell me whether to use setString or setNumber and show the correct syntax for doing this?

Thanks!

Offline
Joined: 01/03/2018
Posts: 4

Again, please show an example of using an enumerate to set a value of an element.  Thanks.