001package jmri.jmrix.can.adapters.gridconnect.canrs.serialdriver;
002
003import jmri.jmrix.can.TrafficController;
004import jmri.jmrix.can.adapters.gridconnect.GcSerialDriverAdapter;
005import jmri.jmrix.can.adapters.gridconnect.canrs.MergTrafficController;
006import org.slf4j.Logger;
007import org.slf4j.LoggerFactory;
008
009/**
010 * Implements SerialPortAdapter for the MERG CAN-RS or CAN-USB.
011 * <p>
012 * This connects to the MERG adapter via a serial com port (real or virtual).
013 * Normally controlled by the SerialDriverFrame class.
014 *
015 * @author Andrew Crosland Copyright (C) 2008
016 * @author Bob Jacobsen Copyright (C) 2009
017 */
018public class SerialDriverAdapter extends GcSerialDriverAdapter {
019
020    public SerialDriverAdapter() {
021        super();
022        option2Name = "CANID";
023        options.put(option2Name, new Option("CAN ID for CAN-USB", new String[]{"127", "126", "125", "124", "123", "122", "121", "120"}));
024    }
025
026    /**
027     * Set up all of the other objects to operate with a CAN RS adapter
028     * connected to this port.
029     */
030    @Override
031    public void configure() {
032
033        // Register the CAN traffic controller being used for this connection
034        TrafficController tc = new MergTrafficController();
035        try {
036            tc.setCanId(Integer.parseInt(getOptionState(option2Name)));
037        } catch (Exception e) {
038            log.error("Cannot parse CAN ID - check your preference settings", e);
039            log.error("Now using default CAN ID");
040        }
041
042        this.getSystemConnectionMemo().setTrafficController(tc);
043
044        // Now connect to the traffic controller
045        log.debug("Connecting port");
046        tc.connectPort(this);
047
048        this.getSystemConnectionMemo().setProtocol(getOptionState(option1Name));
049
050        // do central protocol-specific configuration
051        //jmri.jmrix.can.ConfigurationManager.configure(getOptionState(option1Name));
052        this.getSystemConnectionMemo().configureManagers();
053    }
054
055    private final static Logger log = LoggerFactory.getLogger(SerialDriverAdapter.class);
056
057}