获取环形指示器isRING并使用jssc库将其添加到侦听器?

问题描述

我正在尝试使用JSSC库为收银机编写一个小程序。我已经使用该库在条形码扫描仪上工作,并且可以正常工作,并且从扫描仪获得了返回值。但是对于收银机,我没有任何价值。每当收银机打开时,ringindicator = true,关闭时为false。在这种情况下,如何创建侦听器以获取ringindicator的状态(在SerialPort类中为isRING())。谢谢!

 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,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;
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...