Esempio n. 1
0
        static void test_LuaConsole(String host, int port)
        {
            try {
                Client client = new Client(host, port);

                Console.WriteLine("Connected to " + host + ":" + port);

                String chunk =
                    "if not node.is_reading() then" +
                    "   node.close()" +
                    "   node.scan()" +
                    "   node.start()" +
                    " end" +
                    " if node.is_reading() then" +
                    "   print('Reading from ' .. node.num_reading() .. ' device(s)')" +
                    " else" +
                    "   print('Failed to start reading')" +
                    " end";

                LuaConsole.ResultType result =
                    LuaConsole.SendChunk(client, chunk);

                if (LuaConsole.ResultCode.Success == result.first)
                {
                    Console.WriteLine(result.second);
                }
                else if (LuaConsole.ResultCode.Continue == result.first)
                {
                    Console.WriteLine("incomplete Lua chunk: " + result.second);
                }
                else
                {
                    Console.WriteLine("command failed: " + result.second);
                }

                client.close();
                client = null;
            } catch (Exception e) {
                Console.WriteLine(e.ToString());
            }
        }
Esempio n. 2
0
File: Test.cs Progetto: bmswgnp/sdk
        static void test_Client(String host, int port)
        {
            try {
            Client client = new Client(host, port);

            Console.WriteLine("Connected to " + host + ":" + port);

            // The Configurable data service requires that we specify a list of channels
            // that we would like to receive.
            if (PortConfigurable == port) {
              // Access the global quaternion and calibrated accelerometer streams.
              String xml_definition =
              "<?xml version=\"1.0\"?>" +
              "<configurable>" +
              "<preview><Gq/></preview>" +
              "<sensor><a/></sensor>" +
              "</configurable>";

              if (client.writeData(xml_definition)) {
            Console.WriteLine("Sent active channel definition to Configurable service");
              }
            }

            if (client.waitForData()) {
              int sample_count = 0;
              while (true) {
            byte[] data = client.readData();
            if ((null == data) || (sample_count++ >= NSample)) {
              break;
            }

            if (PortPreview == port) {
              IDictionary<int, Format.PreviewElement> container = Format.Preview(data);
              foreach (KeyValuePair<int, Format.PreviewElement> itr in container) {
                float[] q = itr.Value.getQuaternion(false);
                Console.WriteLine("q(" + itr.Key + ") = (" + q[0] + ", " + q[1] + "i, " + q[2] + "j, " + q[3] + "k)");
              }
            }

            if (PortSensor == port) {
              IDictionary<int, Format.SensorElement> container = Format.Sensor(data);
              foreach (KeyValuePair<int, Format.SensorElement> itr in container) {
                float[] a = itr.Value.getAccelerometer();
                Console.WriteLine("a(" + itr.Key + ") = (" + a[0] + ", " + a[1] + ", " + a[2] + ") g");
              }
            }

            if (PortRaw == port) {
              IDictionary<int, Format.RawElement> container = Format.Raw(data);
              foreach (KeyValuePair<int, Format.RawElement> itr in container) {
                short[] a = itr.Value.getAccelerometer();
                Console.WriteLine("a(" + itr.Key + ") = (" + a[0] + ", " + a[1] + ", " + a[2] + ") g");
              }
            }

            if (PortConfigurable == port) {
              IDictionary<int, Format.ConfigurableElement> container = Format.Configurable(data);
              foreach (KeyValuePair<int, Format.ConfigurableElement> itr in container) {
                Console.Write("data(" + itr.Key + ") = (");
                for (int i=0; i<itr.Value.size(); i++) {
                  if (i > 0) {
                    Console.Write(", ");
                  }
                  Console.Write(itr.Value.value(i));
                }
                Console.WriteLine(")");
              }
            }

              }
            }

            client.close();
            client = null;
              } catch (Exception e) {
            Console.WriteLine(e.ToString());
              }
        }
