001package jmri.jmrix.powerline.dmx512; 002 003import java.util.Arrays; 004import jmri.jmrix.powerline.SerialPortController; 005import jmri.jmrix.powerline.SerialTrafficController; 006import org.slf4j.Logger; 007import org.slf4j.LoggerFactory; 008 009/** 010 * Provide access to DMX512 devices via a serial com port. 011 * Derived from the Powerline code. 012 * 013 * @author Bob Jacobsen Copyright (C) 2006, 2007, 2008 014 * @author Ken Cameron, (C) 2009, sensors from poll replies Converted to 015 * multiple connection 016 * @author Ken Cameron Copyright (C) 2023 017 */ 018public class SpecificDriverAdapter extends SerialPortController { 019 020 public SpecificDriverAdapter() { 021 super(new SpecificSystemConnectionMemo()); 022 } 023 024 @Override 025 public String openPort(String portName, String appName) { 026 027 // get and open the primary port 028 currentSerialPort = activatePort(portName, log, 2); 029 if (currentSerialPort == null) { 030 log.error("failed to connect DMX512 to {}", portName); 031 return Bundle.getMessage("SerialPortNotFound", portName); 032 } 033 log.info("Connecting DMX512 to {} {}", portName, currentSerialPort); 034 035 // try to set it for communication via SerialDriver 036 // find the baud rate value, configure comm options 037 int baud = currentBaudNumber(mBaudRate); 038 setBaudRate(currentSerialPort, baud); 039 configureLeads(currentSerialPort, true, true); 040 setFlowControl(currentSerialPort, FlowControl.NONE); 041 042 // report status 043 reportPortStatus(log, portName); 044 045 opened = true; 046 047 return null; // indicates OK return 048 } 049 050 /** 051 * set up all of the other objects to operate connected to this port 052 */ 053 @Override 054 public void configure() { 055 SerialTrafficController tc = null; 056 // create a DMX512 port controller 057 //adaptermemo = new jmri.jmrix.powerline.dmx512.SpecificSystemConnectionMemo(); 058 tc = new SpecificTrafficController(this.getSystemConnectionMemo()); 059 060 // connect to the traffic controller 061 this.getSystemConnectionMemo().setTrafficController(tc); 062 tc.setAdapterMemo(this.getSystemConnectionMemo()); 063 this.getSystemConnectionMemo().configureManagers(); 064 tc.connectPort(this); 065 // Configure the form of serial address validation for this connection 066 this.getSystemConnectionMemo().setSerialAddress(new jmri.jmrix.powerline.SerialAddress(this.getSystemConnectionMemo())); 067 this.getSystemConnectionMemo().setActiveSerialPort(currentSerialPort); 068 } 069 070 /** 071 * {@inheritDoc} 072 */ 073 @Override 074 public String[] validBaudRates() { 075 return Arrays.copyOf(validSpeeds, validSpeeds.length); 076 } 077 078 /** 079 * {@inheritDoc} 080 */ 081 @Override 082 public int[] validBaudNumbers() { 083 return Arrays.copyOf(validSpeedValues, validSpeedValues.length); 084 } 085 086 @Override 087 public boolean status() { 088 return opened; 089 } 090 // private control members 091 092 protected String[] validSpeeds = new String[]{Bundle.getMessage("Baud250000")}; 093 protected int[] validSpeedValues = new int[]{250000}; 094 095 @Override 096 public int defaultBaudIndex() { 097 return 0; 098 } 099 100 private final static Logger log = LoggerFactory.getLogger(SpecificDriverAdapter.class); 101 102}