Wiring an optocoupler to have both inverting and non-inverting output
If you want full logic swing 0-24V signals then it will be necessary to add one more transistor and a couple of resistors like this: