Created
January 23, 2018 23:10
-
-
Save gianpiero/4933e0ab3bf3a2f9fb2f395fcf345671 to your computer and use it in GitHub Desktop.
Example on how to set an enum with python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<dds> | |
<types> | |
<enum name="COLOR"> | |
<enumerator name="RED" value="0"/> | |
<enumerator name="BLUE" value="1"/> | |
<enumerator name="YELLOW" value="2"/> | |
</enum> | |
<struct name="Foo"> | |
<member name="id" type="long"/> | |
<member name="myColor" type="nonBasic" nonBasicTypeName="COLOR"/> | |
</struct> | |
</types> | |
<domain_library name="MyDomainLibrary"> | |
<domain name="MyDomain" domain_id="0"> | |
<register_type name="FooRegistered" type_ref="Foo"/> | |
<topic name="MyTopic" register_type_ref="FooRegistered"/> | |
</domain> | |
</domain_library> | |
<domain_participant_library name="MyParticipantLibrary"> | |
<domain_participant name="MyParticipant" domain_ref="MyDomainLibrary::MyDomain"> | |
<publisher name="MyPub"> | |
<data_writer name="MyTopicWriter" topic_ref="MyTopic"/> | |
</publisher> | |
</domain_participant> | |
</domain_participant_library> | |
</dds> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################################################## | |
# Copyright (c) 2005-2015 Real-Time Innovations, Inc. All rights reserved. | |
# Permission to modify and use for internal purposes granted. | |
# This software is provided "as is", without warranty, express or implied. | |
############################################################################## | |
"""Samples's writer.""" | |
from sys import path as sysPath | |
from os import path as osPath | |
from time import sleep | |
filepath = osPath.dirname(osPath.realpath(__file__)) | |
sysPath.append(filepath + "/../../../") | |
import rticonnextdds_connector as rti | |
connector = rti.Connector("MyParticipantLibrary::MyParticipant", | |
filepath + "/EnumExample.xml") | |
outputDDS = connector.getOutput("MyPub::MyTopicWriter") | |
COLORS = {"RED":0, "BLUE":1, "YELLOW":2} | |
for i in range(1, 500): | |
outputDDS.instance.setNumber("id", i) | |
outputDDS.instance.setNumber("myColor", COLORS["RED"]) | |
#outputDDS.instance.setNumber("myColor", 0) | |
outputDDS.write() | |
sleep(2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment