001package jmri.jmrix.secsi.serialdriver; 002 003import java.util.Arrays; 004import jmri.jmrix.secsi.SecsiSystemConnectionMemo; 005import jmri.jmrix.secsi.SerialPortController; 006 007/** 008 * Provide access to SECSI via a serial com port. Normally controlled by the 009 * secsi.serialdriver.SerialDriverFrame class. 010 * 011 * @author Bob Jacobsen Copyright (C) 2006, 2007 012 */ 013public class SerialDriverAdapter extends SerialPortController { 014 015 public SerialDriverAdapter() { 016 super(new SecsiSystemConnectionMemo()); 017 this.manufacturerName = jmri.jmrix.secsi.SerialConnectionTypeList.TRACTRONICS; 018 } 019 020 @Override 021 public String openPort(String portName, String appName) { 022 023 // get and open the primary port 024 currentSerialPort = activatePort(portName, log); 025 if (currentSerialPort == null) { 026 log.error("failed to connect SECSI to {}", portName); 027 return Bundle.getMessage("SerialPortNotFound", portName); 028 } 029 log.info("Connecting SECSI to {} {}", portName, currentSerialPort); 030 031 // try to set it for communication via SerialDriver 032 // find the baud rate value, configure comm options 033 int baud = currentBaudNumber(mBaudRate); 034 setBaudRate(currentSerialPort, baud); 035 configureLeads(currentSerialPort, true, true); 036 setFlowControl(currentSerialPort, FlowControl.NONE); 037 038 // report status 039 reportPortStatus(log, portName); 040 041 opened = true; 042 043 return null; // indicates OK return 044 } 045 046 /** 047 * Can the port accept additional characters 048 * 049 * @return true always 050 */ 051 public boolean okToSend() { 052 return true; 053 } 054 055 /** 056 * Set up all of the other objects to operate connected to this port. 057 */ 058 @Override 059 public void configure() { 060 // connect to the traffic controller 061 ((SecsiSystemConnectionMemo) getSystemConnectionMemo()).getTrafficController().connectPort(this); 062 ((SecsiSystemConnectionMemo) getSystemConnectionMemo()).configureManagers(); 063 } 064 065 // base class methods for the SerialPortController interface 066 067 @Override 068 public boolean status() { 069 return opened; 070 } 071 072 /** 073 * {@inheritDoc} 074 */ 075 @Override 076 public String[] validBaudRates() { 077 return Arrays.copyOf(validSpeeds, validSpeeds.length); 078 } 079 080 /** 081 * {@inheritDoc} 082 */ 083 @Override 084 public int[] validBaudNumbers() { 085 return Arrays.copyOf(validSpeedValues, validSpeedValues.length); 086 } 087 088 protected String[] validSpeeds = new String[]{Bundle.getMessage("Baud38400")}; 089 protected int[] validSpeedValues = new int[]{38400}; 090 091 @Override 092 public int defaultBaudIndex() { 093 return 0; 094 } 095 096 /** 097 * Get an array of valid values for "option 2"; used to display valid 098 * options.May not be null, but may have zero entries 099 * @return zero entries. 100 */ 101 public String[] validOption2() { 102 return new String[]{""}; 103 } 104 105 /** 106 * Get a String that says what Option 2 represents. 107 * 108 * @return may be an empty string, but will not be null 109 */ 110 public String option2Name() { 111 return ""; 112 } 113 114 private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(SerialDriverAdapter.class); 115 116}