예제 #1
0
        public async Task <List <float> > ReadSensors(int intTime = 20, int numObs = 1)
        {
            Lock();

            // send command
            byte[] msg = new byte[4];
            msg[0] = 18;
            msg[1] = (byte)intTime;
            msg[2] = (byte)numObs;

            Writer.WriteBytes(msg);
            await Writer.StoreAsync();

            // get result
            await Reader.LoadAsync(sizeof(float) * 18);

            var lst = new List <SpectralData>();

            for (int i = 0; i < 18; ++i)
            {
                var value = Reader.ReadSingle();
                Debug.WriteLine($"Channel {i}: {value}");
                lst.Add(new SpectralData
                {
                    Channel = i,
                    Freq    = SpectralData.GetChannelFreq(i),
                    Value   = value
                });
            }

            Unlock();
            return(lst.OrderBy(a => a.Freq).Select(a => a.Value).ToList());
        }
예제 #2
0
        public async Task <Measurement> GetMeasurement()
        {
            Lock();

            var meas = new Measurement();

            try
            {
                byte[] msg = new byte[4];
                msg[0] = 0x6;
                msg[1] = 5;
                msg[2] = 25;
                msg[3] = 255;

                Writer.WriteBytes(msg);
                await Writer.StoreAsync();
            }
            catch (Exception ee)
            {
                await new Windows.UI.Popups.MessageDialog($"Warning!\n{ee.Message}").ShowAsync();
                throw new Exception(ee.Message);
            }

            try
            {
                await Reader.LoadAsync(sizeof(float) * 36);

                var loc = new List <float>();
                for (int i = 0; i < 36; ++i)
                {
                    float value = Reader.ReadSingle();

                    meas.Data.Add(new SpectralData
                    {
                        Measurement = meas,
                        LedId       = (int)(i / 18),
                        Channel     = i,
                        Freq        = SpectralData.GetChannelFreq(i % 18),
                        Value       = value
                    });
                }
            }
            catch (Exception ee)
            {
                await new Windows.UI.Popups.MessageDialog($"Warning!\n{ee.Message}").ShowAsync();
                throw new Exception(ee.Message);
            }

            Unlock();
            return(meas);
        }