마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

시리얼통신 usb-serial-for-android-v010.jar

0 추천

UsbSerialDriver mDriver = UsbSerialProber.acquire(manager, device);

사용하려고 하는데요 널값이 계속 들어오고 있습니다

널값이 들어오면 안되는건데..

시러얼통신 기계에 정보는 읽어오는것은 되고 있지만

저기서 널값이 안뜰때에 mDriver.open(); 을 시도 하고 있습니다.

권한은 이미 다들어가 있는 상태고..

device_filter.xml에도 설정을 잡아놓은 상태입니다..

혹시 격어보신분 말씀좀 부탁드립니다.

간략적인 소스는 이러합니다.

 

UsbManager manager = (UsbManager) mContext.getSystemService(Context.USB_SERVICE);
HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
if (pos == 0) {
 
Log.d(tag, "Device Count : " + deviceList.size());
mListener.onReceive(Constants.MSG_DEVICE_COUNT, deviceList.size(), 0, null, null);
 
Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
while(deviceIterator.hasNext()){
StringBuilder sb = new StringBuilder();
UsbDevice device = deviceIterator.next();
sb.append(" DName : ").append(device.getDeviceName()).append("\n")
.append(" DID : ").append(device.getDeviceId()).append("\n")
.append(" VID : ").append(device.getVendorId()).append("\n")
.append(" PID : ").append(device.getProductId()).append("\n")
.append(" IF Count : ").append(device.getInterfaceCount()).append("\n");
mListener.onReceive(Constants.MSG_DEVICD_INFO, 0, 0, sb.toString(), null);
 
if( device.getVendorId() == TARGET_VENDOR_ID) {
mDevice = device; // This is target device
}
}
 
if(mDevice != null ) {
try {
// WARNING!!
// If you've got the exception about you have no permission to this device.
// Check /xml/device_filter.xml
mDriver =  UsbSerialProber.acquire(manager, mDevice);
}
catch(Exception allEx) {
// User has not given permission to current device
mListener.onReceive(Constants.MSG_SERIAL_ERROR, 0, 0, "Fatal Error : User has not given permission to current device. \n", null);
return;
}
 
if(mDriver != null) {
try {
mDriver.open();
mDriver.setBaudRate(BAUD_RATE);
catch (IOException e) {
mListener.onReceive(Constants.MSG_SERIAL_ERROR, 0, 0, "Error 1: " + e.toString() + "\n", null);
return;
catch (Exception allEx) {
mListener.onReceive(Constants.MSG_SERIAL_ERROR, 0, 0, "Error 2: " + allEx.toString() + "\n", null);
return;
finally {
}
 
// Everything is fine. Start serial monitoring thread.
startThread();
 
} else {
mListener.onReceive(Constants.MSG_SERIAL_ERROR, 0, 0, "Error 3: Driver is Null \n", null);
}
}
kiraim (3,040 포인트) 님이 2015년 4월 13일 질문

1개의 답변

0 추천
자답입니다.

OTG 케이블을 써야합니다.
kiraim (3,040 포인트) 님이 2015년 4월 14일 답변
...