示例#1
0
        public override void RunExample(string[] args)
        {
            base.RunExample(args);

            DomainParticipantFactory factory = DomainParticipantFactory.GetInstance(Bootstrap.CreateInstance());
            DomainParticipant        dp      = factory.CreateParticipant();

            // Implicitly create TypeSupport and register type:
            Topic <Greeting> tp = dp.CreateTopic <Greeting>("Greetings Topic");

            // Create the publisher
            Publisher pub = dp.CreatePublisher();

            /* DataWriter<Greeting> dw = pub.CreateDataWriter(tp);
             *
             */

            DataWriter <Greeting> dw = pub.CreateDataWriter <Greeting>(tp,
                                                                       pub.GetDefaultDataWriterQos(), null, null);
            // Create the subscriber
            Subscriber sub = dp.CreateSubscriber();
            DataReaderListener <Greeting> ls = new MyListener();
            /*DataReader<Greeting> dr = sub.CreateDataReader(tp);*/

            DataReader <Greeting> dr = sub.CreateDataReader <Greeting>(tp,
                                                                       sub.GetDefaultDataReaderQos(),
                                                                       ls,
                                                                       null);

            /*
             * // Now Publish some piece of data
             * Greeting data = new Greeting("Hello, World with DDS.");
             * Console.WriteLine("Sending data:\"{0}\"", data.Value);
             * dw.Write(data);
             * //and check that the reader has this data
             * dr.WaitForHistoricalData(10, TimeUnit.SECONDS);
             *
             */
            int i = 0;

            // Now Publish some piece of data
            //Greeting data = new Greeting("Hola Mundo"+ i.ToString());


            for (i = 0; i < 1; i++)
            {
                Greeting data = new Greeting("Hola Mundo" + i.ToString());

                Console.WriteLine("Sending data:\"{0}\"", data.Value);
                dw.Write(data);
                dr.WaitForHistoricalData(1500, TimeUnit.MILLISECONDS);
            }


            //and check that the reader has this data
            //dr.WaitForHistoricalData(10000, TimeUnit.SECONDS);

            dp.Close();
        }
示例#2
0
        private void InitializeDDS()
        {
            //string id = usuario.Id;
            string id = "0";

            int.TryParse(id, out domainId);


            // Create the DomainFactory
            factory = DomainParticipantFactory.GetInstance(Bootstrap.CreateInstance());
            // Create the DomainParticipant with reference to the configuration file with the domain ID
            dp = factory.CreateParticipant(domainId);
            // Console.WriteLine("Domain ID = {0} has been created", domainId);
            // Implicitly create TypeSupport and register type:
            tp = dp.CreateTopic <ChatMessage>("Greetings Topic");
            // Create the subscriber
            sub = dp.CreateSubscriber();
            // Create a Listener for the publishing data
            ls = new MyListener(backgroundWorker1, backgroundWorker2, backgroundWorker3, backgroundWorker4, backgroundWorker5,
                                backgroundWorker6);
            ls2 = new MyListener2();
            // Create the DataReader using the topic, politics of QoS for DataReader and implemented listener
            dr = sub.CreateDataReader <ChatMessage>(tp,
                                                    sub.GetDefaultDataReaderQos(),
                                                    ls,
                                                    null);



            // Create the publisher
            pub = dp.CreatePublisher();
            // Create the DataWriter using the topic specified
            //dw = pub.CreateDataWriter(tp);

            dw = pub.CreateDataWriter <ChatMessage>(tp,
                                                    pub.GetDefaultDataWriterQos(),
                                                    ls2,
                                                    null);
        }