Well.. you can try tmpe's timed traffic light. I remember it can be done on the rail tracks as well. Calculate the time that the train travels on that section of rail. In the timed traffic light, set the timer as double the time +3-5 seconds buffer, so you can make sure the train will always have a clear path. Not sure would that work though.