private async void OnNegativeResultClicked(object sender, EventArgs e)
        {
            bool RunningReal = false;
            bool RunningNC   = true;
            bool RunningPC   = false;
            bool RunningDPV  = false;

            ScanDatabase scan = new ScanDatabase
            {
                AmountBacteria        = 0,
                ConcentrationBacteria = 0,
                Date       = DateTime.Now,
                VoltamType = "Real Test"
            };
            await App.Database.SaveScanAsync(scan);

            int fileNum = Convert.ToInt32(fileNumber.Text);

            try
            {
                DependencyService.Get <IBtControl>().SimpleConnect(fileNum, RunningPC, RunningNC, RunningReal, RunningDPV);
            }
            catch (Exception ex)
            {
                await DisplayAlert("Error", "Failed with error message: " + ex, "OK");

                Crashes.TrackError(ex);
            }

            await Navigation.PushAsync(new AllData
            {
            });
        }
        private async void OnClearRecentClicked(object sender, EventArgs e)
        {
            List <ScanDatabase> allDb = await App.Database.GetScanDatabasesAsync();

            ScanDatabase _database = await App.Database.GetScanAsync(allDb.Count);

            await App.Database.DeleteScanAsync(_database);
        }
Exemplo n.º 3
0
 public Task <int> SaveScanAsync(ScanDatabase scan)   //Saves the current scan into the database
 {
     if (scan.ID != 0)
     {
         return(_database.UpdateAsync(scan));
     }
     else
     {
         return(_database.InsertAsync(scan));
     }
 }
Exemplo n.º 4
0
        public LinearSweep LinSweep(ScanDatabase _database)   //Set the parameters for a linear sweep scan
        {
            LinearSweep linearSweep = new LinearSweep
            {
                BeginPotential = (float)_database.StartingPotential,
                EndPotential   = (float)_database.EndingPotential,
                Scanrate       = (float)_database.ScanRate,
                StepPotential  = (float)_database.PotentialStep   //Add in additional required values once determined
            };

            return(linearSweep);
        }
Exemplo n.º 5
0
        private async Task <ScanDatabase> ACV(ScanDatabase Scan)
        {
            if (Entry1.Text.Length >= 1 &&
                Entry2.Text.Length >= 1 &&
                Entry3.Text.Length >= 1 &&
                Entry4.Text.Length >= 1 &&
                Entry5.Text.Length >= 1 &&
                Entry6.Text.Length >= 1)               //If there is an entry in all of the requried fields
            {
                if (OnlyDotDash(Entry1.Text,
                                Entry2.Text,
                                Entry3.Text,
                                Entry4.Text,
                                Entry5.Text,
                                Entry6.Text))   //If all of them have numbers
                {
                    if (InPRange(Convert.ToDouble(Entry1.Text)) &&
                        InPRange(Convert.ToDouble(Entry2.Text)) &&
                        InStepRange(Convert.ToDouble(Entry3.Text)) &&
                        InPRange(Convert.ToDouble(Entry4.Text)) &&
                        InScanRateRange(Convert.ToDouble(Entry5.Text)) &&
                        InFrequencyRange(Convert.ToDouble(Entry6.Text)))        //If they are all in range
                    {
                        Scan.StartingPotential = Convert.ToDouble(Entry1.Text); //Set parameters in the database based on entered values
                        Scan.EndingPotential   = Convert.ToDouble(Entry2.Text);
                        Scan.PotentialStep     = Convert.ToDouble(Entry3.Text);
                        Scan.ACPotential       = Convert.ToDouble(Entry4.Text);
                        Scan.ScanRate          = Convert.ToDouble(Entry5.Text);
                        Scan.Frequency         = Convert.ToDouble(Entry6.Text);
                    }
                    else
                    {
                        await DisplayAlert("Warning", "You must fill in all fields with a number within range", "OK");

                        return(null);
                    }
                }
                else
                {
                    await DisplayAlert("Warning", "You must enter a number", "OK");

                    return(null);
                }
            }
            else
            {
                await DisplayAlert("Warning", "You must fill in all fields with a number within range", "OK");

                return(null);
            }
            return(Scan);
        }
