New to serial development (newer to development) and have been working with the JSSC library. I am working on an application that will control the actions of an electrometer.

I experimented with the example code provided in this link I'm getting DSR -Off which then makes me assume that the flow control being used is DTR/DSR. The section of this code I don't understand is the following:

Java Code:
int mask = SerialPort.MASK_RXCHAR + SerialPort.MASK_CTS + SerialPort.MASK_DSR;//Prepare mask
The term Mask seems to be a pretty commonly referenced term but I can not find a concrete definition of what it is and why it needs to be set. DTR/DSR is a form of hardware flow control. I know the const value for DSR is 16 per the API but what do you do with this?

The following code:

Java Code:
package org.mfldclin.readmeter.serialConnection;

import java.io.UnsupportedEncodingException;

import jssc.SerialPort;
import jssc.SerialPortEvent;
import jssc.SerialPortEventListener;
import jssc.SerialPortException;
import jssc.SerialPortList;
import jssc.SerialPortTimeoutException;

public class SerialConnection {
	
	static SerialPort serialPort = new SerialPort("com9");
	
	public void establishCom() {		
		try {
			serialPort.openPort();
            serialPort.setParams(19200, 8, 1, 0, false, true);            
            int mask = SerialPort.MASK_RXCHAR + SerialPort.MASK_DSR;
            //Set the prepared mask
            serialPort.setEventsMask(mask);

            //Add an interface through which we will receive information about events
            serialPort.addEventListener(new SerialPortReader());
            try {
				serialPort.writeString("ETX", "US-ASCII");
			} catch (UnsupportedEncodingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
            //serialPort.writeString("*AUZ?");						
			serialPort.closePort();
		} catch (SerialPortException ex) {
			System.out.println(ex);
		}		
	}
	
	static class SerialPortReader implements SerialPortEventListener {
		public void serialEvent(SerialPortEvent event) {
			
            if(event.isRXCHAR()){//If data is available
                if(event.getEventValue() == 8){//Check bytes count in the input buffer
                    //Read data, if 10 bytes available 
                    try {
                        byte buffer[] = serialPort.readBytes(8);                       
                    }
                    catch (SerialPortException ex) {
                        System.out.println(ex);
                    }
                }
            }
            else if(event.isCTS()){//If CTS line has changed state
                if(event.getEventValue() == 1){//If line is ON
                    System.out.println("CTS - ON");
                }
                else {
                    System.out.println("CTS - OFF");
                }
            }
            else if(event.isDSR()){///If DSR line has changed state            	
                if(event.getEventValue() == 1){//If line is ON
                    System.out.println("DSR - ON");
                }
                else {
                    System.out.println("DSR - OFF");
                    try {
						System.out.println(serialPort.getFlowControlMode() + " Flow Control Mode");
					} catch (SerialPortException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}                    
                }
            }
        }
    }
}
produces this result set:

DSR - OFF
0 Flow Control Mode
DSR - OFF
0 Flow Control Mode
This line
Java Code:
serialPort.writeString("ETX", "US-ASCII");
puts the electrometer in a state in which it can receive commands. What I should be getting back is
=>
which indicates the command was successful but I'm not sure how to read back the data coming from the electrometer.

1. Why am I seeing the result set above twice like that? It is responding to a state change but I don't understand what that might mean.
2. In this context what is a mask and how to decided how it is set.

Any tips would be helpful if for nothing else to help me define what exactly I should be researching for. Doing my best to understand serial communication but sometimes it's helpful to have someone see where your struggles are to clarify. Thanks in advance.