001package jmri.jmrix.sprog.sprogCS;
002
003import jmri.jmrix.sprog.SprogConstants.SprogMode;
004
005import org.slf4j.Logger;
006import org.slf4j.LoggerFactory;
007
008/**
009 * Implement SerialPortAdapter for the Sprog system.
010 * <p>
011 * This connects an Sprog command station via a serial com port. Also used for
012 * the USB SPROG, which appears to the computer as a serial port.
013 * <p>
014 * The current implementation only handles the 9,600 baud rate, and does not use
015 * any other options at configuration time.
016 *
017 * @author Andrew Crosland Copyright (C) 2006
018 */
019public class SprogCSSerialDriverAdapter
020        extends jmri.jmrix.sprog.serialdriver.SerialDriverAdapter {
021
022    public SprogCSSerialDriverAdapter() {
023        super(SprogMode.OPS);
024        options.put("NumSlots", // NOI18N
025                new Option(Bundle.getMessage("MakeLabel", Bundle.getMessage("NumSlotOptions")), // NOI18N
026                        new String[]{"16", "8", "32", "48", "64"}, true));
027
028        options.put("TrackPowerState", new Option(Bundle.getMessage("OptionTrackPowerLabel"),
029                new String[]{Bundle.getMessage("PowerStateOff"), Bundle.getMessage("PowerStateOn")},
030                true)); // first element (TrackPowerState) NOI18N
031        // Set the username to match name, once refactored to handle multiple connections or user setable names/prefixes then this can be removed
032        this.getSystemConnectionMemo().setUserName(Bundle.getMessage("SprogCSTitle"));
033    }
034
035    /**
036     * Set up all of the other objects to operate with an Sprog command station
037     * connected to this port.
038     */
039    @Override
040    public void configure() {
041        String slots = getOptionState("NumSlots");
042        try {
043            numSlots = Integer.parseInt(slots);
044        }
045        catch (NumberFormatException e) {
046            log.warn("Could not parse number of slots {}", e.getMessage());
047            numSlots = 16;
048        }
049        
050        super.configure();
051    }
052
053    private final static Logger log = LoggerFactory.getLogger(SprogCSSerialDriverAdapter.class);
054
055}