public static void main(String[] args) {
        // System.out.println("STARTING.");

        if (args[0].equals("--list")) {
            String[] portNames = SerialPortList.getPortNames();
            for (int i = 0; i < portNames.length; i++){
                outCommand('p', portNames[i].getBytes());
            }
            outCommand('p', new byte[] { });
            System.exit(0);
        }

        serialPort = new SerialPort(args[0]); 
        try {
            serialPort.openPort();//Open port
            serialPort.setParams(9600, 8, 1, 0);//Set params
            int mask = SerialPort.MASK_RXCHAR + SerialPort.MASK_CTS + SerialPort.MASK_DSR;//Prepare mask
            serialPort.setEventsMask(mask);//Set mask
            serialPort.addEventListener(new SerialPortReader());//Add SerialPortEventListener
        }
        catch (SerialPortException ex) {
            System.err.println("Error opening serial port.");
            outError(ex);
            silentClose();
            System.exit(1);
        }

        Runtime.getRuntime().addShutdownHook(new Thread() {
            public void run() {
                silentClose();
            }
        });

        outCommand('L', new byte[] {});

      //  read the username from the command-line; need to use try/catch with the
      //  readLine() method
        while (true) {
            // System.out.println("TRYING TO READING...");
            BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));  
            try {
                String input = stdin.readLine();
                if (input.substring(0, 1).equals("O")) {
                    byte[] o = DatatypeConverter.parseBase64Binary(input.substring(1));
                    serialPort.writeBytes(o);
                } else if (input.substring(0, 1).equals("B")) {
                    System.err.println("Break 5 seconds");
                    serialPort.sendBreak(5000);
                }
            } catch (IOException ex) {
                System.err.println("Stdin error.");
                outError(ex);
                silentClose();
                System.exit(2);
            } catch (SerialPortException ex) {
                System.err.println("Writing error.");
                outError(ex);
                silentClose();
                System.exit(3);
            }
        }
    }