com.moxa.mxnportapi

## Interface MxNPort

-     public interface MxNPort

  An MxNPort object is an abstraction of a NPort serial port. The MxNPort is created by MxNPortService.getNPortInfoList. Users should not create an MxNPort by themselves due to lack of internal initialization.
  Port control
  `open`
  `close`
  `setIoctlMode`
  `setFlowCtrl`
  `setBaud`
  `setRTS`
  `setDTR`
  `flush`
  Input/Output
  `read`
  `write`
  Port status inquery
  `getBaud`
  `getFlowCtrl`
  `getIoctlMode`
  `getLineStatus`
  `getModemStatus`
  `getOQueue`
  Miscellaneous
  `setBreak`

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Interface and Description
    --- | ---
    `static class` | `MxNPort.FlowCtrl` This class represents serial flow control settings.
    `static class` | `MxNPort.IoctlMode` This class represents serial parameters such as baud rate, data bits, parity, and stop bits.
    `static class` | `MxNPort.LineError` This class represents errors on line.
    `static class` | `MxNPort.ModemStatus` This class represents modem status, such as CTS, DSR, DCD, and RI.

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `CTS_FLOW_ENABLE` Defines CTS hardware flow control
    `static int` | `CTS_OFF` Defines CTS state OFF
    `static int` | `CTS_ON` Defines CTS state ON
    `static int` | `DATA_BITS_5` Defines serial communication with 5 data bits
    `static int` | `DATA_BITS_6` Defines serial communication with 6 data bits
    `static int` | `DATA_BITS_7` Defines serial communication with 7 data bits
    `static int` | `DATA_BITS_8` Defines serial communication with 8 data bits
    `static int` | `DCD_OFF` Defines DCD state OFF
    `static int` | `DCD_ON` Defines DCD state ON
    `static int` | `DSR_FLOW_ENABLE` Defines DSR hardware flow control
    `static int` | `DSR_OFF` Defines DSR state OFF
    `static int` | `DSR_ON` Defines DSR state ON
    `static int` | `DTR_FLOW_ENABLE` Defines DTR hardware flow control
    `static int` | `DTR_OFF` Defines DTS state OFF
    `static int` | `DTR_ON` Defines DTS state ON
    `static int` | `DTRDSR_FLOW_ENABLE` Defines DTR/DSR software flow control
    `static int` | `DTRDSR_FLOW_MASK` Defines the bit mask of DTR/DSR hardware flow control
    `static int` | `FLUSH_INPUT` Defines the flush to read buffer (Reserve for Android socket API)
    `static int` | `FLUSH_OUTPUT` Defines the flush to write buffer
    `static int` | `LINE_ERROR` Defines the error state for each `LineError` field
    `static int` | `LINE_NO_ERROR` Defines the non-error state for each `LineError` field
    `static int` | `PARITY_EVEN` Defines even parity checking
    `static int` | `PARITY_MARK` Defines mark parity checking
    `static int` | `PARITY_NONE` Defines no parity checking
    `static int` | `PARITY_ODD` Defines odd parity checking
    `static int` | `PARITY_SPACE` Defines space parity checking
    `static int` | `RI_OFF` Defines RI state OFF (Reserve)
    `static int` | `RI_ON` Defines RI state ON (Reserve)
    `static int` | `RTS_FLOW_ENABLE` Defines RTS hardware flow control
    `static int` | `RTS_OFF` Defines RTS state OFF
    `static int` | `RTS_ON` Defines RTS state ON
    `static int` | `RTSCTS_FLOW_ENABLE` Defines RTS/CTS hardware flow control
    `static int` | `RTSCTS_FLOW_MASK` Defines bit mask of RTS/CTS hardware flow control
    `static int` | `STOP_BITS_1` Defines 1 stop bit on serial communication
    `static int` | `STOP_BITS_1_5` Defines 1.5 stop bits on serial communication
    `static int` | `STOP_BITS_2` Defines 2 stop bits on serial communication
    `static int` | `XOFF_FLOW_ENABLE` Defines software auto receive flow control
    `static int` | `XON_FLOW_ENABLE` Defines software auto transmit flow control
    `static int` | `XONXOFF_FLOW_ENABLE` Defines XON/XOFF software flow control
    `static int` | `XONXOFF_FLOW_MASK` Defines the bit mask of XON/XOFF hardware flow control

  - ### Method Summary

    All Methods Instance Methods Abstract Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()` Disable NPort's serial com port so that it cannot receive/transmit data.
    `void` | `flush(int mode)` Flushes any data in the NPort's output buffer.
    `int` | `getBaud()` Get the serial port baud rate setting.
    `MxNPort.FlowCtrl` | `getFlowCtrl()` Get the serial port's hardware and software flow control settings.
    `MxNPort.IoctlMode` | `getIoctlMode()` Gets the serial port's mode settings, such as data bits, parity, and stop bits.
    `MxNPort.LineError` | `getLineStatus()` Checks if errors occurred when receiving data, such as overrun error, parity error, framing error and break_error.
    `MxNPort.ModemStatus` | `getModemStatus()` Gets the line status, such as CTS, DSR, DCD, or RI.
    `java.net.InetAddress` | `getNPortIPAddress(int interface_index)` Returns the IP address of a NPort devices.
    `byte[]` | `getNPortMACAddress(int interface_number)` Returns the MAC address of a NPort devices.
    `int` | `getNPortMaximumPort()` Returns the total serial port number of a NPort device.
    `java.lang.String` | `getNPortModelName()` Returns the model name of a NPort device.
    `int` | `getNPortPortIndex()` Returns the using serial port number of a NPort device.
    `int` | `getOQueue()` Gets the length (in bytes) remaining in the NPort's output buffer.
    `void` | `open()` Open NPort's serial com port for data transmitting/receiving.
    `int` | `read(byte[] buffer)` Reads data from the port; returns the data if the buffer is full.
    `int` | `read(byte[] buffer, int length)` Reads data from a port; returns the data if the given length of data has been received.
    `int` | `read(byte[] buffer, int length, int timeout)` Reads data from the port; returns the data if the given length of data has been received.
    `void` | `setBaud(int speed)` Sets the baud rate using the actual speed value.
    `void` | `setBreak(int time)` Sends out a break signal.
    `void` | `setDTR(int mode)` Sets the DTR state for a serial port.
    `void` | `setFlowCtrl(MxNPort.FlowCtrl flow)` Sets the hardware and/or software flow control.
    `void` | `setIoctlMode(MxNPort.IoctlMode mode)` Configure communication parameters, such as baud rate, parity, data bits, stop bits and flow control settings.
    `void` | `setRTS(int mode)` Sets the RTS state for a serial port.
    `int` | `write(byte[] buffer)` Puts a block of data to the driver's output buffer.
    `int` | `write(byte[] buffer, int length)` Puts a block of data to the driver's output buffer.
    `int` | `write(byte[] buffer, int length, int timeout)` Puts a block of data to the driver's output buffer.

- - ### Field Detail

    - #### CTS_FLOW_ENABLE

          static final int CTS_FLOW_ENABLE

      Defines CTS hardware flow control
      See Also:
        Constant Field Values

    - #### CTS_OFF

          static final int CTS_OFF

      Defines CTS state OFF
      See Also:
        Constant Field Values

    - #### CTS_ON

          static final int CTS_ON

      Defines CTS state ON
      See Also:
        Constant Field Values

    - #### DATA_BITS_5

          static final int DATA_BITS_5

      Defines serial communication with 5 data bits
      See Also:
        Constant Field Values

    - #### DATA_BITS_6

          static final int DATA_BITS_6

      Defines serial communication with 6 data bits
      See Also:
        Constant Field Values

    - #### DATA_BITS_7

          static final int DATA_BITS_7

      Defines serial communication with 7 data bits
      See Also:
        Constant Field Values

    - #### DATA_BITS_8

          static final int DATA_BITS_8

      Defines serial communication with 8 data bits
      See Also:
        Constant Field Values

    - #### DCD_OFF

          static final int DCD_OFF

      Defines DCD state OFF
      See Also:
        Constant Field Values

    - #### DCD_ON

          static final int DCD_ON

      Defines DCD state ON
      See Also:
        Constant Field Values

    - #### DSR_FLOW_ENABLE

          static final int DSR_FLOW_ENABLE

      Defines DSR hardware flow control
      See Also:
        Constant Field Values

    - #### DSR_OFF

          static final int DSR_OFF

      Defines DSR state OFF
      See Also:
        Constant Field Values

    - #### DSR_ON

          static final int DSR_ON

      Defines DSR state ON
      See Also:
        Constant Field Values

    - #### DTR_FLOW_ENABLE

          static final int DTR_FLOW_ENABLE

      Defines DTR hardware flow control
      See Also:
        Constant Field Values

    - #### DTR_OFF

          static final int DTR_OFF

      Defines DTS state OFF
      See Also:
        Constant Field Values

    - #### DTR_ON

          static final int DTR_ON

      Defines DTS state ON
      See Also:
        Constant Field Values

    - #### DTRDSR_FLOW_ENABLE

          static final int DTRDSR_FLOW_ENABLE

      Defines DTR/DSR software flow control
      See Also:
        Constant Field Values

    - #### DTRDSR_FLOW_MASK

          static final int DTRDSR_FLOW_MASK

      Defines the bit mask of DTR/DSR hardware flow control
      See Also:
        Constant Field Values

    - #### FLUSH_INPUT

          static final int FLUSH_INPUT

      Defines the flush to read buffer (Reserve for Android socket API)
      See Also:
        Constant Field Values

    - #### FLUSH_OUTPUT

          static final int FLUSH_OUTPUT

      Defines the flush to write buffer
      See Also:
        Constant Field Values

    - #### LINE_ERROR

          static final int LINE_ERROR

      Defines the error state for each `LineError` field
      See Also:
        Constant Field Values

    - #### LINE_NO_ERROR

          static final int LINE_NO_ERROR

      Defines the non-error state for each `LineError` field
      See Also:
        Constant Field Values

    - #### PARITY_EVEN

          static final int PARITY_EVEN

      Defines even parity checking
      See Also:
        Constant Field Values

    - #### PARITY_MARK

          static final int PARITY_MARK

      Defines mark parity checking
      See Also:
        Constant Field Values

    - #### PARITY_NONE

          static final int PARITY_NONE

      Defines no parity checking
      See Also:
        Constant Field Values

    - #### PARITY_ODD

          static final int PARITY_ODD

      Defines odd parity checking
      See Also:
        Constant Field Values

    - #### PARITY_SPACE

          static final int PARITY_SPACE

      Defines space parity checking
      See Also:
        Constant Field Values

    - #### RI_OFF

          static final int RI_OFF

      Defines RI state OFF (Reserve)
      See Also:
        Constant Field Values

    - #### RI_ON

          static final int RI_ON

      Defines RI state ON (Reserve)
      See Also:
        Constant Field Values

    - #### RTS_FLOW_ENABLE

          static final int RTS_FLOW_ENABLE

      Defines RTS hardware flow control
      See Also:
        Constant Field Values

    - #### RTS_OFF

          static final int RTS_OFF

      Defines RTS state OFF
      See Also:
        Constant Field Values

    - #### RTS_ON

          static final int RTS_ON

      Defines RTS state ON
      See Also:
        Constant Field Values

    - #### RTSCTS_FLOW_ENABLE

          static final int RTSCTS_FLOW_ENABLE

      Defines RTS/CTS hardware flow control
      See Also:
        Constant Field Values

    - #### RTSCTS_FLOW_MASK

          static final int RTSCTS_FLOW_MASK

      Defines bit mask of RTS/CTS hardware flow control
      See Also:
        Constant Field Values

    - #### STOP_BITS_1

          static final int STOP_BITS_1

      Defines 1 stop bit on serial communication
      See Also:
        Constant Field Values

    - #### STOP_BITS_1_5

          static final int STOP_BITS_1_5

      Defines 1.5 stop bits on serial communication
      See Also:
        Constant Field Values

    - #### STOP_BITS_2

          static final int STOP_BITS_2

      Defines 2 stop bits on serial communication
      See Also:
        Constant Field Values

    - #### XOFF_FLOW_ENABLE

          static final int XOFF_FLOW_ENABLE

      Defines software auto receive flow control
      See Also:
        Constant Field Values

    - #### XON_FLOW_ENABLE

          static final int XON_FLOW_ENABLE

      Defines software auto transmit flow control
      See Also:
        Constant Field Values

    - #### XONXOFF_FLOW_ENABLE

          static final int XONXOFF_FLOW_ENABLE

      Defines XON/XOFF software flow control
      See Also:
        Constant Field Values

    - #### XONXOFF_FLOW_MASK

          static final int XONXOFF_FLOW_MASK

      Defines the bit mask of XON/XOFF hardware flow control
      See Also:
        Constant Field Values

  - ### Method Detail

    - #### close

          void close()
              throws MxException

      Disable NPort's serial com port so that it cannot receive/transmit data.
      Upon executing close(), the actual "close" action depends on the data remaining in output buffer of the COM port.
      If no data remains in output buffer, the COM port will be closed immediately.
      If data remains in output buffer, close() waits maximum for 3 seconds to let the remaining data sent out.
      After 3 seconds, if data still remains in output buffer, all data will be flushed immediately. Then the COM port is closed.

      Example:

             ...
             try{
                 mCurrentNPort.open();
             } catch (MxException e) {
                 // Open fail
             }
             ...
             try{
                 //Close the NPort's serial com port
                 mCurrentNPort.close();
             } catch (MxEcxeption e) {
                 //Close fail
             }

      Throws:
        `MxException` - If an error occurs.

    - #### flush

          void flush(int mode)
              throws MxException

      Flushes any data in the NPort's output buffer.

      Example:

             ...
             try{
                 mCurrentNPort.open();
             } catch (MxException e) {
                 // Open fail
             }
             try{
                 // Flush the data in the output buffer
                 mCurrentNPort.flush(MxNPort.FLUSH_OUTPUT);
             } catch (MxException e) {
                 // Flush fail
             }

      Parameters:
        `mode` - `FLUSH_OUTPUT`.
      Throws:
        `MxException` - If an error occurs.

    - #### getBaud

          int getBaud()
               throws MxException

      Get the serial port baud rate setting. The return value is the actual baud rate. For example, a return value of 9600 means 9600 bps whereas 200 means 200bps.

      Example:

             ...
             try{
                 mCurrentNPort.open();
             } catch (MxException e) {
                 // Open fail
             }
             try{
                 // Get the NPort current baud rate
                 int baud = mCurrentNPort.getBaud();
             } catch (MxException e) {
                 // Get baud rate fail
             }

      Returns:
        The actual baud rate.
      Throws:
        `MxException` - If an error occurs.

    - #### getFlowCtrl

          MxNPort.FlowCtrl getFlowCtrl()
                                throws MxException

      Get the serial port's hardware and software flow control settings.

      Example:

             ...
             try{
                 mCurrentNPort.open();
             } catch (MxException e) {
                 // Open fail
             }
             try{
                 // Get the NPort current flow control setting
                 MxNPort.FlowCtrl flow = mCurrentNPort.getFlowCtrl();
             } catch (MxException e) {
                 // Get flow control setting fail
             }

      Returns:
        `FlowCtrl`
      Throws:
        `MxException` - If an error occurs.

    - #### getIoctlMode

          MxNPort.IoctlMode getIoctlMode()
                                  throws MxException

      Gets the serial port's mode settings, such as data bits, parity, and stop bits.

      Example:

             ...
             try{
                 mCurrentNPort.open();
             } catch (MxException e) {
                 // Open fail
             }
             try{
                 // Gets the NPort serial port's mode settings
                 MxNPort.IoctlMode mode = mCurrentNPort.getIoctlMode();
             } catch (MxException e) {
                 // Get serial port's mode setting fail
             }

      Returns:
        `IoctlMode`
      Throws:
        `MxException` - If an error occurs.

    - #### getLineStatus

          MxNPort.LineError getLineStatus()
                                   throws MxException

      Checks if errors occurred when receiving data, such as overrun error, parity error, framing error and break_error. Detail of these errors can refer to `LineError`. Returns and cleans the error during the transaction.

      Example:

             ...
             try{
                 mCurrentNPort.open();
             } catch (MxException e) {
                 // Open fail
             }

             try{
                // Get if errors occurred when receiving data
                MxNPort.LineError lineError = mCurrentNPort.getLineStatus();
             } catch (MxException e) {
                // Get if errors occurred when receiving data fail
             }

      Returns:
        `LineError`
      Throws:
        `MxException` - If an error occurs.

    - #### getModemStatus

          MxNPort.ModemStatus getModemStatus()
                                      throws MxException

      Gets the line status, such as CTS, DSR, DCD, or RI.

      Example:

             ...
             try{
                 mCurrentNPort.open();
             } catch (MxException e) {
                 // Open fail
             }

             try{
                // Get NPort's line status
                MxNPort.ModemStatus modem = mCurrentNPort.getModemStatus();
             } catch (MxException e) {
                // Get NPort's line status fail
             }

      Returns:
        `ModemStatus`
      Throws:
        `MxException` - If an error occurs.

    - #### getNPortIPAddress

          java.net.InetAddress getNPortIPAddress(int interface_index)
                                          throws MxException

      Returns the IP address of a NPort devices.

      Example:
      Write characters to NPort's serial com port.

             try{
                InetAddress addr = getNPortIPAddress(1);
             } catch (MxException e) {
                 // Get IP address fail
             }

      Parameters:
        `interface_index` - [in] The interface port index, only support first interface port now.
      Returns:
        The IP address of the device.
      Throws:
        `MxException` - If an error occurs.

    - #### getNPortMACAddress

          byte[] getNPortMACAddress(int interface_number)
                             throws MxException

      Returns the MAC address of a NPort devices.

      Example:
      Write characters to NPort's serial com port.

             try{
                byte[] mac = getNPortMACAddress(1);
             } catch (MxException e) {
                 // Get MAC address fail
             }

      Parameters:
        `interface_number` - [in] The interface port index, only support first interface port now.
      Returns:
        The MAC address of the device.
      Throws:
        `MxException` - If an error occurs.

    - #### getNPortMaximumPort

          int getNPortMaximumPort()
                           throws MxException

      Returns the total serial port number of a NPort device.

      Example:
      Write characters to NPort's serial com port.

             try{
                 int number = getNPortMaximumPort();
             } catch (MxException e) {
                 // Get total serial port number fail
             }

      Returns:
        The total serial port number of the device.
      Throws:
        `MxException`

    - #### getNPortModelName

          java.lang.String getNPortModelName()
                                      throws MxException

      Returns the model name of a NPort device.

      Example:
      Write characters to NPort's serial com port.

             try{
                 String model = getNPortModelName();
             } catch (MxException e) {
                 // Get model name fail
             }

      Returns:
        The model name of the device.
      Throws:
        `MxException`

    - #### getNPortPortIndex

          int getNPortPortIndex()
                         throws MxException

      Returns the using serial port number of a NPort device.

      Example:
      Write characters to NPort's serial com port.

             try{
                 int number = getNPortPortIndex();
             } catch (MxException e) {
                 // Get using serial port number fail
             }

      Returns:
        The using serial port number of the device.
      Throws:
        `MxException`

    - #### getOQueue

          int getOQueue()
                 throws MxException

      Gets the length (in bytes) remaining in the NPort's output buffer.

      Example:

             ...
             try{
                 mCurrentNPort.open();
             } catch (MxException e) {
                 // Open fail
             }

             try{
                // Get the length of NPort's output buffer.
                int oqueue_len = mCurrentNPort.getOQueue();
             } catch (MxException e) {
                // Get the length of NPort's output buffer. fail
             }

      Returns:
        The length output buffer.
      Throws:
        `MxException` - If an error occurs.

    - #### open

          void open()
             throws MxException

      Open NPort's serial com port for data transmitting/receiving. This function will connect to NPort by socket. You should call this function before most of other functions in MxNPort.
      After calling open(), the initial status of the COM port is:

      Baud rate | Data bits | Stop bits | Parity | Flow control | DTR state | RTS state
      38400 bps | 8 | 1 | None | None | ON | ON

      Example:

             // Get a MxNPort list from current network
             List<MxNPort> mNPortList = MxNPortService.getNPortInfoList();

             if( mNPortList!=null ){
                 // Get the first NPort device
                 MxNPort mCurrentNPort = mNPortList.get(0);
                 try{
                     // Open the NPort's serial com port
                     mCurrentNPort.open();
                 } catch (MxException e) {
                     // Open fail
                 }
             }

      Throws:
        `MxException` - If an error occurs.

    - #### read

          int read(byte[] buffer)
            throws MxException

      Reads data from the port; returns the data if the buffer is full.

      Example:
      Read 10 characters form NPort's serial com port.

             ...
             try{
                 // Open the NPort's serial com port
                 mCurrentNPort.open();
             } catch (MxException e) {
                 // Open fail
             }
             int len;
             char buf[10];
             try{
                 len = read(buf);
             } catch (MxException e) {
                 // Read fail
             }
             if(len < 0) {
                 // fail
             }

      Parameters:
        `buffer` - [in][out] The repository for the incoming data.
      Returns:
        The actual read data in the buffer.
      Throws:
        `MxException` - If an error occurs.

    - #### read

          int read(byte[] buffer,
                   int length)
            throws MxException

      Reads data from a port; returns the data if the given length of data has been received.

      Example:
      Read 10 characters form NPort's serial com port.

             ...
             try{
                 // Open the NPort's serial com port
                 mCurrentNPort.open();
             } catch (MxException e) {
                 // Open fail
             }
             int len;
             char buf[10];
             try{
                 len = read(buf, 10);
             } catch (MxException e) {
                 // Read fail
             }
             if(len < 0) {
                 // fail
             }

      Parameters:
        `buffer` - [in][out] The repository for the incoming data.
        `length` - [in] The required data length. It must not exceed the size of the buffer.
      Returns:
        The actual read data in the buffer.
      Throws:
        `MxException` - If an error occurs.

    - #### read

          int read(byte[] buffer,
                   int length,
                   int timeout)
            throws MxException

      Reads data from the port; returns the data if the given length of data has been received. Otherwise, if a timeout has occurred, the received data will be stored in the buffer and the length of received data will be returned.

      Example:
      Read 10 characters form NPort's serial com port whit timeout 5 seconds.

             ...
             try{
                 // Open the NPort's serial com port
                 mCurrentNPort.open();
             } catch (MxException e) {
                 // Open fail
             }
             int len;
             char buf[10];
             int timeout = 5000;
             try{
                 len = read(buf, 10, timeout);
             } catch (MxException e) {
                 // Read fail
             }
             if(len < 0) {
                 // fail
             }

      Parameters:
        `buffer` - [in][out] The repository for the incoming data.
        `length` - [in] The required data length. It must not exceed the size of the buffer.
        `timeout` - [in] The timeout value for receiving data.
      Returns:
        The actual read data in the buffer.
      Throws:
        `MxException` - If an error occurs.

    - #### setBaud

          void setBaud(int speed)
                throws MxException

      Sets the baud rate using the actual speed value.

      Example:
      Set baud rate to 38400bps

             ...
             try{
                 // Open the NPort's serial com port
                 mCurrentNPort.open();
             } catch (MxException e) {
                 // Open fail
             }
             int speed = 38400;
             try{
                 // Set baud rate 38400bps
                 mCurrentNPort.setBaud(speed);
             } catch (MxException e) {
                 // Set baud rate fail
             }

      Parameters:
        `speed` - [in] The true baud rate, e.g. 200, 1200, 9600, 19200, etc.
      Throws:
        `MxException` - If an error occurs.

    - #### setBreak

          void setBreak(int time)
                 throws MxException

      Sends out a break signal. This function will block access for the given length of time.

      Example:

             ...
             try{
                 // Open the NPort's serial com port
                 mCurrentNPort.open();
             } catch (MxException e) {
                 // Open fail
             }
             int time = 1000;
             try{
                 // Keep sending break to NPort in 1 second
                 mCurrentNPort.setBreak(time);
             } catch (MxException e) {
                 // Send break to NPort fail
             }

      Parameters:
        `time` - [in] Break time in milliseconds.
      Throws:
        `MxException` - If an error occurs.

    - #### setDTR

          void setDTR(int mode)
               throws MxException

      Sets the DTR state for a serial port.

      Example:

             ...
             try{
                 // Open the NPort's serial com port
                 mCurrentNPort.open();
             } catch (MxException e) {
                 // Open fail
             }
             try{
                 // Set DTR enable
                 mCurrentNPort.setDTR(MxNPort.DTR_ON);
             } catch (MxException e) {
                 // Set DTR enable fail
             }

      Parameters:
        `mode` - [in] for the DTR setting, which is either `DTR_ON` or `DTR_OFF`.
      Throws:
        `MxException` - If an error occurs.

    - #### setFlowCtrl

          void setFlowCtrl(MxNPort.FlowCtrl flow)
                    throws MxException

      Sets the hardware and/or software flow control. Supports `RTSCTS_FLOW_ENABLE` and `XONXOFF_FLOW_ENABLE` flow control settings.

      Example:
      Set baud rate to 38400bps

             ...
             try{
                 // Open the NPort's serial com port
                 mCurrentNPort.open();
             } catch (MxException e) {
                 // Open fail
             }
             MxNPort.FlowCtrl flow = new MxNPort.FlowCtrl();
             flow.RtsCts |= MxNPort.RTSCTS_FLOW_ENABLE;
             flow.XonXoff |= MxNPort.XONXOFF_FLOW_ENABLE;
             flow.DtrDsr &= 0;
             try{
                 // Configure NPort's flow control
                 mCurrentNPort.setFlowCtrl(flow);
             } catch (MxException e) {
                 // Configure NPort's flow control
             }

      Parameters:
        `flow` - [in] `FlowCtrl` contains flow control settings.
      Throws:
        `MxException` - If an error occurs.

    - #### setIoctlMode

          void setIoctlMode(MxNPort.IoctlMode mode)
                     throws MxException

      Configure communication parameters, such as baud rate, parity, data bits, stop bits and flow control settings.

      Example:

             ...
             try{
                 // Open the NPort's serial com port
                 mCurrentNPort.open();
             } catch (MxException e) {
                 // Open fail
             }
             MxNPort.IoctlMode mode = new MxNPort.IoctlMode();
             mode.baud = 38400;
             mode.dataBits = MxNPort.DATA_BITS_8;
             mode.mParity = MxNPort.PARITY_NONE;
             mode.stopBits = MxNPort.STOP_BITS_1;
             try{
                 // Configure NPort's communication parameters
                 mCurrentNPort.setIoctlMode(mode);
             } catch (MxException e) {
                 // Configure NPort's communication parameters fail
             }

      Parameters:
        `mode` - [in] `IoctlMode` contains serial settings.
      Throws:
        `MxException` - If an error occurs.

    - #### setRTS

          void setRTS(int mode)
               throws MxException

      Sets the RTS state for a serial port.

      Example:

             ...
             try{
                 // Open the NPort's serial com port
                 mCurrentNPort.open();
             } catch (MxException e) {
                 // Open fail
             }
             try{
                 // Set RTS enable
                 mCurrentNPort.setRTS(MxNPort.RTS_ON);
             } catch (MxException e) {
                 // Set RTS enable fail
             }

      Parameters:
        `mode` - [in] for RTS settings; is either `RTS_ON` or `RTS_OFF`.
      Throws:
        `MxException` - If an error occurs.

    - #### write

          int write(byte[] buffer)
             throws MxException

      Puts a block of data to the driver's output buffer. The actual length of data written depends on the amount of free space in the driver's output buffer. The write() returns when all data in the buffer has been sent.

      Example:
      Write characters to NPort's serial com port.

             ...
             try{
                 // Open the NPort's serial com port
                 mCurrentNPort.open();
             } catch (MxException e) {
                 // Open fail
             }
             int len;
             byte[] buf = {'H','e','l','l','o',' ','W','o','r','l','d'};
             try{
                 len = write(buf);
             } catch (MxException e) {
                 // write fail
             }
             if(len < 0) {
                 // fail
             }

      Parameters:
        `buffer` - [in] The buffer contains all data to send.
      Returns:
        The actual data written to the device.
      Throws:
        `MxException` - If an error occurs.

    - #### write

          int write(byte[] buffer,
                    int length)
             throws MxException

      Puts a block of data to the driver's output buffer. The actual length of data written depends on the amount of free space in the driver's output buffer. The write() returns when the given length of data in the buffer has been sent.

      Example:
      Write characters to NPort's serial com port.

             ...
             try{
                 // Open the NPort's serial com port
                 mCurrentNPort.open();
             } catch (MxException e) {
                 // Open fail
             }
             int len;
             byte[] buf = {'H','e','l','l','o',' ','W','o','r','l','d'};
             try{
                 len = write(buf, buf.length);
             } catch (MxException e) {
                 // write fail
             }
             if(len < 0) {
                 // fail
             }

      Parameters:
        `buffer` - [in] The buffer that contains data to send.
        `length` - [in] The length of data to send.
      Returns:
        The actual data written to the device.
      Throws:
        `MxException` - If an error occurs.

    - #### write

          int write(byte[] buffer,
                    int length,
                    int timeout)
             throws MxException

      Puts a block of data to the driver's output buffer. The actual length of data written depends on the amount of free space in the driver's output buffer. The write() returns when the given length of data in the buffer has been sent. Otherwise, if a timeout occurs the write() returns the transmitted length of data. The caller should handle transmitting the other data.

      Example:
      Write characters to NPort's serial com port.

             ...
             try{
                 // Open the NPort's serial com port
                 mCurrentNPort.open();
             } catch (MxException e) {
                 // Open fail
             }
             int len;
             int timeout = 1000;
             byte[] buf = {'H','e','l','l','o',' ','W','o','r','l','d'};
             try{
                 len = write(buf, buf.length, timeout);
             } catch (MxException e) {
                 // write fail
             }
             if(len < 0) {
                 // fail
             }

      Parameters:
        `buffer` - [in] The buffer that contains data to send.
        `length` - [in] The length of data to send.
        `timeout` - [in] The timeout value to receive data.
      Returns:
        The actual data written to the device.
      Throws:
        `MxException` - If an error occurs.