Getting Ring Indicator isRING() and add it to the listener using jssc library?

61 views Asked by At

I am trying to write a little program for the cash register using JSSC library. I have used that library to work on barcode scanner and it works fine and I get the return value from the scanner. But for cash register case, I do not get any value. Whenever the cash register is open, ringindicator = true and false when close. How do I create a listener to get the status of ringindicator in this case isRING() in SerialPort class. Thank you!

 public class CashRegister implements SerialPortEventListener {

    private SerialPort serialPort;

    private CashRegisterCallBack callback;

    public CashRegister(CashRegisterCallBack callback) {
        this.callback = callback;
    }

    private boolean result;


    public void startScan() {

        try {
            serialPort = new SerialPort("COM1");
            if (serialPort.isOpened()) {
                serialPort.closePort();
            }
            serialPort.openPort();//Open serial port
            serialPort.addEventListener(this);
            //Set params. Also you can set params by this string: serialPort.setParams(9600, 8, 1, 0);
            serialPort.setParams(9600, 8, 1, 0);
            //Triggers scanner in scanning mode
            serialPort.writeByte((byte)7); // opens the register

        } catch (SerialPortException ex) {
            System.out.println(ex);
        }
    }

        //doesnot get to this method when closed

    @Override
    public void serialEvent(SerialPortEvent event) {
       
        boolean isDataAvailable = event.isRING();
        //Check bytes count in the input buffer

        System.out.println(isDataAvailable);
        try {
            this.callback.callback(isDataAvailable);
                serialPort.writeString(new String(new byte[]{0x03}));
            System.out.println("Close message sent");
                serialPort.removeEventListener();
            System.out.println("Event Listener removed");
                serialPort.closePort();
            System.out.println("Port Closed");
            System.exit(0);
        } catch (IOException | InterruptedException | SerialPortException e) {
            e.printStackTrace();
        }

    }

}

public interface CashRegisterCallBack {
    void callback(boolean result) throws IOException, InterruptedException;
}
0

There are 0 answers