Hi,
This is Lakshmansundeep. I am developing an application that sends the data android device to micro controller as vice versa via VIRTUAL COMM PORT using usb cable. I did my usb connection establishment successfully,coming to the communication part i.e. Communication from Android Device to micro controller and the application was crashed because of having single end point to the virtual comm port.please help me how to communicate to virtual comm port having single end point...please it was a little bit urgent.
Here is my Android Activity java code after my method called:
public boolean Check_Devices_Available()
{
int i,j;
boolean Device_Found;
String as[];
UsbEndpoint tOut = null;
UsbEndpoint tIn = null;
UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
i = deviceList.size();
if(i==0)
{
Toast.makeText(Loginpage.this,"No Devices Attached",Toast.LENGTH_LONG).show();
return false;
}
as = new String[i];
deviceList.keySet().toArray(as);
Device_Found=false;
for(j=0;j<i;j++)
{
device_details = (UsbDevice)deviceList.get(as[j]);
if((device_details.getVendorId()==targetVendorID) && (device_details.getProductId()==targetProductID))
{
Toast.makeText(Loginpage.this,"Device Connected",Toast.LENGTH_LONG).show();
Device_Found=true;
break;
}
}
if(Device_Found==false)
{
Toast.makeText(Loginpage.this,"No Devices Attached with Req Vendor ID",Toast.LENGTH_LONG).show();
return false;
}
if(manager.hasPermission(device_details)==true)
{
Toast.makeText(Loginpage.this, "Permission Granted", Toast.LENGTH_LONG).show();
// Device_Settings(Device_Detials,j);
}
else
{
//PendingIntent intent = null;
Toast.makeText(Loginpage.this, "No Permission", Toast.LENGTH_LONG).show();
manager.requestPermission(device_details, null);
}
UsbEndpoint Device_End_Point = null;
UsbInterface usbinterface = device_details.getInterface(j);
if (usbinterface == null)
{
Toast.makeText(Loginpage.this, "Device Found But UnKnown Exception-1", 50000).show();
return false;
}
Device_End_Point=usbinterface.getEndpoint(j);
Toast.makeText(Loginpage.this, ""+Device_End_Point, 50000).show();
tIn=tOut=Device_End_Point;
if(Device_End_Point==null)
{
Toast.makeText(Loginpage.this, "End Point Error ", 50000).show();
return false;
}
UsbDeviceConnection Device_Connection=null;
if(device_details!=null)
{
Device_Connection=manager.openDevice(device_detail s);
if (Device_Connection != null )
{
Toast.makeText(Loginpage.this, "Checking", Toast.LENGTH_LONG).show();
Device_Connection.controlTransfer(0x21, 34, 0, 0, null, 0, 0);
Device_Connection.controlTransfer(0x21, 32, 0, 0, new byte[] { (byte) 0x80, 0x25, 0x00, 0x00, 0x00, 0x00, 0x08 }, 7, 0);
byte []Communication_Byte=new byte[1];
Communication_Byte[0]='&';
selectedendpoint = listusbendpoint.getType();
Toast.makeText(Loginpage.this,""+selectedendpoint, Toast.LENGTH_LONG).show();
//usbDeviceConnection.bulkTransfer(tOut,Communicatio n_Byte, 1, 0);
}
if(Device_Connection==null)
{
Toast.makeText(Loginpage.this, "Unable to open device", 50000).show();
return false;
}
}
return true;
}
Thank you in advance
This is Lakshmansundeep. I am developing an application that sends the data android device to micro controller as vice versa via VIRTUAL COMM PORT using usb cable. I did my usb connection establishment successfully,coming to the communication part i.e. Communication from Android Device to micro controller and the application was crashed because of having single end point to the virtual comm port.please help me how to communicate to virtual comm port having single end point...please it was a little bit urgent.
Here is my Android Activity java code after my method called:
public boolean Check_Devices_Available()
{
int i,j;
boolean Device_Found;
String as[];
UsbEndpoint tOut = null;
UsbEndpoint tIn = null;
UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
i = deviceList.size();
if(i==0)
{
Toast.makeText(Loginpage.this,"No Devices Attached",Toast.LENGTH_LONG).show();
return false;
}
as = new String[i];
deviceList.keySet().toArray(as);
Device_Found=false;
for(j=0;j<i;j++)
{
device_details = (UsbDevice)deviceList.get(as[j]);
if((device_details.getVendorId()==targetVendorID) && (device_details.getProductId()==targetProductID))
{
Toast.makeText(Loginpage.this,"Device Connected",Toast.LENGTH_LONG).show();
Device_Found=true;
break;
}
}
if(Device_Found==false)
{
Toast.makeText(Loginpage.this,"No Devices Attached with Req Vendor ID",Toast.LENGTH_LONG).show();
return false;
}
if(manager.hasPermission(device_details)==true)
{
Toast.makeText(Loginpage.this, "Permission Granted", Toast.LENGTH_LONG).show();
// Device_Settings(Device_Detials,j);
}
else
{
//PendingIntent intent = null;
Toast.makeText(Loginpage.this, "No Permission", Toast.LENGTH_LONG).show();
manager.requestPermission(device_details, null);
}
UsbEndpoint Device_End_Point = null;
UsbInterface usbinterface = device_details.getInterface(j);
if (usbinterface == null)
{
Toast.makeText(Loginpage.this, "Device Found But UnKnown Exception-1", 50000).show();
return false;
}
Device_End_Point=usbinterface.getEndpoint(j);
Toast.makeText(Loginpage.this, ""+Device_End_Point, 50000).show();
tIn=tOut=Device_End_Point;
if(Device_End_Point==null)
{
Toast.makeText(Loginpage.this, "End Point Error ", 50000).show();
return false;
}
UsbDeviceConnection Device_Connection=null;
if(device_details!=null)
{
Device_Connection=manager.openDevice(device_detail s);
if (Device_Connection != null )
{
Toast.makeText(Loginpage.this, "Checking", Toast.LENGTH_LONG).show();
Device_Connection.controlTransfer(0x21, 34, 0, 0, null, 0, 0);
Device_Connection.controlTransfer(0x21, 32, 0, 0, new byte[] { (byte) 0x80, 0x25, 0x00, 0x00, 0x00, 0x00, 0x08 }, 7, 0);
byte []Communication_Byte=new byte[1];
Communication_Byte[0]='&';
selectedendpoint = listusbendpoint.getType();
Toast.makeText(Loginpage.this,""+selectedendpoint, Toast.LENGTH_LONG).show();
//usbDeviceConnection.bulkTransfer(tOut,Communicatio n_Byte, 1, 0);
}
if(Device_Connection==null)
{
Toast.makeText(Loginpage.this, "Unable to open device", 50000).show();
return false;
}
}
return true;
}
Thank you in advance
0 commentaires:
Enregistrer un commentaire