Package jmri.jmrix
Class UsbPortAdapter
- java.lang.Object
-
- jmri.jmrix.AbstractPortController
-
- jmri.jmrix.UsbPortAdapter
-
- All Implemented Interfaces:
PortAdapter
- Direct Known Subclasses:
AnymaDMX_UsbPortAdapter
public class UsbPortAdapter extends AbstractPortController
Enables basic setup of a USB interface for a jmrix implementation.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class jmri.jmrix.AbstractPortController
AbstractPortController.Option
-
-
Field Summary
Fields Modifier and Type Field Description protected javax.usb.UsbDeviceusbDevice-
Fields inherited from class jmri.jmrix.AbstractPortController
allowConnectionRecovery, manufacturerName, opened, option1Name, option2Name, option3Name, option4Name, options, reconnectinterval, reconnectMaxAttempts, reconnectMaxInterval
-
-
Constructor Summary
Constructors Constructor Description UsbPortAdapter(SystemConnectionMemo memo)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidconfigure()Configure all of the other jmrix widgets needed to work with this adapter.voidconnect()Open the connection.java.lang.StringgetCurrentPortName()java.io.DataInputStreamgetInputStream()Get the InputStream from the port.java.io.DataOutputStreamgetOutputStream()Get the outputStream to the port.java.util.List<java.lang.String>getPortNames()Get the list of USB locations with devices matching a single vendor/product ID combination.java.lang.ShortgetProductID()java.lang.StringgetSerialNumber()Get the device serial number.javax.usb.UsbDevicegetUsbDevice()java.lang.ShortgetVendorID()java.lang.StringopenPort(java.lang.String portName, java.lang.String serialNumber)voidrecover()This is called when a connection is initially lost.booleansendControlTransfer(int requestType, int request, int value, int index, byte[] data)send USB control transfervoidsetPort(java.lang.String s)voidsetProductID(java.lang.Short value)voidsetSerialNumber(java.lang.String serialNumber)Set the device serial number.voidsetVendorID(java.lang.Short value)-
Methods inherited from class jmri.jmrix.AbstractPortController
closeConnection, configureOption1, configureOption2, configureOption3, configureOption4, dispose, getDisabled, getManufacturer, getOption1Name, getOption2Name, getOption3Name, getOption4Name, getOptionChoices, getOptionDisplayName, getOptions, getOptionState, getReconnectMaxAttempts, getReconnectMaxInterval, getSystemConnectionMemo, getSystemPrefix, getUserName, isDirty, isOptionAdvanced, isOptionTypePassword, isOptionTypeText, isRestartRequired, purgeStream, reconnect, reconnectFromLoop, resetupConnection, safeSleep, setClosed, setDisabled, setManufacturer, setOpened, setOptionState, setReconnectMaxAttempts, setReconnectMaxInterval, setSystemConnectionMemo, setSystemPrefix, setUserName, status
-
-
-
-
Field Detail
-
usbDevice
protected javax.usb.UsbDevice usbDevice
-
-
Constructor Detail
-
UsbPortAdapter
public UsbPortAdapter(SystemConnectionMemo memo)
-
-
Method Detail
-
getVendorID
public java.lang.Short getVendorID()
-
setVendorID
public void setVendorID(java.lang.Short value)
-
getProductID
public java.lang.Short getProductID()
-
setProductID
public void setProductID(java.lang.Short value)
-
getSerialNumber
public java.lang.String getSerialNumber()
Get the device serial number.- Returns:
- the serial number or null if there is no serial number
-
setSerialNumber
public void setSerialNumber(java.lang.String serialNumber)
Set the device serial number.- Parameters:
serialNumber- the serial number; if null, empty, or only containing whitespace, sets property to null
-
getUsbDevice
public javax.usb.UsbDevice getUsbDevice()
-
openPort
public java.lang.String openPort(java.lang.String portName, java.lang.String serialNumber)
-
connect
public void connect() throws java.io.IOException
Open the connection.- Throws:
java.io.IOException- if unable to connect
-
getInputStream
public java.io.DataInputStream getInputStream()
Get the InputStream from the port.- Specified by:
getInputStreamin interfacePortAdapter- Specified by:
getInputStreamin classAbstractPortController- Returns:
- the InputStream from the port
-
getOutputStream
public java.io.DataOutputStream getOutputStream()
Get the outputStream to the port.- Specified by:
getOutputStreamin interfacePortAdapter- Specified by:
getOutputStreamin classAbstractPortController- Returns:
- the outputStream to the port
-
recover
public void recover()
This is called when a connection is initially lost. After checking the allowConnectionRecovery flag, closes the connection, resets the open flag and attempts a reconnection.- Specified by:
recoverin interfacePortAdapter- Overrides:
recoverin classAbstractPortController
-
configure
public void configure()
Configure all of the other jmrix widgets needed to work with this adapter.
-
getPortNames
@Nonnull public java.util.List<java.lang.String> getPortNames()
Get the list of USB locations with devices matching a single vendor/product ID combination. These are "portNames" to match the calling API.- Returns:
- the list of locations with matching devices; this is an empty list if there are no matches
-
setPort
public void setPort(java.lang.String s)
-
getCurrentPortName
public java.lang.String getCurrentPortName()
- Specified by:
getCurrentPortNamein interfacePortAdapter- Specified by:
getCurrentPortNamein classAbstractPortController
-
sendControlTransfer
public boolean sendControlTransfer(int requestType, int request, int value, int index, byte[] data)
send USB control transfer- Parameters:
requestType- the request typerequest- the requestvalue- the valueindex- the indexdata- the data- Returns:
- true if successful sent
-
-