示例#1
0
        public float GetBatteryPercentage(ITtlEncoder encoder)
        {
            if (sessionThreadControl.InvokeRequired)
            {
                return (float)sessionThreadControl.Invoke(new Func<ITtlEncoder, float>(GetBatteryPercentage), encoder);
            }

            if (encoder == null)
                return 0.0f;

            //Get percentage
            float percentage;
            try
            {
                TTLEncoder ttlEncoder = GetEncoder(encoder);
                percentage = session.BatteryLevelPct[ttlEncoder.HND];
            }
            catch (KeyNotFoundException)
            {
                percentage = 0.0f;
            }

            return percentage;
        }
示例#2
0
        TTLEncoder GetEncoder(ITtlEncoder encoderInfo)
        {
            TTLEncoder encoder = session.GetFirstEncoder();
            while (encoder.SerialNumber != encoderInfo.SerialNumber && encoder != null)
            {
                encoder = session.GetNextEncoder();
            }

            if (encoder == null)
                throw new KeyNotFoundException();

            return encoder;
        }
示例#3
0
 public float GetBatteryPercentage(ITtlEncoder encoder)
 {
     return LiveSessionTtl.CreateInstance().GetBatteryPercentage(encoder);
 }
示例#4
0
        /*
        public void StartChannels()
        {
            session.StartChannels();
            channelsStarted = true;
            return;
        }

        public void StopChannels()
        {
            channelsStarted = false;
            session.StopChannels();
            return;
        }
        */
        public TtlSensor CreateSensor(ITtlEncoder encoder, SensorType type, Channel channel, String name, bool queueData)
        {
            if (sessionThreadControl.InvokeRequired)
            {
                Func<ITtlEncoder, SensorType, Channel, String, bool, TtlSensor> func = new Func<ITtlEncoder, SensorType, Channel, String, bool, TtlSensor>(CreateSensor);
                return (TtlSensor)sessionThreadControl.Invoke(func, encoder, type, channel, name, queueData);
            }

            //Find the encoder
            TTLEncoder ttlEncoder = GetEncoder(encoder);

            //Get the first available channel handle on the encoder
            int channelHandle = -1;  //passing in -1 means AddChannel() will just return the first available channel
            ttlEncoder.AddChannel((TTLAPI_CHANNELS)channel, ref channelHandle);

            float sampleRate = session.get_NominalSampleRate(channelHandle);

            TtlSensor sensor = CreateTtlSensor(type, name, channel, sampleRate, queueData);
            channelHandleToSensor.Add(channelHandle, sensor);

            sensor.Started += new SensorEventHandler(sensor_Started);
            sensor.Stopped += new SensorEventHandler(sensor_Stopped);
            return sensor;
        }
示例#5
0
 public ITtlSensor CreateTtlSensor(SensorType type, String name, ITtlEncoder encoder, Channel channel)
 {
     return CreateTtlSensor(type, name, encoder, channel, false);
 }
示例#6
0
 public ITtlSensor CreateTtlSensor(SensorType type, String name, ITtlEncoder encoder, Channel channel, bool queueData)
 {
     return LiveSessionTtl.CreateInstance().CreateSensor(encoder, type, channel, name, queueData);
 }
示例#7
0
 public ITempSensor CreateTempSensor(String name, ITtlEncoder encoder, Channel channel, bool queueData)
 {
     TtlSensor sensor = LiveSessionTtl.CreateInstance().CreateSensor(encoder, SensorType.Temperature, channel, name, queueData);
     return (TempSensor)sensor;
 }
示例#8
0
 public ITempSensor CreateTempSensor(String name, ITtlEncoder encoder, Channel channel)
 {
     return CreateTempSensor(name, encoder, channel, false);
 }
示例#9
0
 public IHeartSensor CreateHeartSensor(String name, ITtlEncoder encoder, Channel channel, bool queueData)
 {
     TtlSensor sensor = LiveSessionTtl.CreateInstance().CreateSensor(encoder, SensorType.Heart, channel, name, queueData);
     return (HeartSensor)sensor;
 }
示例#10
0
        int GetChannelHandle(ITtlEncoder encoder, Channel channel)
        {
            if (sessionThreadControl.InvokeRequired)
            {
                Func<ITtlEncoder, Channel, int> func = new Func<ITtlEncoder, Channel, int>(GetChannelHandle);
                return (int)sessionThreadControl.Invoke(func, encoder, channel);
            }

            // Check if we already have this channel
            int channelHandle;
            if (channelToChannelHandle.TryGetValue(channel, out channelHandle))
                return channelHandle;

            //Find the encoder
            TTLEncoder ttlEncoder = GetEncoder(encoder.Info);

            //Get the first available channel handle on the encoder
            channelHandle = -1;  //passing in -1 means AddChannel() will just return the first available channel
            ttlEncoder.AddChannel((TTLAPI_CHANNELS)channel, ref channelHandle);

            // Add channel
            channelToChannelHandle.Add(channel, channelHandle);
            channelHandleToSensor.Add(channelHandle, new List<TtlSensor>());

            return channelHandle;
        }
示例#11
0
        /*
        public void StartChannels()
        {
            session.StartChannels();
            channelsStarted = true;
            return;
        }

        public void StopChannels()
        {
            channelsStarted = false;
            session.StopChannels();
            return;
        }
        */
        // Note: We have to make sure the sensor is created on the calling thread so that events are fired on the calling thread.
        public TtlSensor CreateSensor(ITtlEncoder encoder, SensorType type, Channel channel, String name, bool queueData)
        {
            int channelHandle = GetChannelHandle(encoder, channel);

            float samplesPerSecond = GetSampleRate(channelHandle);

            TtlSensor sensor = CreateTtlSensor(type, name, channel, samplesPerSecond, queueData);
            AddSensor(channelHandle, sensor);

            sensorsCreated++;

            sensor.Started += new SensorEventHandler(sensor_Started);
            sensor.Stopped += new SensorEventHandler(sensor_Stopped);
            return sensor;
        }