limit switch problem

After 16 hour of working on two limit switches, they still won’t work. I wrote a code for our limit switches that when our top limitswitch is pressed it would stop the motor from going up so the motor can only go down, and when the bottom one is pressed it stops the motor from going down so the motor can only go up. The problem is that I does not do any of that. Can any one please review this code an tell me where I went wrong?


		    if (ds->GetDigitalIn(3) != 1 || ds->GetDigitalIn(3) != 1 && Carriage_down->Get() == 0)
		    {			    
			    Carriage_motor->Set(1.0);
			    while(Carriage_down->Get() == 0)
			    {
			    	Carriage_motor->Set(0.0);
			    }
		    }
		    else if(ds->GetDigitalIn(4) != 1 || ds->GetDigitalIn(4) != 1 && Carriage_up->Get() == 0)
		    {
		    	Carriage_motor->Set(-1.0);
			    while(Carriage_up->Get() == 0)
			    {
			    	Carriage_motor->Set(0.0);
			    }
		    }
		    else
		    {
		      	Carriage_motor->Set(0.0);
		    }

If the motor is forced to stop whenever a limit switch is pressed, it will stick at the end of its travel and never be able to leave.

One easy way to do it “right” is to use the “top limit” switch to turn off the motor only if it’s being commanded up, and use the “bottom limit” switch to turn off the motor only if it’s being commanded down.


  // use operator console buttons to decide which way to run the motor
  if (ds->GetDigitalIn(3) != 1)
    motorvalue = 1;
  else if (ds->GetDigitalIn(4) != 1)
    motorvalue = -1;
  else
    motorvalue = 0;
  // stop motor from being commanded forward if at lower limit
  if (Carriage_down->Get() == 0 &&  motorvalue > 0)
    motorvalue = 0;
  // stop motor from being commanded backward if at upper limit
  if (Carriage_up->Get() == 0 && motorvalue < 0)
    motorvalue = 0;
  Carriage_motor->Set(motorvalue);

I deleted my post, it was wrong, thank you for correction! =D