Package gurux.serial

Class GXSerial

java.lang.Object
gurux.serial.GXSerial
All Implemented Interfaces:
gurux.common.IGXMedia, gurux.common.IGXMedia2, AutoCloseable

public class GXSerial extends Object implements gurux.common.IGXMedia, gurux.common.IGXMedia2, AutoCloseable
The GXSerial component determines methods that make the communication possible using serial port connection.
  • Constructor Details

    • GXSerial

      public GXSerial()
      Constructor.
    • GXSerial

      public GXSerial(String port, gurux.io.BaudRate baudRateValue, int dataBitsValue, gurux.io.Parity parityValue, gurux.io.StopBits stopBitsValue)
      Constructor.
      Parameters:
      port - Serial port.
      baudRateValue - Baud rate.
      dataBitsValue - Data bits.
      parityValue - Parity.
      stopBitsValue - Stop bits.
  • Method Details

    • getPortNames

      public static String[] getPortNames()
      Gets an array of serial port names for the current computer.
      Returns:
      Collection of available serial ports.
    • getAvailableBaudRates

      public static final gurux.io.BaudRate[] getAvailableBaudRates(String portName)
      Get baud rates supported by given serial port.
      Parameters:
      portName - Name of serial port.
      Returns:
      Collection of available baud rates.
    • finalize

      protected final void finalize() throws Throwable
      Overrides:
      finalize in class Object
      Throws:
      Throwable
    • getTrace

      public final gurux.common.enums.TraceLevel getTrace()
      Specified by:
      getTrace in interface gurux.common.IGXMedia
    • setTrace

      public final void setTrace(gurux.common.enums.TraceLevel value)
      Specified by:
      setTrace in interface gurux.common.IGXMedia
    • getConfigurableSettings

      public final int getConfigurableSettings()
      Specified by:
      getConfigurableSettings in interface gurux.common.IGXMedia
    • setConfigurableSettings

      public final void setConfigurableSettings(int value)
      Specified by:
      setConfigurableSettings in interface gurux.common.IGXMedia
    • properties

      public final boolean properties(JFrame parent)
      Specified by:
      properties in interface gurux.common.IGXMedia
    • aboutBox

      public final void aboutBox()
      Displays the copyright of the control, user license, and version information, in a dialog box.
    • send

      public final void send(Object data, String target) throws Exception
      Specified by:
      send in interface gurux.common.IGXMedia
      Throws:
      Exception
    • open

      public final void open() throws Exception
      Specified by:
      open in interface gurux.common.IGXMedia
      Throws:
      Exception
    • close

      public final void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface gurux.common.IGXMedia
    • getBaudRate

      public final gurux.io.BaudRate getBaudRate()
      Used baud rate for communication. Can be changed without disconnecting.
      Returns:
      Used baud rate.
    • setBaudRate

      public final void setBaudRate(gurux.io.BaudRate value)
      Set new baud rate.
      Parameters:
      value - New baud rate.
    • getBreakState

      public final boolean getBreakState()
      Get break state.
      Returns:
      True if the port is in a break state; otherwise, false.
    • setBreakState

      public final void setBreakState(boolean value)
      Set break state.
      Parameters:
      value - True if the port is in a break state; otherwise, false.
    • getBytesToRead

      public final int getBytesToRead()
      Gets the number of bytes in the receive buffer.
      Returns:
      Amount of read bytes.
    • getBytesToWrite

      public final int getBytesToWrite()
      Gets the number of bytes in the send buffer.
      Returns:
      Amount of bytes to write in the send buffer.
    • getCDHolding

      public final boolean getCDHolding()
      Gets the state of the Carrier Detect line for the port.
      Returns:
      Is Carrier Detect in holding state.
    • getCtsHolding

      public final boolean getCtsHolding()
      Gets the state of the Clear-to-Send line.
      Returns:
      Clear-to-Send state.
    • getDataBits

      public final int getDataBits()
      Gets the standard length of data bits per byte.
      Returns:
      Amount of data bits.
    • setDataBits

      public final void setDataBits(int value)
      Sets the standard length of data bits per byte.
      Parameters:
      value - Amount of data bits.
    • getDsrHolding

      public final boolean getDsrHolding()
      Gets the state of the Data Set Ready (DSR) signal.
      Returns:
      Is Data Set Ready set.
    • getDtrEnable

      public final boolean getDtrEnable()
      Get is Data Terminal Ready (DTR) signal enabled.
      Returns:
      Is DTR enabled.
    • setDtrEnable

      public final void setDtrEnable(boolean value)
      Set is Data Terminal Ready (DTR) signal enabled.
      Parameters:
      value - Is DTR enabled.
    • getHandshake

      public final gurux.io.Handshake getHandshake()
      Gets the handshaking protocol for serial port transmission of data.
      Returns:
      Used handshake protocol.
    • setHandshake

      public final void setHandshake(gurux.io.Handshake value)
      Sets the handshaking protocol for serial port transmission of data.
      Parameters:
      value - Handshake protocol.
    • isOpen

      public final boolean isOpen()
      Specified by:
      isOpen in interface gurux.common.IGXMedia
    • getParity

      public final gurux.io.Parity getParity()
      Gets the parity-checking protocol.
      Returns:
      Used parity.
    • setParity

      public final void setParity(gurux.io.Parity value)
      Sets the parity-checking protocol.
      Parameters:
      value - Used parity.
    • getPortName

      public final String getPortName()
      Gets the port for communications, including but not limited to all available COM ports.
      Returns:
      Used serial port
    • setPortName

      public final void setPortName(String value)
      Sets the port for communications, including but not limited to all available COM ports.
      Parameters:
      value - Used serial port.
    • getReadBufferSize

      public final int getReadBufferSize()
      Gets the size of the serial port input buffer.
      Returns:
      Size of input buffer.
    • setReadBufferSize

      public final void setReadBufferSize(int value)
      Sets the size of the serial port input buffer.
      Parameters:
      value - Size of input buffer.
    • getReadTimeout

      public final int getReadTimeout()
      Gets the number of milliseconds before a time-out occurs when a read operation does not finish.
      Returns:
      Read timeout.
    • setReadTimeout

      public final void setReadTimeout(int value)
      Sets the number of milliseconds before a time-out occurs when a read operation does not finish.
      Parameters:
      value - Read timeout.
    • getRtsEnable

      public final boolean getRtsEnable()
      Gets a value indicating whether the Request to Send (RTS) signal is enabled during serial communication.
      Returns:
      Is RTS enabled.
    • setRtsEnable

      public final void setRtsEnable(boolean value)
      Sets a value indicating whether the Request to Send (RTS) signal is enabled during serial communication.
      Parameters:
      value - Is RTS enabled.
    • getStopBits

      public final gurux.io.StopBits getStopBits()
      Gets the standard number of stop bits per byte.
      Returns:
      Used stop bits.
    • setStopBits

      public final void setStopBits(gurux.io.StopBits value)
      Sets the standard number of stop bits per byte.
      Parameters:
      value - Used stop bits.
    • getWriteTimeout

      public final int getWriteTimeout()
      Gets the number of milliseconds before a time-out occurs when a write operation does not finish.
      Returns:
      Used time out.
    • setWriteTimeout

      public final void setWriteTimeout(int value)
      Sets the number of milliseconds before a time-out occurs when a write operation does not finish.
      Parameters:
      value - Used time out.
    • receive

      public final <T> boolean receive(gurux.common.ReceiveParameters<T> args)
      Specified by:
      receive in interface gurux.common.IGXMedia
    • getBytesSent

      public final long getBytesSent()
      Specified by:
      getBytesSent in interface gurux.common.IGXMedia
    • getBytesReceived

      public final long getBytesReceived()
      Specified by:
      getBytesReceived in interface gurux.common.IGXMedia
    • resetByteCounters

      public final void resetByteCounters()
      Specified by:
      resetByteCounters in interface gurux.common.IGXMedia
    • getSettings

      public final String getSettings()
      Specified by:
      getSettings in interface gurux.common.IGXMedia
    • setSettings

      public final void setSettings(String value)
      Specified by:
      setSettings in interface gurux.common.IGXMedia
    • copy

      public final void copy(Object target)
      Specified by:
      copy in interface gurux.common.IGXMedia
    • getName

      public final String getName()
      Specified by:
      getName in interface gurux.common.IGXMedia
    • getMediaType

      public final String getMediaType()
      Specified by:
      getMediaType in interface gurux.common.IGXMedia
    • getSynchronous

      public final Object getSynchronous()
      Specified by:
      getSynchronous in interface gurux.common.IGXMedia
    • getIsSynchronous

      public final boolean getIsSynchronous()
      Specified by:
      getIsSynchronous in interface gurux.common.IGXMedia
    • resetSynchronousBuffer

      public final void resetSynchronousBuffer()
      Specified by:
      resetSynchronousBuffer in interface gurux.common.IGXMedia
    • validate

      public final void validate()
      Specified by:
      validate in interface gurux.common.IGXMedia
    • getEop

      public final Object getEop()
      Specified by:
      getEop in interface gurux.common.IGXMedia
    • setEop

      public final void setEop(Object value)
      Specified by:
      setEop in interface gurux.common.IGXMedia
    • addListener

      public final void addListener(gurux.common.IGXMediaListener listener)
      Specified by:
      addListener in interface gurux.common.IGXMedia
    • removeListener

      public final void removeListener(gurux.common.IGXMediaListener listener)
      Specified by:
      removeListener in interface gurux.common.IGXMedia
    • getReceiveDelay

      public int getReceiveDelay()
      Specified by:
      getReceiveDelay in interface gurux.common.IGXMedia2
    • setReceiveDelay

      public void setReceiveDelay(int value)
      Specified by:
      setReceiveDelay in interface gurux.common.IGXMedia2
    • getAsyncWaitTime

      public int getAsyncWaitTime()
      Specified by:
      getAsyncWaitTime in interface gurux.common.IGXMedia2
    • setAsyncWaitTime

      public void setAsyncWaitTime(int value)
      Specified by:
      setAsyncWaitTime in interface gurux.common.IGXMedia2
    • getAsyncWaitHandle

      public Object getAsyncWaitHandle()
      Specified by:
      getAsyncWaitHandle in interface gurux.common.IGXMedia2