/// <summary>
 /// Constructor to set values for stimulation data for pulse width, stim rate and stim amp
 /// </summary>
 /// <param name="pulsewidth">Sets the pulseWidth value</param>
 /// <param name="stimrate">Sets the stimRate value</param>
 /// <param name="stimamp">Sets the stimAmp value</param>
 /// <param name="electrodesStim">Sets the electrode that is stimming</param>
 /// <param name="therapyElectrodes">Therapy electrodes</param>
 /// <param name="therapyGroup">Therapy group with all settings</param>
 public StimParameterModel(string pulsewidth, string stimrate, string stimamp, string electrodesStim, TherapyElectrodes therapyElectrodes, TherapyGroup therapyGroup, AmplitudeLimits ampLimits)
 {
     PulseWidth        = pulsewidth;
     StimRate          = stimrate;
     StimAmp           = stimamp;
     StimElectrodes    = electrodesStim;
     TherapyElectrodes = therapyElectrodes;
     TherapyGroup      = therapyGroup;
     AmpLimits         = ampLimits;
 }
 /// <summary>
 /// Constructor to set values for stimulation data for pulse width, stim rate and stim amp
 /// </summary>
 /// <param name="pulsewidth">Sets the pulseWidth value</param>
 /// <param name="stimrate">Sets the stimRate value</param>
 /// <param name="stimamp">Sets the stimAmp value</param>
 /// <param name="electrodesStim">Sets the electrode that is stimming</param>
 /// <param name="therapyElectrodes">Therapy electrodes</param>
 /// <param name="therapyGroup">Therapy group with all settings</param>
 /// <param name="ampLimits">Amp Limits</param>
 /// <param name="rateValue">Rate value as double</param>
 /// <param name="ampValue">Amp value as double</param>
 /// <param name="pwValue">Pulse width value as double</param>
 public StimParameterModel(string pulsewidth, string stimrate, string stimamp, string electrodesStim, TherapyElectrodes therapyElectrodes, TherapyGroup therapyGroup, AmplitudeLimits ampLimits, double rateValue, double ampValue, int pwValue)
 {
     PulseWidth        = pulsewidth;
     StimRate          = stimrate;
     StimAmp           = stimamp;
     StimElectrodes    = electrodesStim;
     TherapyElectrodes = therapyElectrodes;
     TherapyGroup      = therapyGroup;
     AmpLimits         = ampLimits;
     StimAmpValue      = ampValue;
     StimRateValue     = rateValue;
     PulseWidthValue   = pwValue;
 }
        /// <summary>
        /// Gets the stim parameters based on group from the actual API
        /// </summary>
        /// <param name="theSummit">SummitSystem for making the API call to INS</param>
        /// <param name="groupNumber">Group number corresponding to which group we want to get stim parameters from such as Group0, Group1, etc</param>
        /// <returns>StimParameterModel that contains stim amp, stim rate and pulse width</returns>
        private StimParameterModel GetStimParameterModel(SummitSystem theSummit, GroupNumber groupNumber, int program)
        {
            if (theSummit == null || theSummit.IsDisposed)
            {
                return(null);
            }
            TherapyGroup    insStateGroup = null;
            AmplitudeLimits ampLimits     = null;

            try
            {
                int counter = 5;
                do
                {
                    bufferInfo = theSummit.ReadStimGroup(groupNumber, out insStateGroup);
                    counter--;
                } while ((insStateGroup == null || bufferInfo.RejectCode != 0) && counter > 0);
                if (bufferInfo.RejectCode != 0 && counter == 0)
                {
                    _log.Warn("Could not read stim group from Medtronic api call");
                }
            }
            catch (Exception e)
            {
                _log.Error(e);
            }
            try
            {
                int counter = 5;
                do
                {
                    bufferInfo = theSummit.ReadStimAmplitudeLimits(groupNumber, out ampLimits);
                    counter--;
                } while ((insStateGroup == null || bufferInfo.RejectCode != 0) && counter > 0);
                if (bufferInfo.RejectCode != 0 && counter == 0)
                {
                    _log.Warn("Could not read amp limits from Medtronic api call");
                }
            }
            catch (Exception e)
            {
                _log.Error(e);
            }
            int    pulseWidthValue = -1;
            double rateValue       = -1;
            double ampValue        = -1;

            try
            {
                //parse the data to get the pulsewidth
                if (insStateGroup != null)
                {
                    pulseWidth      = insStateGroup.Programs[program].PulseWidthInMicroseconds.ToString();
                    stimRate        = insStateGroup.RateInHz.ToString();
                    stimAmp         = insStateGroup.Programs[program].AmplitudeInMilliamps.ToString();
                    stimElectrode   = FindStimElectrodes(insStateGroup, program);
                    electrodes      = insStateGroup?.Programs[program]?.Electrodes;
                    pulseWidthValue = insStateGroup.Programs[program].PulseWidthInMicroseconds;
                    rateValue       = insStateGroup.RateInHz;
                    ampValue        = insStateGroup.Programs[program].AmplitudeInMilliamps;
                }
            }
            catch (Exception e)
            {
                _log.Error(e);
            }
            //Set the Model with these values and return model
            if (rateValue == -1 || ampValue == -1 || pulseWidthValue == -1)
            {
                StimParameterModel StimParameterModel = new StimParameterModel(pulseWidth, stimRate, stimAmp, stimElectrode, electrodes, insStateGroup, ampLimits);
                return(StimParameterModel);
            }
            else
            {
                StimParameterModel StimParameterModel = new StimParameterModel(pulseWidth, stimRate, stimAmp, stimElectrode, electrodes, insStateGroup, ampLimits, rateValue, ampValue, pulseWidthValue);
                return(StimParameterModel);
            }
        }