function getDigitalOutputPinRange (hObj, hDlg, tag, ~)
% Checks whether the provided pin number is within the pin range or not 
% Copyright 2020-2021 The MathWorks, Inc.

cs = hObj.getConfigSet();
ud = hDlg.getUserData(tag);
fieldName = ud.Storage;
newVal = hDlg.getWidgetValue(tag);
newVal = regexprep(newVal,'(?i)gpio',''); %removes GPIO prefix irrespective of case
newVal = strtrim(newVal);
valNum = str2num(newVal); %#ok<ST2NM>

% Get the pin range for digital output

target_data = codertarget.targethardware.getTargetHardware(hObj);

if isequal(target_data.SubFamily, '2837xS') || isequal(target_data.SubFamily, '2837xD')        
        gpioArr = codertarget.tic2000.pinmap.F2837xS.getGPIOPinData();
    else
        callbackHdl = str2func(['codertarget.tic2000.pinmap.F' target_data.SubFamily '.getGPIOPinData']);
        gpioArr = callbackHdl();
end

if ~isempty(valNum) && (length(valNum) == 1) && ismember(valNum, gpioArr)
    codertarget.data.setParameterValue(cs, fieldName, num2str(valNum));
else
    curVal = codertarget.data.getParameterValue(cs, fieldName);
    hDlg.setWidgetValue(tag, curVal);
    DAStudio.error('TIC2000:blocks:ConfigSetInvalidDigitalOutputPin');  
end
end