2011-09-28 1 views
0
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(); 

를 사용하여 프린터로부터의 응답을받는 : 은 CommPortIdentifier portId = CommPortIdentifier.getPortIdentifier ("COM");흐름은 다음 행에 관해서는 오차를 줄 상기 프로그램에서 XON 및 Xoff로

오류 :: java.lang.ExceptionInInitializerError

답변

0

허? CommPortIdentifier 클래스가 Android에 없습니다. 어떻게 이것을 컴파일하게 만들었습니까?

또한 안드로이드는 Windows가 아니므로 직렬 포트 (있는 경우)는 "COM"이라고 불리지 않습니다.

먼저, 블루투스 프린터로 이야기가이 안드로이드 API에서 사용할 수있는 유일한 블루투스 프로토콜이기 때문에 RFCOMM을 지원하는지 확인하려면, 두 번째 블루투스 튜토리얼 참조 : 답장을 http://developer.android.com/guide/topics/wireless/bluetooth.html

+0

하이 피터 감사 , –

+0

우리는 jar 파일 "javax.comm"인 API를 가지고 있는데이 클래스는 CommPortIdentifier 클래스를 제공합니다. 그렇다면 CommPortIdentifier가 작동하지 않는다고 가정 해 봅시다. bluetoothSocket.getInputStream()을 피곤했기 때문에 다른 방법으로 블루투스 프린터를들을 수 있었지만,이 스트림에는 아무 것도주지 않았습니다. 메모리 버퍼가 오버 플로우되는 동안 프린터가 보낸 xon (십진 값 = 17) 및 xoff (십진 값 = 19) (메모리 버퍼 오버 플로우 동안 보냄) 플래그를 청취하고 싶다는 또 하나의 요점을 추가하고 싶습니다. –

+0

데스크톱 자바에서 클래스를 가져 와서 Android에서 작동하도록 기대할 수는 없습니다. "javax.comm"은 Android에없는 저수준 기능을 사용합니다. 전자에서는 직렬 포트를 Android에서 사용할 수 없습니다. –

관련 문제