If your using a pc then you can get barcode scanners like they use in shops, maybe modded a little it could fit under the track, and then have standard barcode labels on the wagons, the pc can control points using a parallel port or a usb/relay interface, all of which is cheap, you can get new ones cheaply nowadays with a short range.
Otherwise you'll have to either build a barcode reader from scratch, or hack one and communicate with it using a microcontroller.
Heres an idea, presumably your using a microcontroller, well how about having 2 lengths of reflective tape under the wagon corresponding to 2 photosensors under the track, one of the 2 strips of reflective tape would then generate a clock pulse (chequer pattern) to compensate for the speed of the train, and then the length of the pulse from the other reflective strip would tell you which wagon it was.
Or more efficiently have one strip as the clock pulse and the other as binary data, you'd just need to make sure the clock pulse reflective area was a little less than the data to prevent read errors.