Esempio n. 3
0
File: Test.cs Progetto: bmswgnp/sdk
        static void test_LuaConsole(String host, int port)
        {
            try {
            Client client = new Client(host, port);

            Console.WriteLine("Connected to " + host + ":" + port);

            String chunk =
              "if not node.is_reading() then" +
              "   node.close()" +
              "   node.scan()" +
              "   node.start()" +
              " end" +
              " if node.is_reading() then" +
              "   print('Reading from ' .. node.num_reading() .. ' device(s)')" +
              " else" +
              "   print('Failed to start reading')" +
              " end";

            LuaConsole.ResultType result =
              LuaConsole.SendChunk(client, chunk);

            if (LuaConsole.ResultCode.Success == result.first) {
              Console.WriteLine(result.second);
            } else if (LuaConsole.ResultCode.Continue == result.first) {
              Console.WriteLine("incomplete Lua chunk: " + result.second);
            } else {
              Console.WriteLine("command failed: " + result.second);
            }

            client.close();
            client = null;
              } catch (Exception e) {
            Console.WriteLine(e.ToString());
              }
        }
Esempio n. 4
0
        static void test_Client(String host, int port)
        {
            try {
                Client client = new Client(host, port);

                Console.WriteLine("Connected to " + host + ":" + port);

                // The Configurable data service requires that we specify a list of channels
                // that we would like to receive.
                if (PortConfigurable == port)
                {
                    // Access the global quaternion and calibrated accelerometer streams.
                    String xml_definition =
                        "<?xml version=\"1.0\"?>" +
                        "<configurable>" +
                        "<preview><Gq/></preview>" +
                        "<sensor><a/></sensor>" +
                        "</configurable>";

                    if (client.writeData(xml_definition))
                    {
                        Console.WriteLine("Sent active channel definition to Configurable service");
                    }
                }

                if (client.waitForData())
                {
                    int sample_count = 0;
                    while (true)
                    {
                        byte[] data = client.readData();
                        if ((null == data) || (sample_count++ >= NSample))
                        {
                            break;
                        }

                        if (PortPreview == port)
                        {
                            IDictionary <int, Format.PreviewElement> container = Format.Preview(data);
                            foreach (KeyValuePair <int, Format.PreviewElement> itr in container)
                            {
                                float[] q = itr.Value.getQuaternion(false);
                                Console.WriteLine("q(" + itr.Key + ") = (" + q[0] + ", " + q[1] + "i, " + q[2] + "j, " + q[3] + "k)");
                            }
                        }

                        if (PortSensor == port)
                        {
                            IDictionary <int, Format.SensorElement> container = Format.Sensor(data);
                            foreach (KeyValuePair <int, Format.SensorElement> itr in container)
                            {
                                float[] a = itr.Value.getAccelerometer();
                                Console.WriteLine("a(" + itr.Key + ") = (" + a[0] + ", " + a[1] + ", " + a[2] + ") g");
                            }
                        }

                        if (PortRaw == port)
                        {
                            IDictionary <int, Format.RawElement> container = Format.Raw(data);
                            foreach (KeyValuePair <int, Format.RawElement> itr in container)
                            {
                                short[] a = itr.Value.getAccelerometer();
                                Console.WriteLine("a(" + itr.Key + ") = (" + a[0] + ", " + a[1] + ", " + a[2] + ") g");
                            }
                        }

                        if (PortConfigurable == port)
                        {
                            IDictionary <int, Format.ConfigurableElement> container = Format.Configurable(data);
                            foreach (KeyValuePair <int, Format.ConfigurableElement> itr in container)
                            {
                                Console.Write("data(" + itr.Key + ") = (");
                                for (int i = 0; i < itr.Value.size(); i++)
                                {
                                    if (i > 0)
                                    {
                                        Console.Write(", ");
                                    }
                                    Console.Write(itr.Value.value(i));
                                }
                                Console.WriteLine(")");
                            }
                        }
                    }
                }

                client.close();
                client = null;
            } catch (Exception e) {
                Console.WriteLine(e.ToString());
            }
        }