001package jmri.jmrix.direct.serial; 002 003import jmri.jmrix.direct.PortController; 004import jmri.jmrix.direct.TrafficController; 005 006/** 007 * Implements SerialPortAdapter for direct serial drive. 008 * <p> 009 * Normally controlled by the SerialDriverFrame class. 010 * <p> 011 * The current implementation only handles the 19,200 baud rate, and does not 012 * use any other options at configuration time. A prior implementation 013 * tried 17240, then 16457, then finally 19200. 014 * 015 * @author Bob Jacobsen Copyright (C) 2001, 2002, 2004, 2023 016 */ 017public class SerialDriverAdapter extends PortController { 018 019 @Override 020 public String openPort(String portName, String appName) { 021 022 // get and open the primary port 023 currentSerialPort = activatePort(portName, log); 024 if (currentSerialPort == null) { 025 log.error("failed to connect Direct Serial to {}", portName); 026 return Bundle.getMessage("SerialPortNotFound", portName); 027 } 028 log.info("Connecting Direct Serial to {} {}", portName, currentSerialPort); 029 030 // try to set it for communication via SerialDriver 031 setBaudRate(currentSerialPort, 19200); 032 configureLeads(currentSerialPort, true, true); 033 setFlowControl(currentSerialPort, FlowControl.NONE); 034 035 // report status 036 reportPortStatus(log, portName); 037 038 opened = true; 039 040 return null; // indicates OK return 041 } 042 043 /** 044 * Set up all of the other objects to operate with direct drive on this port. 045 */ 046 @Override 047 public void configure() { 048 // connect to the traffic controller 049 TrafficController tc = new TrafficController((jmri.jmrix.direct.DirectSystemConnectionMemo)getSystemConnectionMemo()); 050 ((jmri.jmrix.direct.DirectSystemConnectionMemo)getSystemConnectionMemo()).setTrafficController(tc); 051 // connect to the traffic controller 052 tc.connectPort(this); 053 054 // do the common manager config 055 ((jmri.jmrix.direct.DirectSystemConnectionMemo)getSystemConnectionMemo()).configureManagers(); 056 } 057 058 // base class methods for the PortController interface 059 060 /** 061 * {@inheritDoc} 062 */ 063 @Override 064 public boolean status() { 065 return opened; 066 } 067 068 /** 069 * {@inheritDoc} 070 * Currently only 19,200 bps. 071 */ 072 @Override 073 public String[] validBaudRates() { 074 return new String[]{Bundle.getMessage("Baud19200")}; 075 } 076 077 /** 078 * {@inheritDoc} 079 */ 080 @Override 081 public int[] validBaudNumbers() { 082 return new int[]{19200}; 083 } 084 085 @Override 086 public int defaultBaudIndex() { 087 return 0; 088 } 089 090 private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(SerialDriverAdapter.class); 091 092}