Esempio n. 1
0
        static void Main(string[] args)
        {
            ZenClientHandle_t zenHandle = new ZenClientHandle_t();

            OpenZen.ZenInit(zenHandle);

            ExThread obj = new ExThread(zenHandle);

            // Creating thread
            // Using thread class
            Thread thr = new Thread(new ThreadStart(obj.sensorEventThread));

            thr.Start();

            // start sensor listing, new sensors will be reported as Events in our event thread
            OpenZen.ZenListSensorsAsync(zenHandle);

            while (!obj.mSearchDone)
            {
                Console.WriteLine("Searching for sensors ...");
                Thread.Sleep(1000);
            }

            if (obj.mFoundSensors.Count == 0)
            {
                Console.WriteLine("No sensor found on the system");
                OpenZen.ZenShutdown(zenHandle);
                thr.Abort();
                return;
            }

            ZenSensorInitError sensorInitError = ZenSensorInitError.ZenSensorInitError_Max;

            // try three connection attempts
            for (int i = 0; i < 3; i++)
            {
                ZenSensorHandle_t sensorHandle = new ZenSensorHandle_t();
                sensorInitError = OpenZen.ZenObtainSensor(zenHandle, obj.mFoundSensors[0], sensorHandle);
                Console.WriteLine("Connecting to sensor " + obj.mFoundSensors[0].identifier + " on IO interface " + obj.mFoundSensors[0].ioType);
                if (sensorInitError == ZenSensorInitError.ZenSensorInitError_None)
                {
                    Console.WriteLine("Succesfully connected to sensor");
                    break;
                }
            }

            if (sensorInitError != ZenSensorInitError.ZenSensorInitError_None)
            {
                Console.WriteLine("Could not connect to sensor");
                System.Environment.Exit(1);
            }

            // stream some data
            Thread.Sleep(5000);

            OpenZen.ZenShutdown(zenHandle);
            thr.Abort();
        }
Esempio n. 2
0
    void OnDestroy()
    {
        if (mSensorHandle != null)
        {
            OpenZen.ZenReleaseSensor(mZenHandle, mSensorHandle);
        }
        OpenZen.ZenShutdown(mZenHandle);

        // connection.Stop();
    }