0

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;
}
sanki
  • 59
  • 2
  • 9
  • Unless you're using a real modem, the RING and RLSD signal lines are often unconnected. If the specifications of the so-called "cash register case" state that the open/close status is actually notified from RING, the specifications of the cable required for connection are described or a dedicated cable is sold. Please check if you are using that cable. – kunif Oct 15 '20 at 22:04
  • Thank you for your reply. I am using the provided cable and also have software from the supplier. The software shows the status of the ring indicator with the same cable we are using and I am trying to imitate the same in my program. How do I go about this using any java library. Any ideas? – sanki Oct 21 '20 at 19:22
  • Please try specifying [MASK_RING](http://javadox.com/org.scream3r/jssc/2.8.0/javadoc/jssc/SerialPort.html#MASK_RING) in [setEventsMask](http://javadox.com/org.scream3r/jssc/2.8.0/javadoc/jssc/SerialPort.html#setEventsMask(int)), as in the first example on this [Java SerialPortException Examples](https://java.hotexamples.com/examples/jssc/SerialPortException/-/java-serialportexception-class-examples.html) page. – kunif Oct 21 '20 at 22:45

0 Answers0