001package jmri.jmrix.loconet.locobufferusb;
002
003import jmri.jmrix.loconet.locobuffer.LocoBufferAdapter;
004import org.slf4j.Logger;
005import org.slf4j.LoggerFactory;
006import purejavacomm.SerialPort;
007import purejavacomm.UnsupportedCommOperationException;
008
009/**
010 * Override {@link jmri.jmrix.loconet.locobuffer.LocoBufferAdapter} so that it refers to the
011 * (switch) settings on the LocoBuffer-USB.
012 *
013 * @author Bob Jacobsen Copyright (C) 2004, 2005
014 */
015public class LocoBufferUsbAdapter extends LocoBufferAdapter {
016
017    public LocoBufferUsbAdapter() {
018        super();
019        options.remove(option1Name);
020    }
021
022    /**
023     * Always use flow control, not considered a user-settable option.
024     */
025    @Override
026    protected void setSerialPort(SerialPort activeSerialPort) throws UnsupportedCommOperationException {
027        // find the baud rate value, configure comm options
028        // default, must match fixed adapter setting as speed not stored for LB usb
029        int baud = currentBaudNumber(mBaudRate);
030        activeSerialPort.setSerialPortParams(baud, SerialPort.DATABITS_8,
031                SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
032
033        // configure flow control to always on
034        int flow = SerialPort.FLOWCONTROL_RTSCTS_OUT;
035        configureLeadsAndFlowControl(activeSerialPort, flow);
036
037        log.info("LocoBuffer-USB adapter{}{} RTSCTS_OUT=" + SerialPort.FLOWCONTROL_RTSCTS_OUT + " RTSCTS_IN=" + SerialPort.FLOWCONTROL_RTSCTS_IN, activeSerialPort.getFlowControlMode() == SerialPort.FLOWCONTROL_RTSCTS_OUT ? " set hardware flow control, mode=" : " set no flow control, mode=", activeSerialPort.getFlowControlMode());
038    }
039
040    /**
041     * {@inheritDoc}
042     */
043    @Override
044    public String[] validBaudRates() {
045        return new String[]{Bundle.getMessage("Baud57600")};
046    }
047
048    /**
049     * {@inheritDoc}
050     */
051    @Override
052    public int[] validBaudNumbers() {
053        return new int[]{57600};
054    }
055
056    @Override
057    public int defaultBaudIndex() {
058        return 0;
059    }
060
061    private final static Logger log = LoggerFactory.getLogger(LocoBufferUsbAdapter.class);
062
063}