Marx used to supply those with some simple operating accessories, such as the bell-ringing crossing signal. They will give you a short pulse whenever a wheel is present. To use them to make a reliable activator you need two of them in conjunction with two relays. One track thingie to operate the first relay, which holds on its own windings, and a second track thingie to operate the second relay, which knocks down the holding path of the first relay, and holds the accessory operated until the last car clears the block. In this way, using just two relays, you can eliminate the concern of train length. Every train, whether short or long, will operate the signal the same way.
The usual caveats apply: Use DC and use slow-release relays (with capacitors).