Exemplo n.º 6
0
        //Below runs the necessary scan on the APM
        public async Task <Method> RunScan()
        {
            List <ScanDatabase> allDb = await App.Database.GetScanDatabasesAsync();

            ScanDatabase _database = await App.Database.GetScanAsync(allDb.Count);

            ScanParams instance = new ScanParams();

            switch (_database.VoltamType)
            {
            case "Linear Voltammetry":
                LinearSweep linSweep = instance.LinSweep(_database);

                linSweep.Ranging.StartCurrentRange   = new CurrentRange(5);
                linSweep.Ranging.MaximumCurrentRange = new CurrentRange(6);
                linSweep.Ranging.MaximumCurrentRange = new CurrentRange(3);

                return(linSweep);

            case "Cyclic Voltammetry":
                CyclicVoltammetry cVoltammetry = instance.CV(_database);

                cVoltammetry.Ranging.StartCurrentRange   = new CurrentRange(5);
                cVoltammetry.Ranging.MaximumCurrentRange = new CurrentRange(6);
                cVoltammetry.Ranging.MaximumCurrentRange = new CurrentRange(3);

                return(cVoltammetry);

            case "Square Wave Voltammetry":
                SquareWave squareWave = instance.SWV(_database);

                squareWave.Ranging.StartCurrentRange   = new CurrentRange(5);
                squareWave.Ranging.MaximumCurrentRange = new CurrentRange(6);
                squareWave.Ranging.MaximumCurrentRange = new CurrentRange(3);

                return(squareWave);

            case "Alternating Current Voltammetry":
                ACVoltammetry acVoltammetry = instance.ACV(_database);

                acVoltammetry.Ranging.StartCurrentRange   = new CurrentRange(5);
                acVoltammetry.Ranging.MaximumCurrentRange = new CurrentRange(6);
                acVoltammetry.Ranging.MaximumCurrentRange = new CurrentRange(3);

                return(acVoltammetry);

            default:
                //Add code to notify user that something has gone wrong and needs to be fixed

                return(null);
            }
        }
Exemplo n.º 7
0
        public CyclicVoltammetry CV(ScanDatabase _database)   //Set the parameters for a cyclic scan
        {
            CyclicVoltammetry cyclicVoltammetry = new CyclicVoltammetry
            {
                BeginPotential = (float)_database.StartingPotential,
                Vtx1Potential  = (float)_database.NegativeVertex,
                Vtx2Potential  = (float)_database.PositiveVertex,
                StepPotential  = (float)_database.PotentialStep,
                Scanrate       = (float)_database.ScanRate
            };

            return(cyclicVoltammetry);
        }
Exemplo n.º 8
0
        public SquareWave SWV(ScanDatabase _database)   //Set the parameters for a square wave scan
        {
            SquareWave squareWave = new SquareWave
            {
                BeginPotential = (float)_database.StartingPotential,
                EndPotential   = (float)_database.EndingPotential,
                StepPotential  = (float)_database.PotentialStep,
                PulseAmplitude = (float)_database.Amplitude,
                Frequency      = (float)_database.Frequency
            };

            return(squareWave);
        }
Exemplo n.º 9
0
        public ACVoltammetry ACV(ScanDatabase _database)   //Set the parameters for an alternating current scan
        {
            ACVoltammetry acVoltammetry = new ACVoltammetry
            {
                BeginPotential    = (float)_database.StartingPotential,
                EndPotential      = (float)_database.EndingPotential,
                StepPotential     = (float)_database.PotentialStep,
                SineWaveAmplitude = (float)_database.ACPotential,
                Scanrate          = (float)_database.ScanRate,
                Frequency         = (float)_database.Frequency
            };

            return(acVoltammetry);
        }
Exemplo n.º 10
0
        private async Task <ScanDatabase> CyclicVotammetry(ScanDatabase Scan)
        {
            if (Entry1.Text.Length >= 1 &&
                Entry2.Text.Length >= 1 &&
                Entry3.Text.Length >= 1 &&
                Entry4.Text.Length >= 1 &&
                Entry5.Text.Length >= 1)               //If there is an entry in all of the required fields
            {
                if (OnlyDotDash(Entry1.Text,
                                Entry2.Text,
                                Entry3.Text,
                                Entry4.Text,
                                Entry5.Text))   //If all of them have numbers
                {
                    if (InPRange(Convert.ToDouble(Entry1.Text)) &&
                        InPRange(Convert.ToDouble(Entry2.Text)) &&
                        InPRange(Convert.ToDouble(Entry3.Text)) &&
                        InStepRange(Convert.ToDouble(Entry4.Text)) &&
                        InScanRateRange(Convert.ToDouble(Entry5.Text)))         //If all of them are in the correct range
                    {
                        Scan.StartingPotential = Convert.ToDouble(Entry1.Text); //Set parameters in the database based on entered values
                        Scan.NegativeVertex    = Convert.ToDouble(Entry2.Text);
                        Scan.PositiveVertex    = Convert.ToDouble(Entry3.Text);
                        Scan.PotentialStep     = Convert.ToDouble(Entry4.Text);
                        Scan.ScanRate          = Convert.ToDouble(Entry5.Text);
                    }
                    else
                    {
                        await DisplayAlert("Warning", "You must fill in all fields with a number within range", "OK");

                        return(null);
                    }
                }
                else
                {
                    await DisplayAlert("Warning", "You must enter a number", "OK");

                    return(null);
                }
            }
            else
            {
                await DisplayAlert("Warning", "You must fill in all fields with a number within range", "OK");

                return(null);
                //Setup error loop to get proper values
            }
            return(Scan);
        }
