Skip to content

Commit

Permalink
Merge pull request #7210 from silverailscolo/eb-connection-baud
Browse files Browse the repository at this point in the history
Empty port speed value in xml
  • Loading branch information
bobjacobsen committed Jul 20, 2019
2 parents f663232 + 4838e14 commit c6f097c
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 27 deletions.
25 changes: 16 additions & 9 deletions java/src/jmri/jmrix/AbstractSerialPortController.java
Expand Up @@ -236,25 +236,32 @@ public String getCurrentBaudRate() {
return mBaudRate;
}

/**
* {@inheritDoc}
*/
@Override
public String getCurrentBaudNumber() {
int[] numbers = validBaudNumbers();
String[] rates = validBaudRates();
if (numbers == null || rates == null || numbers.length != rates.length) { // entries in arrays should correspond
return "";
}
// start with some value, not the default per se
// changed once the user explicitly opens the prefs connection config option details
String baudNumString = "";
if (numbers.length > 0) {
baudNumString = Integer.toString(numbers[0]);
}
// find the configured baud rate value
if (mBaudRate != null) {
int[] numbers = validBaudNumbers();
String[] rates = validBaudRates();
if (numbers == null || rates == null || numbers.length != rates.length) { // entries in arrays should correspond
return "";
}
String baudNumString = "";
// find the configured baud rate value
for (int i = 0; i < numbers.length; i++) {
if (rates[i].equals(mBaudRate)) {
baudNumString = Integer.toString(numbers[i]);
break;
}
}
return baudNumString;
}
return ""; // (none)
return baudNumString;
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion java/src/jmri/jmrix/JmrixBundle.properties
Expand Up @@ -167,7 +167,7 @@ Baud9600 = 9,600 bps
Baud9600Zimo = 9,600 bps (default)
Baud19200 = 19,200 bps
LIBaud19200 = 19,200 bps (default)
Baud28800 = 28,000 bps
Baud28800 = 28,800 bps
Baud38400 = 38,400 bps
Baud57600 = 57,600 bps
Baud115200 = 115,200 bps
Expand Down
5 changes: 5 additions & 0 deletions java/src/jmri/jmrix/SerialPortAdapter.java
Expand Up @@ -80,6 +80,11 @@ public interface SerialPortAdapter extends PortAdapter {

public String getCurrentBaudRate();

/**
* To store as XML attribute, get a string to represent current port speed.
*
* @return speed as number string
*/
public String getCurrentBaudNumber();

public int getCurrentBaudIndex();
Expand Down
Expand Up @@ -45,7 +45,7 @@ public String openPort(String portName, String appName) {
return handlePortBusy(p, portName, log);
}

// try to set it for comunication via SerialDriver
// try to set it for communication via SerialDriver
try {
// find the baud rate value, configure comm options
int baud = baudValues[0]; // default, but also defaulted in the initial value of selectedSpeed
Expand Down
Expand Up @@ -202,7 +202,7 @@ public void configureBaudRate(String rate) {
Bundle.getMessage("Baud19200"), Bundle.getMessage("Baud28800"),
Bundle.getMessage("Baud57600"), Bundle.getMessage("Baud115200")};
protected int[] validSpeedValues = new int[]{9600, 19200, 28800, 57600, 115200};
protected String selectedSpeed = validSpeeds[0];
protected String selectedSpeed = validSpeeds[1];

// private control members
private boolean opened = false;
Expand Down
1 change: 1 addition & 0 deletions java/src/jmri/jmrix/loconet/LnPortController.java
Expand Up @@ -39,6 +39,7 @@ protected LnPortController(LocoNetSystemConnectionMemo connectionMemo) {
* intervals, but it might also stick off if something goes wrong.
* <p>
* Provide a default implementation for the MS100, etc.
*
* @return _always_ true, as we rely on the queueing in the port itself
*/
public boolean okToSend() {
Expand Down
4 changes: 4 additions & 0 deletions java/src/jmri/jmrix/nce/NceBundle.properties
Expand Up @@ -21,3 +21,7 @@ AddOutputEntryToolTip = 16 (Output/Turnout 16)<br>\
enter a number from 1 to 2044 (inclusive).
AddInputEntryToolTip = 4:3 (AIU Cab 4, pin 3)<br>\
50 (AIU Cab 4, pin 3)

# Nce usbdriver items
SystemLabel = System:
UsbVersionLabel = USB Version:
4 changes: 4 additions & 0 deletions java/src/jmri/jmrix/nce/NceBundle_nl.properties
Expand Up @@ -13,3 +13,7 @@ AddOutputEntryToolTip = 16 (Uitgang/Wissel 16)<br>\
voer in als geheel getal van 1 tot en met 2044.
AddInputEntryToolTip = 4:3 (AIU Cab 4, pin 3)<br>\
50 (AIU Cab 4, pin 3)

# Nce usbdriver items
SystemLabel = Systeem:
UsbVersionLabel = USB versie:
Expand Up @@ -34,6 +34,7 @@ public SerialDriverAdapter() {
option1Name = "Eprom"; // NOI18N
// the default is 2006 or later
options.put(option1Name, new Option("Command Station EPROM", new String[]{"2006 or later", "2004 or earlier"}));
// TODO I18N
setManufacturer(jmri.jmrix.nce.NceConnectionTypeList.NCE);
}

Expand Down Expand Up @@ -94,7 +95,6 @@ public String openPort(String portName, String appName) {
}

return null; // indicates OK return

}

/**
Expand Down
2 changes: 1 addition & 1 deletion java/src/jmri/jmrix/nce/usbdriver/ConnectionConfig.java
Expand Up @@ -51,7 +51,7 @@ protected void setInstance() {
@Override
protected String[] getPortFriendlyNames() {
if (SystemType.isWindows()) {
return new String[]{"Silicon Labs CP210x USB to UART Bridge", "Silicon Labs CP210x"};
return new String[]{"Silicon Labs CP210x USB to UART Bridge", "Silicon Labs CP210x"}; // NOI18N
}
return new String[]{};
}
Expand Down
25 changes: 12 additions & 13 deletions java/src/jmri/jmrix/nce/usbdriver/UsbDriverAdapter.java
Expand Up @@ -23,7 +23,6 @@
* This connects an NCE PowerCab or PowerPro via a USB port. Normally
* controlled by the UsbDriverFrame class.
*
*
* @author Bob Jacobsen Copyright (C) 2001, 2002
* @author Daniel Boudreau Copyright (C) 2007
* @author ken cameron Copyright (C) 2013
Expand All @@ -36,9 +35,9 @@ public class UsbDriverAdapter extends NcePortController {
public UsbDriverAdapter() {
super(new NceSystemConnectionMemo());
option1Name = "System"; // NOI18N
options.put(option1Name, new Option("System:", option1Values, false));
option2Name = "USB Version";
options.put(option2Name, new Option("USB Version", option2Values, false));
options.put(option1Name, new Option(Bundle.getMessage("SystemLabel"), option1Values, false));
option2Name = "USB Version"; // NOI18N
options.put(option2Name, new Option(Bundle.getMessage("UsbVersionLabel"), option2Values, false));
// Set default USB version to V7.x.x
setOptionState(option2Name, getOptionChoices(option2Name)[1]);
}
Expand All @@ -57,16 +56,16 @@ public String openPort(String portName, String appName) {

// try to set it for communication via SerialDriver
try {
// find the baud rate value, configure comm options
int baud = validSpeedValues[0]; // default, but also defaulted in the initial value of selectedSpeed
// find the baud rate value, configure comm options
for (int i = 0; i < validSpeeds.length; i++) {
if (validSpeeds[i].equals(mBaudRate)) {
baud = validSpeedValues[i];
}
}
activeSerialPort.setSerialPortParams(baud, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException e) {
log.error("Cannot set serial parameters on port " + portName + ": " + e.getMessage());
log.error("Cannot set serial parameters on port {}: {}", portName, e.getMessage());
return "Cannot set serial parameters on port " + portName + ": " + e.getMessage();
}

Expand All @@ -76,7 +75,7 @@ public String openPort(String portName, String appName) {

// set timeout
// activeSerialPort.enableReceiveTimeout(1000);
log.debug("Serial timeout was observed as: " + activeSerialPort.getReceiveTimeout()
log.debug("Serial timeout was observed as: {}", activeSerialPort.getReceiveTimeout()
+ " " + activeSerialPort.isReceiveTimeoutEnabled());

// get and save stream
Expand All @@ -87,8 +86,7 @@ public String openPort(String portName, String appName) {

// report status
if (log.isInfoEnabled()) {
log.info("NCE USB " + portName + " port opened at "
+ activeSerialPort.getBaudRate() + " baud");
log.info("NCE USB {} port opened at {} baud", portName, activeSerialPort.getBaudRate());
}
opened = true;

Expand All @@ -103,12 +101,12 @@ public String openPort(String portName, String appName) {

}

String[] option1Values = new String[]{"PowerCab", "SB3/SB3a", "Power Pro", "Twin", "SB5"};
String[] option2Values = new String[]{"V6.x.x", "V7.x.x"};
String[] option1Values = new String[]{"PowerCab", "SB3/SB3a", "Power Pro", "Twin", "SB5"}; // NOI18N
String[] option2Values = new String[]{"V6.x.x", "V7.x.x"}; // NOI18N

/**
* set up all of the other objects to operate with an NCE command station
* connected to this port
* Set up all of the other objects to operate with an NCE command station
* connected to this port.
*/
@Override
public void configure() {
Expand Down Expand Up @@ -204,6 +202,7 @@ public void configure() {
}

// base class methods for the NcePortController interface

@Override
public DataInputStream getInputStream() {
if (!opened) {
Expand Down

0 comments on commit c6f097c

Please sign in to comment.