Take a look at Team 358's
Limit Switch example.
The "In Range and Coerce" function will limit the motor output so that it can't drive forward if the "forward limit" switch is active, and it can't drive backward if the "backward limit" switch is active. If you don't have both switches, replace the DIO Get and associated select with a constant
1 or
-1 into the In Range and Coerce input.