/// <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); } }