Exemplo n.º 11
0
        public DifferentialPulse DPV(ScanDatabase _database)
        {
            DifferentialPulse differentialPulse = new DifferentialPulse
            {
                EquilibrationTime = (float)_database.EquilTime,
                BeginPotential    = (float)_database.StartingPotential,
                EndPotential      = (float)_database.EndingPotential,
                StepPotential     = (float)_database.PotentialStep,
                PulsePotential    = (float)_database.PotentialPulse,
                PulseTime         = (float)_database.TimePulse,
                Scanrate          = (float)_database.ScanRate
            };

            differentialPulse.Technique = 1;
            return(differentialPulse);
        }
Exemplo n.º 12
0
        private async void IsInfected()   //Displays whether or not the sample is infected
        {
            List <ScanDatabase> allDb = await App.Database.GetScanDatabasesAsync();

            ScanDatabase _database = await App.Database.GetScanAsync(allDb.Count);

            if (_database.IsInfected)
            {
                isInfect = "The sample is infected";
            }
            else
            {
                isInfect = "The sample is not infected";
            }
            boolPath.Text = isInfect;
        }
Exemplo n.º 13
0
        private async void GetContext()   //Get the database which was just scanned and display whether or not the sample is infected
        {
            List <ScanDatabase> allDb = await App.Database.GetScanDatabasesAsync();

            ScanDatabase _database = await App.Database.GetScanAsync(allDb.Count);

            String isInfected;

            if (_database.IsInfected)
            {
                isInfected = "The sample is infected.";
            }
            else
            {
                isInfected = "The sample is not infected";
            }
            BindingContext = isInfected;
        }
Exemplo n.º 14
0
        private async void GetDatabase()
        {
            if (i > 0)
            {
                Scan = await App.Database.GetScanAsync(i);

                if (i <= allDb.Count)
                {
                    RefreshGui();
                }
                else
                {
                    i--;
                }
            }
            else
            {
                i++;
            }
        }
Exemplo n.º 15
0
        private async void GetDatabase()   //Get a specific database depending on where you are in the list of databases
        {
            if (i > 0)
            {
                Scan = await App.Database.GetScanAsync(i);

                if (i <= allDB.Count)
                {
                    RefreshGui();
                }
                else    //If you try and go to the next database and it doesn't exist, don't change and reset i to it's previous value
                {
                    i--;
                }
            }
            else   //If you try and go to the previous database and it doesn't exist, don't change and reset i to it's previous value
            {
                i++;
            }
        }
