001package jmri.jmrix.wangrow.serialdriver; 002 003import jmri.jmrix.nce.NcePortController; 004import jmri.jmrix.nce.NceSystemConnectionMemo; 005import jmri.jmrix.nce.NceTrafficController; 006 007/** 008 * Implements SerialPortAdapter for the Wangrow system. 009 * <p> 010 * Note that this still uses a significant number of classes from the 011 * {@link jmri.jmrix.nce} package. 012 * <p> 013 * This connects an Wangrow command station via a serial com port. Normally 014 * controlled by the SerialDriverFrame class. 015 * <p> 016 * The current implementation only handles the 9,600 baud rate, and does not use 017 * any other options at configuration time. 018 * 019 * 020 * @author Bob Jacobsen Copyright (C) 2001, 2002 021 */ 022public class SerialDriverAdapter extends NcePortController { 023 024 public SerialDriverAdapter() { 025 super(new NceSystemConnectionMemo()); 026 setManufacturer(jmri.jmrix.wangrow.WangrowConnectionTypeList.WANGROW); 027 } 028 029 @Override 030 public String openPort(String portName, String appName) { 031 032 // get and open the primary port 033 currentSerialPort = activatePort(portName, log); 034 if (currentSerialPort == null) { 035 log.error("failed to connect Wangrow to {}", portName); 036 return Bundle.getMessage("SerialPortNotFound", portName); 037 } 038 log.info("Connecting Wangrow to {} {}", portName, currentSerialPort); 039 040 // try to set it for communication via SerialDriver, configure comm options 041 setBaudRate(currentSerialPort, 9600); 042 configureLeads(currentSerialPort, true, true); 043 setFlowControl(currentSerialPort, FlowControl.NONE); 044 045 // report status 046 reportPortStatus(log, portName); 047 048 opened = true; 049 050 return null; // indicates OK return 051 } 052 053 /** 054 * set up all of the other objects to operate with an NCE command station 055 * connected to this port 056 */ 057 @Override 058 public void configure() { 059 NceTrafficController tc = new NceTrafficController(); 060 this.getSystemConnectionMemo().setNceTrafficController(tc); 061 tc.setAdapterMemo(this.getSystemConnectionMemo()); 062 063 // set the command option 064 tc.setCommandOptions(NceTrafficController.OPTION_1999); 065 066 tc.connectPort(this); 067 068 this.getSystemConnectionMemo().configureManagers(); 069 } 070 071 // base class methods for the NcePortController interface 072 073 @Override 074 public boolean status() { 075 return opened; 076 } 077 078 /** 079 * {@inheritDoc} 080 * Currently only 9,600 bps 081 */ 082 @Override 083 public String[] validBaudRates() { 084 return new String[]{"9,600 bps"}; 085 } 086 087 /** 088 * {@inheritDoc} 089 */ 090 @Override 091 public int[] validBaudNumbers() { 092 return new int[]{9600}; 093 } 094 095 private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(SerialDriverAdapter.class); 096 097}