Hi,

I have been staring myself blind on this problem now. I am looking at two words, iFC and iInput, to determine what status I am going to return. It is all determined by induvidual bits in those two words. I've ended up with a quite messy and nasty piece of code here. And I keep thinking ther MUST be a simpler, more general way to do this... But I can't get my head straight.

iInput
Bit 0 - N/A
Bit 1 - N/A
Bit 2 - N/A
Bit 3 - Common alarm
Bit 4 - Running
Bit 5 - Running hi/fwd lo/reverse
Bit 6 - Intermediate

iFC
Bit 0 - N/A
Bit 1 - N/A
Bit 2 - Duty/standby configuration
Bit 3 - N/A
Bit 4 - N/A
Bit 5 - Speed/direction control enable/disable
Bit 6 - 0: Hi-lo speed config, 1: Fwd-Reverse config. Only applicable when bit 5 is on

Any suggestions on getting the code amount and messyness down?

Code:
PRIVATE INT FUNCTION _ShowMotorStatusM(INT iFC, INT iInput)
    INT bIsAlarm 	= BitRead(iInput,3); //BitRead(InputWord,BitNo)
    INT bIsRunning 	= BitRead(iInput,4);
    INT bIsRunningSDC	= BitRead(iInput,5);
    INT bIsIntermediate	= BitRead(iInput,6);
    INT bIsStandby	= BitRead(iFC,2);
    INT bIsSpdDirCont 	= BitRead(iFC,5);
    INT bIsDirCont	= BitRead(iFC,6);
	
    IF bIsAlarm THEN
        IF bIsRunning THEN
	    IF bIsSpdDirCont THEN
	        IF bIsDirCont THEN
		    IF bIsRunningSDC THEN
		        RETURN GN_MOTOR_ALARM_RUN_REV;
		    ELSE
			RETURN GN_MOTOR_ALARM_RUN;
		    END
		ELSE
		    IF bIsRunningSDC THEN
		        RETURN GN_MOTOR_ALARM_RUN_FAST;
		    ELSE
			RETURN GN_MOTOR_ALARM_RUN_SLOW;
		    END
		END
	    ELSE
		RETURN GN_MOTOR_ALARM_RUN;
	    END
        ELSE
	    RETURN GN_MOTOR_ALARM_STOP;
        END
    END

    IF bIsIntermediate THEN
        IF bIsRunning THEN
	    IF bIsSpdDirCont THEN
	        IF bIsDirCont THEN
		    IF bIsRunningSDC THEN
			RETURN GN_MOTOR_GHOST_RUN_REV;
		    ELSE
			RETURN GN_MOTOR_GHOST_RUN;
		    END
		ELSE
		    IF bIsRunningSDC THEN
		        RETURN GN_MOTOR_GHOST_RUN_FAST;
		    ELSE
		        RETURN GN_MOTOR_GHOST_RUN_SLOW;
		    END
		END
	    ELSE
		RETURN GN_MOTOR_GHOST_RUN;
	    END
	ELSE
	    RETURN GN_MOTOR_GHOST_STOP;
	END
    END
	
    IF bIsStandby THEN
        IF bIsRunning THEN
	    IF bIsSpdDirCont THEN
		IF bIsDirCont THEN
		    IF bIsRunningSDC THEN
		        RETURN GN_MOTOR_STANDBY_RUN_REV;
	            ELSE
			RETURN GN_MOTOR_STANDBY_RUN;
		    END
		ELSE
		    IF bIsRunningSDC THEN
		        RETURN GN_MOTOR_STANDBY_RUN_FAST;
		    ELSE
			RETURN GN_MOTOR_STANDBY_RUN_SLOW;
		    END
		END
	    ELSE
		RETURN GN_MOTOR_STANDBY_RUN;
	    END
	ELSE
	    RETURN GN_MOTOR_STANDBY_STOP;
	END
    END
	
    IF bIsRunning THEN
        IF bIsSpdDirCont THEN
	    IF bIsDirCont THEN
		IF bIsRunningSDC THEN
		    RETURN GN_MOTOR_RUN_REV;
		ELSE
		    RETURN GN_MOTOR_RUN;
		END
	    ELSE
		IF bIsRunningSDC THEN
		    RETURN GN_MOTOR_RUN_FAST;
		ELSE
		    RETURN GN_MOTOR_RUN_SLOW;
		END
	    END
	ELSE
	    RETURN GN_MOTOR_RUN;
	END
    ELSE
        RETURN GN_MOTOR_INACT;
    END
END
Essentialy these four blocks of nested IF-statements are doing the same thing, but In prioritized order, so the function will return on the most "severe" cases.

Note: A Switch statement (SELECT CASE) in this language (Cicode) will exit on matching case.

As if you did this in C:
Code:
switch(var)
{
    case 0:
        // Do stuff
        break;
    case 1:
        // Do other stuff
        break;
}