Exemplo n.º 16
0
        private async void OnRunTestClicked(object sender, EventArgs e)
        {
            //Setup the standard scan
            ScanDatabase scan = new ScanDatabase
            {
                VoltamType        = "Square Wave Voltammetry",
                Date              = DateTime.Now,
                StartingPotential = 0.0,
                EndingPotential   = -0.6,
                PotentialStep     = 0.001,
                Amplitude         = 0.025,
                Frequency         = 60
            };
            await App.Database.SaveScanAsync(scan);

            DependencyService.Get <IBtControl>().SimpleConnect(1, false, false, true, false);

            await Navigation.PushAsync(new DuringRun
            {
            });
        }
        private async void OnDPVResultClicked(object sender, EventArgs e)
        {
            bool RunningReal = false;
            bool RunningNC   = false;
            bool RunningPC   = false;
            bool RunningDPV  = true;

            ScanDatabase scan = new ScanDatabase
            {
                AmountBacteria        = 0,
                ConcentrationBacteria = 0,
                Date              = DateTime.Now,
                VoltamType        = "Differential Pulse Voltammetry",
                EquilTime         = 8,
                StartingPotential = -0.5,
                EndingPotential   = 0.5,
                PotentialStep     = 0.005,
                PotentialPulse    = 0.025,
                TimePulse         = 0.07,
                ScanRate          = 0.025
            };
            await App.Database.SaveScanAsync(scan);

            int fileNum = Convert.ToInt32(fileNumber.Text);

            try
            {
                DependencyService.Get <IBtControl>().SimpleConnect(fileNum, RunningPC, RunningNC, RunningReal, RunningDPV);
            }
            catch (Exception ex)
            {
                await DisplayAlert("Error", "Failed with error message: " + ex, "OK");

                Crashes.TrackError(ex);
            }

            await Navigation.PushAsync(new AllData
            {
            });
        }
        //Simple connection to the palmsens, currently the only one used
        public async void SimpleConnect(int fileNum, bool RunningPC, bool RunningNC, bool RunningReal, bool RunningDPV)
        {
            bool   RunningBL = true;
            string testRun   = "5";
            //Below sets which option the code will execute
            SimpleMeasurement baseline;
            AssetManager      assetManager = Application.Context.Assets;

            using (StreamReader sr = new StreamReader(assetManager.Open(testRun + "_2525AfterMch" + fileNum + ".pssession")))   //Loads a blank baseline curve to subtract from the scanned/loaded curve
                baseline = SimpleLoadSaveFunctions.LoadMeasurements(sr)[0];

            baselineCurves = baseline.SimpleCurveCollection;

            //Runs a real scan depending on whatever parameters the person has set
            if (RunningReal)
            {
                Context       context      = Application.Context; //Loads the current android context
                IAttributeSet attributeSet = null;
                psCommSimpleAndroid = new PSCommSimpleAndroid(context, attributeSet);
                //Uses a simple comm with the palmsens
                Device[] devices = await psCommSimpleAndroid.GetConnectedDevices();

                try
                {
                    await psCommSimpleAndroid.Connect(devices[0]);   //Connect to the first palmsens found
                }
                catch (Exception ex)
                {
                    Crashes.TrackError(ex);
                }

                psCommSimpleAndroid.MeasurementStarted            += PsCommSimpleAndroid_MeasurementStarted; //Loads the necessary flags
                psCommSimpleAndroid.MeasurementEnded              += PsCommSimpleAndroid_MeasurementEnded;
                psCommSimpleAndroid.SimpleCurveStartReceivingData += PsCommSimpleAndroid_SimpleCurveStartReceivingData;

                Method runScan = await RunScan();                                     //Sets the scan parameters

                activeSimpleMeasurement = await psCommSimpleAndroid.Measure(runScan); //Runs the scan on the potentiostat

                psCommSimpleAndroid.Wait(11000);

                psCommSimpleAndroid.Dispose();

                List <ScanDatabase> allDb = await App.Database.GetScanDatabasesAsync();   //Loads the current database

                //Add in processing stuff here
                SimpleLoadSaveFunctions.SaveMeasurement(activeSimpleMeasurement, Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "dpv" + allDb.Count + ".pssession"));

                //FileHack instance = new FileHack();

                //activeSimpleMeasurement = instance.HackDPV(activeSimpleMeasurement);

                List <SimpleCurve> simpleCurves = activeSimpleMeasurement.NewSimpleCurve(DataArrayType.Current, DataArrayType.Potential);

                SimpleCurve subtractedCurve = simpleCurves[0].Subtract(baselineCurves[0]);    //Note, replace simpleCurves[1] w/ the standard blank curve

                SimpleCurve movingAverageBaseline = subtractedCurve.MovingAverageBaseline();  //Subtracts the baseline from the subtracted curve

                SimpleCurve baselineCurve = subtractedCurve.Subtract(movingAverageBaseline);

                subtractedCurve.Dispose();   //Disposes of the subtracted curve

                SimpleCurve smoothedCurve = baselineCurve.Smooth(SmoothLevel.VeryHigh);

                smoothedCurve.DetectPeaks(0.1, 0, true, false, false);

                double peakLocation = smoothedCurve.Peaks[smoothedCurve.Peaks.nPeaks - 1].PeakX;
                double peakHeight   = smoothedCurve.Peaks[smoothedCurve.Peaks.nPeaks - 1].PeakValue;

                ScanDatabase _database = await App.Database.GetScanAsync(allDb.Count);

                if (peakLocation <= -0.3 && peakLocation >= -0.4)   //If the peak is between a certain range, the sample is infected, add in a minimum value once one is determined
                {
                    _database.IsInfected = true;
                }
                else
                {
                    _database.IsInfected = false;
                }

                _database.PeakVoltage = peakHeight;
                await App.Database.SaveScanAsync(_database);   //Saves the current database

                subtractedCurve.Dispose();
                baselineCurve.Dispose();   //Disposes of the baseline curve
                smoothedCurve.Dispose();
            }

            //Runs a differential pulse voltammetric scan for testing
            else if (RunningDPV)
            {
                using (StreamReader sr = new StreamReader(assetManager.Open("blank.pssession")))   //Loads a blank curve as a baseline to be subtracted
                    baseline = SimpleLoadSaveFunctions.LoadMeasurements(sr)[0];

                Context       context      = Application.Context;                     //Loads the current android context
                IAttributeSet attributeSet = null;
                psCommSimpleAndroid = new PSCommSimpleAndroid(context, attributeSet); //Initializes the palmsens comm
                Device[] devices = await psCommSimpleAndroid.GetConnectedDevices();

                try
                {
                    await psCommSimpleAndroid.Connect(devices[0]);   //Connects to the first palmsens found
                }
                catch (Exception ex)
                {
                    psCommSimpleAndroid.Dispose();
                    Crashes.TrackError(ex);
                    return;
                }

                psCommSimpleAndroid.MeasurementStarted            += PsCommSimpleAndroid_MeasurementStarted; //Loads the necessary flags
                psCommSimpleAndroid.MeasurementEnded              += PsCommSimpleAndroid_MeasurementEnded;
                psCommSimpleAndroid.SimpleCurveStartReceivingData += PsCommSimpleAndroid_SimpleCurveStartReceivingData;

                Method runScan = await RunScan();                                     //Sets the scan parameters

                activeSimpleMeasurement = await psCommSimpleAndroid.Measure(runScan); //Runs the scan on the potentiostat

                Thread.Sleep(50000);

                psCommSimpleAndroid.Dispose();                                          //Disposes of the comm when it is done being used

                List <ScanDatabase> allDb = await App.Database.GetScanDatabasesAsync(); //Loads the current database

                //Add in processing stuff here
                SimpleLoadSaveFunctions.SaveMeasurement(activeSimpleMeasurement, Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "dpv" + allDb.Count + ".pssession"));

                //FileHack instance = new FileHack();

                //activeSimpleMeasurement = instance.HackDPV(activeSimpleMeasurement);

                List <SimpleCurve> simpleCurves = activeSimpleMeasurement.NewSimpleCurve(DataArrayType.Current, DataArrayType.Potential);

                //SimpleCurve subtractedCurve = simpleCurves[0].Subtract(baselineCurves[0]);    //Note, replace simpleCurves[1] w/ the standard blank curve

                SimpleCurve movingAverageBaseline = simpleCurves[0].MovingAverageBaseline();   //Subtracts the baseline from the subtracted curve

                SimpleCurve baselineCurve = simpleCurves[0].Subtract(movingAverageBaseline);

                //subtractedCurve.Dispose();   //Disposes of the subtracted curve

                SimpleCurve smoothedCurve = baselineCurve.Smooth(SmoothLevel.VeryHigh);

                smoothedCurve.DetectPeaks(0.1, 0, true, false, false);

                PeakList peakList = smoothedCurve.Peaks; //Detects the peaks on the subtracted curve

                baselineCurve.Dispose();                 //Disposes of the baseline curve
                smoothedCurve.Dispose();

                Peak   mainPeak     = peakList[peakList.nPeaks - 1]; //Note, the proper peak is the last peak, not the first peak
                double peakLocation = mainPeak.PeakX;
                double peakHeight   = mainPeak.PeakValue;

                ScanDatabase _database = await App.Database.GetScanAsync(allDb.Count);

                if (peakLocation <= -0.3 && peakLocation >= -0.4)   //If the peak is between a certain range, the sample is infected, add in a minimum value once one is determined
                {
                    _database.IsInfected = true;
                }
                else
                {
                    _database.IsInfected = false;
                }

                _database.PeakVoltage = peakHeight;
                await App.Database.SaveScanAsync(_database); //Saves the current database
            }
            else if (RunningNC || RunningPC || RunningBL)    //If a test scan is being run
            {
                if (RunningBL)                               //If a simple baseline test is run with no subtraction or curve manipulation
                {
                    SimpleMeasurement baselineMeasurement;
                    using (StreamReader sr = new StreamReader(assetManager.Open(testRun + "_baselineOnly" + fileNum + ".pssession")))
                        baselineMeasurement = SimpleLoadSaveFunctions.LoadMeasurements(sr)[0];

                    List <SimpleCurve> avgBaselineCurves = baselineMeasurement.SimpleCurveCollection;

                    SimpleCurve avgBaselineCurve = avgBaselineCurves[0];

                    avgBaselineCurve.DetectPeaks(0.05, 0, true, false);   //Detect peaks only if they are wider than 0.05 V

                    PeakList avgBaselinePeakList = avgBaselineCurve.Peaks;

                    if (avgBaselinePeakList.nPeaks != 0)                                            //If it detects a peak run below code
                    {
                        Peak avgBaselinePeak = avgBaselinePeakList[avgBaselinePeakList.nPeaks - 1]; //Use the last peak detected which should be the wanted peak

                        double avgBaselinePeakLocation = avgBaselinePeak.PeakX;
                        double avgBaselinePeakValue    = avgBaselinePeak.PeakValue;

                        List <ScanDatabase> allDb = await App.Database.GetScanDatabasesAsync();

                        ScanDatabase _database = await App.Database.GetScanAsync(allDb.Count);

                        if (avgBaselinePeakLocation <= -0.3 && avgBaselinePeakLocation >= -0.4)   //If a peak is between a certain range, the sample is infected, add in a minimal value once determined
                        {
                            _database.IsInfected = true;
                        }
                        else
                        {
                            _database.IsInfected = false;
                        }

                        _database.PeakVoltage = avgBaselinePeakValue;
                        await App.Database.SaveScanAsync(_database);
                    }
                    else   //If no peak is detected
                    {
                        List <ScanDatabase> allDb = await App.Database.GetScanDatabasesAsync();

                        ScanDatabase _database = await App.Database.GetScanAsync(allDb.Count);

                        _database.IsInfected  = false;
                        _database.PeakVoltage = 0.0;
                        _database.VoltamType  = "Failed PC";
                        await App.Database.SaveScanAsync(_database);
                    }
                }
                else if (RunningPC)   //If a postitive control test is being run with known values
                {
                    SimpleMeasurement positiveControl;
                    using (StreamReader sr = new StreamReader(assetManager.Open(testRun + "_2525AfterTarget" + fileNum + ".pssession")))
                        positiveControl = SimpleLoadSaveFunctions.LoadMeasurements(sr)[0];

                    List <SimpleCurve> positiveCurves = positiveControl.SimpleCurveCollection;

                    SimpleCurve baselineCurve;

                    SimpleCurve subtractedCurve = positiveCurves[0].Subtract(baselineCurves[0]);

                    baselineCurve = subtractedCurve.MovingAverageBaseline();

                    subtractedCurve.Dispose();

                    baselineCurve.DetectPeaks(0.05, 0, true, false);   //Detect all peaks with width greater than 0.05 V

                    PeakList positivePeakList = baselineCurve.Peaks;

                    baselineCurve.Dispose();

                    if (positivePeakList.nPeaks != 0)   //If a peak is detected, execute the code below
                    {
                        Peak positivePeak = positivePeakList[positivePeakList.nPeaks - 1];

                        double positivePeakLocation = positivePeak.PeakX;
                        double positivePeakValue    = positivePeak.PeakValue;

                        List <ScanDatabase> allDb = await App.Database.GetScanDatabasesAsync();

                        ScanDatabase _database = await App.Database.GetScanAsync(allDb.Count);

                        if (positivePeakLocation <= -0.3 && positivePeakLocation >= -0.4)   //If a peak is between a certain range, the sample is infected, add in minimum value once determined
                        {
                            _database.IsInfected = true;
                        }
                        else
                        {
                            _database.IsInfected = false;
                        }

                        _database.PeakVoltage = positivePeakValue;
                        await App.Database.SaveScanAsync(_database);
                    }
                    else   //If no peak is detected, execute the code below
                    {
                        List <ScanDatabase> allDb = await App.Database.GetScanDatabasesAsync();

                        ScanDatabase _database = await App.Database.GetScanAsync(allDb.Count);

                        _database.IsInfected  = false;
                        _database.PeakVoltage = 0.0;
                        _database.VoltamType  = "Failed PC";
                        await App.Database.SaveScanAsync(_database);
                    }
                }
                else if (RunningNC)   //If a negative control test is being run
                {
                    SimpleMeasurement negativeControl;
                    using (StreamReader sr = new StreamReader(assetManager.Open(testRun + "_2525AfterMch" + fileNum + ".pssession")))
                        negativeControl = SimpleLoadSaveFunctions.LoadMeasurements(sr)[0];

                    List <SimpleCurve> negativeCurves = negativeControl.SimpleCurveCollection;

                    SimpleCurve baselineCurve;

                    SimpleCurve subtractedCurve = negativeCurves[0].Subtract(baselineCurves[0]);

                    baselineCurve = subtractedCurve.MovingAverageBaseline();

                    subtractedCurve.Dispose();

                    baselineCurve.DetectPeaks(0.05, 0, true, false);   //Detect all peaks with a width greater than 0.05 V

                    PeakList negativePeakList = baselineCurve.Peaks;

                    baselineCurve.Dispose();

                    if (negativePeakList.nPeaks != 0)   //If a peak is detected, execute the code below
                    {
                        Peak   negativePeak         = negativePeakList[negativePeakList.nPeaks - 1];
                        double negativePeakLocation = negativePeak.PeakX;
                        double negativePeakValue    = negativePeak.PeakValue;

                        List <ScanDatabase> allDb = await App.Database.GetScanDatabasesAsync();

                        ScanDatabase _database = await App.Database.GetScanAsync(allDb.Count);

                        if (negativePeakLocation <= -0.3 && negativePeakLocation >= -0.4)   //If a peak is in a certain range, the sample is infected, add a minimum value once determined
                        {
                            _database.IsInfected = true;
                        }
                        else
                        {
                            _database.IsInfected = false;
                        }

                        _database.PeakVoltage = negativePeakValue;
                        await App.Database.SaveScanAsync(_database);
                    }
                    else   //If a peak is not detected
                    {
                        List <ScanDatabase> allDb = await App.Database.GetScanDatabasesAsync();

                        ScanDatabase _database = await App.Database.GetScanAsync(allDb.Count);

                        _database.IsInfected  = false;
                        _database.PeakVoltage = 0.0;
                        _database.VoltamType  = "Failed NC";
                        await App.Database.SaveScanAsync(_database);
                    }
                }
            }
        }
        //Sets the scan parameters
        public async Task <Method> RunScan()
        {
            //Grabs the most recent database to get the required parameters
            List <ScanDatabase> allDb = await App.Database.GetScanDatabasesAsync();

            ScanDatabase _database = await App.Database.GetScanAsync(allDb.Count);

            //Gets an instance of ScanParams
            ScanParams instance = new ScanParams();

            switch (_database.VoltamType)           //Switch which invokes the correct type of scan
            {
            case "Alternating Current Voltammetry": //Sets an alternating current voltammetric scan
                using (ACVoltammetry acVoltammetry = instance.ACV(_database))
                {
                    acVoltammetry.SmoothLevel = 0;
                    acVoltammetry.Ranging.StartCurrentRange   = new CurrentRange(CurrentRanges.cr10uA);     //Sets the range that the potentiostat will use to detect the current
                    acVoltammetry.Ranging.MaximumCurrentRange = new CurrentRange(CurrentRanges.cr100uA);
                    acVoltammetry.Ranging.MaximumCurrentRange = new CurrentRange(CurrentRanges.cr100nA);

                    return(acVoltammetry);
                }

            case "Cyclic Voltammetry":       //Sets a cyclic voltammetric scan
                using (CyclicVoltammetry cVoltammetry = instance.CV(_database))
                {
                    cVoltammetry.SmoothLevel = 0;
                    cVoltammetry.Ranging.StartCurrentRange   = new CurrentRange(CurrentRanges.cr10uA);     //Sets the range that the potentiostat will use to detect the current
                    cVoltammetry.Ranging.MaximumCurrentRange = new CurrentRange(CurrentRanges.cr100uA);
                    cVoltammetry.Ranging.MaximumCurrentRange = new CurrentRange(CurrentRanges.cr100nA);

                    return(cVoltammetry);
                }

            case "Differential Pulse Voltammetry":       //Sets a differential pulse voltammetric scan
                using (DifferentialPulse differentialPulse = instance.DPV(_database))
                {
                    differentialPulse.SmoothLevel = 0;
                    differentialPulse.Ranging.StartCurrentRange   = new CurrentRange(CurrentRanges.cr1uA);     //Sets the range that the potentiostat will use to detect the current
                    differentialPulse.Ranging.MaximumCurrentRange = new CurrentRange(CurrentRanges.cr1uA);
                    differentialPulse.Ranging.MaximumCurrentRange = new CurrentRange(CurrentRanges.cr10nA);

                    return(differentialPulse);
                }

            case "Linear Voltammetry":       //Sets a linear voltammetric scan
                using (LinearSweep linSweep = instance.LinSweep(_database))
                {
                    linSweep.SmoothLevel = 0;
                    linSweep.Ranging.StartCurrentRange   = new CurrentRange(CurrentRanges.cr10uA);     //Sets the range that the potentiostat will use to detect the current
                    linSweep.Ranging.MaximumCurrentRange = new CurrentRange(CurrentRanges.cr100uA);
                    linSweep.Ranging.MaximumCurrentRange = new CurrentRange(CurrentRanges.cr100nA);

                    return(linSweep);
                }

            case "Square Wave Voltammetry":       //Sets a square wave voltammetric scan
                using (SquareWave squareWave = instance.SWV(_database))
                {
                    squareWave.SmoothLevel = 0;
                    squareWave.Ranging.StartCurrentRange   = new CurrentRange(CurrentRanges.cr10uA);     //Sets the range that the potentiostat will use to detect the current
                    squareWave.Ranging.MaximumCurrentRange = new CurrentRange(CurrentRanges.cr100uA);
                    squareWave.Ranging.MaximumCurrentRange = new CurrentRange(CurrentRanges.cr100nA);

                    return(squareWave);
                }

            default:
                //Add code to notify user that something has gone wrong and needs to be fixed

                return(null);
            }
        }
