Heads Up :
The post you are writing will appear in a public forum. Please ensure all content is appropriate for public consumption. Review the employee guidelines for the community here.
Extending samplonius's answer to the SG500X by extrapolating to stacking switches is fairly straighforward. The slot number, instead of being a constant, directly corresponds to the switchunit number. The port number is still derived from the ifIndex...