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.
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?
Let us know if this helps.
Regards,
Isabel
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.
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
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!
Again, please show an example of using an enumerate to set a value of an element. Thanks.
Hello,
I created a simple example on how to set an enum using setNumber. You can access the python code and the relative xml here: https://gist.github.com/gianpiero/4933e0ab3bf3a2f9fb2f395fcf345671
Best,
Gianpiero
Check this one..Python enum
Hi Gianpiero,
I realize this example is old, but can you answer a secondary question in this case? You're defining in your python code:
The definition in the IDL/XML is defined already as:
So my question is, can you bypass the redundant dictionary definition in Python and access the enums from your IDL/XML directly through your Connector? To clarify, I'd mean something more like this, even though this is essentially fake code:
Let's say I have literally dozens of idl defined enums, so the python dictionary definitions are lengthy and redundant. Is there any way to achieve this usage using the connector in any way? This is normally pretty simple in the C++ implementation.
Anyone have ideas on this?
Hey scrowe,
Unfortunately that is not currently possible. So maintaining a dictionary of the enum is required. The setters for enums only accept integer values currently. I have created an RFE CON-204 which addresses the behaviour you are requesting.
Until then, maybe there is a way you can parse the XML in Python yourself to automatically generate that dictionary?
Sam