开发者

Taking the Response from the Printer by using Xon and Xoff

how to retrieve the printer response from the Bluetooth printer in android by using X-On and X-Off. I have tried but It is not working. I have tried with the following code but it is not working:

CommPortIdentifier portId  = CommPortIdentifier.getPortIdentifier("COM");
SerialPort sPort = (SerialPort)portId .open(this.getClass().getName(), 30000);
sPort.setSerialPortParams(9600, SerialPort.DATABITS_8,SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
                                            sPort.setFlowControlMode(SerialPort.FLOWCONTROL_XONXOFF_IN | SerialPort.FLOWCONTROL_XONXOFF_OUT);

 OutputStream os = sPort.getOutputStream();
 os=  sPort.getOutputStream();
 InputStream is = sPort.getInputStream(); 
os.write(baos.toByteArray(), 0, baos.toByteArray().length);
 StringBuffer inputBuffer = new StringBuffer();

do{
     for(int newData = is.read();newData != -1; newData = is.read())
      {
        inputBuffer.append((char)newData);
      }

      try
       {
         Thread.sleep(300);
       }
      catch
       {
       }
  }while(inputBuffer.length() <= 0);

String sDataIn = inputBuffer.toString();

In the above program when the flow comes in the following line it give an error: C开发者_Python百科ommPortIdentifier portId = CommPortIdentifier.getPortIdentifier("COM");

Error is::java.lang.ExceptionInInitializerError


Huh? CommPortIdentifier class does not exist in Android. How did you even get this to compile?

Also, Android is not Windows so serial ports (if they existed) would not be called "COM".

If you want to talk to your Bluetooth printer, first make sure it supports RFCOMM as this is the only Bluetooth protocol that is available in Android API, second see the Bluetooth tutorial: http://developer.android.com/guide/topics/wireless/bluetooth.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