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.UsbDevice
usbDevice
-
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 void
configure()
Configure all of the other jmrix widgets needed to work with this adapter.void
connect()
Open the connection.java.lang.String
getCurrentPortName()
java.io.DataInputStream
getInputStream()
Get the InputStream from the port.java.io.DataOutputStream
getOutputStream()
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.Short
getProductID()
java.lang.String
getSerialNumber()
Get the device serial number.javax.usb.UsbDevice
getUsbDevice()
java.lang.Short
getVendorID()
java.lang.String
openPort(java.lang.String portName, java.lang.String serialNumber)
void
recover()
This is called when a connection is initially lost.boolean
sendControlTransfer(int requestType, int request, int value, int index, byte[] data)
send USB control transfervoid
setPort(java.lang.String s)
void
setProductID(java.lang.Short value)
void
setSerialNumber(java.lang.String serialNumber)
Set the device serial number.void
setVendorID(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:
getInputStream
in interfacePortAdapter
- Specified by:
getInputStream
in classAbstractPortController
- Returns:
- the InputStream from the port
-
getOutputStream
public java.io.DataOutputStream getOutputStream()
Get the outputStream to the port.- Specified by:
getOutputStream
in interfacePortAdapter
- Specified by:
getOutputStream
in 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:
recover
in interfacePortAdapter
- Overrides:
recover
in 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:
getCurrentPortName
in interfacePortAdapter
- Specified by:
getCurrentPortName
in 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
-
-