Exemplo n.º 20
0
 void InitialDatabase()
 {
     thrScanDB    = new ScanDatabase[2];
     thrScanDB[0] = new ScanDatabase("tas", "tam", "LLTLBA");
     thrScanDB[1] = new ScanDatabase("tas", "tam", "LLTLBB");
 }
Exemplo n.º 21
0
        private async void OnManTestClicked(object sender, EventArgs e)   //When you click the button to run the manual test
        {
            Scanner      scanner = App.Database;
            ScanDatabase Scan    = new ScanDatabase
            {
                VoltamType = VoltammetryScan.SelectedItem.ToString(), //Sets the type of voltammetric scan to be run
                IsInfected = false                                    //Sets isinfected to false temporarily
            };

            try
            {
                switch (Scan.VoltamType)   //Depending on the type of scan being performed, it sets different values from the same fields
                {
                case "Cyclic Voltammetry": //If a cyclic voltammetry scan is wanted
                    Scan = await CyclicVotammetry(Scan);

                    if (Scan == null)
                    {
                        return;
                    }
                    break;

                case "Square Wave Voltammetry":       //If a squre wave voltammetric scan is wanted
                    Scan = await SWV(Scan);

                    if (Scan == null)
                    {
                        return;
                    }
                    break;

                case "Linear Voltammetry":       //If a Linear Voltammetric scan is wanted
                    Scan = await LinearVoltammetry(Scan);

                    if (Scan == null)
                    {
                        return;
                    }
                    break;

                case "Alternating Current Voltammetry":       //If an alternating current voltammetric scan is wanted
                    Scan = await ACV(Scan);

                    if (Scan == null)
                    {
                        return;
                    }
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                Crashes.TrackError(ex, new Dictionary <string, string> {
                    { "Entry 1:", Entry1.Text },
                    { "Entry 2:", Entry2.Text },
                    { "Entry 3:", Entry3.Text },
                    { "Entry 4:", Entry4.Text },
                    { "Entry 5:", Entry5.Text },
                    { "Entry 6:", Entry6.Text },
                });
            }

            Scan.Date = DateTime.Now;   //Set the date/time of the scan
            await scanner.SaveScanAsync(Scan);

            //File.Copy(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "notes.db3"), DependencyService.Get<BtControl>().FilePath());

            DependencyService.Get <IBtControl>().SimpleConnect(1, false, false, true, false);  //Runs the test on the APM, need to setup to run async, or move to RunFinal and run async on that page

            await Navigation.PushAsync(new RunFinal
            {
            });
        }
Exemplo n.º 22
0
        public async void SimpleConnect()
        {
            Context             context             = Application.Context;
            IAttributeSet       attributeSet        = null;
            PSCommSimpleAndroid psCommSimpleAndroid = new PSCommSimpleAndroid(context, attributeSet);

            Device[] devices = await psCommSimpleAndroid.GetConnectedDevices();

            for (int i = 0; i < 10; i++)
            {
                try
                {
                    psCommSimpleAndroid.Connect(devices[i]);
                }
                catch (Exception ex)
                {
                    Crashes.TrackError(ex);
                }
            }

            psCommSimpleAndroid.MeasurementStarted            += PsCommSimpleAndroid_MeasurementStarted;
            psCommSimpleAndroid.MeasurementEnded              += PsCommSimpleAndroid_MeasurementEnded;
            psCommSimpleAndroid.SimpleCurveStartReceivingData += PsCommSimpleAndroid_SimpleCurveStartReceivingData;
            RunScan runScan = await RunScan();

            SimpleMeasurement activeSimpleMeasurement = psCommSimpleAndroid.Measure(runScan);

            /*
             * Method method;
             * using (System.IO.StreamReader file = new System.IO.StreamReader(Assets.Open(asset)))
             *  method = SimpleLoadSaveFunctions.LoadMethod(file);
             */

            SimpleLoadSaveFunctions.SaveMeasurement(activeSimpleMeasurement, null);

            List <SimpleCurve> simpleCurves = activeSimpleMeasurement.SimpleCurveCollection;

            //Load base null curve

            SimpleCurve subtractedCurve = simpleCurves[0].Subtract(simpleCurves[1]);    //Note, replace simpleCurves[1] w/ the standard blank curve

            subtractedCurve.DetectPeaks();
            PeakList peakList   = subtractedCurve.Peaks;
            Peak     mainPeak   = peakList[0];
            double   peakHeight = mainPeak.PeakValue;

            List <ScanDatabase> allDb = await App.Database.GetScanDatabasesAsync();

            ScanDatabase _database = await App.Database.GetScanAsync(allDb.Count);

            if (peakHeight <= -0.001)
            {
                _database.IsInfected = true;
            }
            else
            {
                _database.IsInfected = false;
            }

            //Add equations to calculate the amount of bacteria and concentration based on the peak from either detecting the peak
        }
Exemplo n.º 23
0
 public Task <int> DeleteScanAsync(ScanDatabase scan)   //Deletes the current scan from the database
 {
     return(_database.DeleteAsync(scan));
 }