I've read this answer
(reverse function optocoupler) but my case is different:
I've got a CNC mini lathe.
I have a limit switch on one of the lathe's axis ends (X+) wired as NC to my Gecko G540 controller and it works normally. When the switch is closed, the Gecko's input is grounded, the lathe works normally. When the switch is open, the input is not grounded, the lathe halts, for protection. And, if the switch eventually fails, or a wire disconnects, the controller's input will see it as OPEN also and will halt the lathe also. So it's for extra protection.
If I add another switch wired in series with the first, (as in the A picture) for example to limit the movement of the axis to both extremes of movement, it works also normally. If any switch is open, or if any switch malfunctions, the controller halts the movements of the lathe's axis.
But I can't use a switch in one of the lathe's axis extremes. I'll need to use a slot optocoupler.
But I can't figure it out how to do the same thing with the Optocoupler, which will sense the presence or not of the X leadscrew between it's IR LED and it's phototransistor (X+)
If I wire it the way the B picture shows, it's in a normally open configuration. It works normally as the X+ NC Switch. If the led light reaches the transistor it allows the Gecko's input to be grounded. If not, the system halts. If the switch or the Optocoupler fails, the input won't be grounded, and the system will also halt. (Do I need a resistor between the collector and the gecko's input??)
But I want the optocoupler to behave the opposite. When the led light is blocked I want the gecko's input to be grounded, and when the led light reaches the phototransistor, I want to have a high state on the Input. I can't figure how to wire it in series with the physical NC switch (to still use only one input), even with a transistor for inverting the signal, and still mantaining the safety of if any of the switches (opto of physical) fail, the circuit will be open and the controller will halt.
So I'd like the optocoupler to behave exactly as any of the switches on the A picture, but with it's logic inverted. Can it be done in a simple way?
Thanks a lot!