mirror of
				https://github.com/mik3y/usb-serial-for-android
				synced 2025-10-28 00:47:27 +00:00 
			
		
		
		
	
						commit
						fd8c155ca5
					
				| @ -227,7 +227,11 @@ public class TerminalFragment extends Fragment implements SerialInputOutputManag | ||||
| 
 | ||||
|         try { | ||||
|             usbSerialPort.open(usbConnection); | ||||
|             usbSerialPort.setParameters(baudRate, 8, 1, UsbSerialPort.PARITY_NONE); | ||||
|             try{ | ||||
|                 usbSerialPort.setParameters(baudRate, 8, 1, UsbSerialPort.PARITY_NONE); | ||||
|             }catch (UnsupportedOperationException e){ | ||||
|                 status("unsupport setparameters"); | ||||
|             } | ||||
|             if(withIoManager) { | ||||
|                 usbIoManager = new SerialInputOutputManager(usbSerialPort, this); | ||||
|                 usbIoManager.start(); | ||||
| @ -351,7 +355,7 @@ public class TerminalFragment extends Fragment implements SerialInputOutputManag | ||||
|                 cdBtn.setChecked(controlLines.contains(UsbSerialPort.ControlLine.CD)); | ||||
|                 riBtn.setChecked(controlLines.contains(UsbSerialPort.ControlLine.RI)); | ||||
|                 mainLooper.postDelayed(runnable, refreshInterval); | ||||
|             } catch (IOException e) { | ||||
|             } catch (Exception e) { | ||||
|                 status("getControlLines() failed: " + e.getMessage() + " -> stopped control line refresh"); | ||||
|             } | ||||
|         } | ||||
| @ -368,8 +372,15 @@ public class TerminalFragment extends Fragment implements SerialInputOutputManag | ||||
|                 if (!controlLines.contains(UsbSerialPort.ControlLine.CD))   cdBtn.setVisibility(View.INVISIBLE); | ||||
|                 if (!controlLines.contains(UsbSerialPort.ControlLine.RI))   riBtn.setVisibility(View.INVISIBLE); | ||||
|                 run(); | ||||
|             } catch (IOException e) { | ||||
|             } catch (Exception e) { | ||||
|                 Toast.makeText(getActivity(), "getSupportedControlLines() failed: " + e.getMessage(), Toast.LENGTH_SHORT).show(); | ||||
|                 rtsBtn.setVisibility(View.INVISIBLE); | ||||
|                 ctsBtn.setVisibility(View.INVISIBLE); | ||||
|                 dtrBtn.setVisibility(View.INVISIBLE); | ||||
|                 dsrBtn.setVisibility(View.INVISIBLE); | ||||
|                 cdBtn.setVisibility(View.INVISIBLE); | ||||
|                 cdBtn.setVisibility(View.INVISIBLE); | ||||
|                 riBtn.setVisibility(View.INVISIBLE); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|  | ||||
| @ -0,0 +1,111 @@ | ||||
| package com.hoho.android.usbserial.driver; | ||||
| 
 | ||||
| import android.hardware.usb.UsbConstants; | ||||
| import android.hardware.usb.UsbDevice; | ||||
| import android.hardware.usb.UsbEndpoint; | ||||
| import android.hardware.usb.UsbInterface; | ||||
| import android.util.Log; | ||||
| 
 | ||||
| import java.io.IOException; | ||||
| import java.util.Collections; | ||||
| import java.util.EnumSet; | ||||
| import java.util.LinkedHashMap; | ||||
| import java.util.List; | ||||
| import java.util.Map; | ||||
| 
 | ||||
| public class GsmModemSerialDriver implements UsbSerialDriver{ | ||||
| 
 | ||||
|     private final String TAG = GsmModemSerialDriver.class.getSimpleName(); | ||||
| 
 | ||||
|     private final UsbDevice mDevice; | ||||
|     private final UsbSerialPort mPort; | ||||
| 
 | ||||
|     @Override | ||||
|     public UsbDevice getDevice() { | ||||
|         return mDevice; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public List<UsbSerialPort> getPorts() { | ||||
|         return Collections.singletonList(mPort); | ||||
|     } | ||||
| 
 | ||||
|     public GsmModemSerialDriver(UsbDevice mDevice) { | ||||
|         this.mDevice = mDevice; | ||||
|         mPort = new GsmModemSerialPort(mDevice, 0); | ||||
|     } | ||||
| 
 | ||||
|     public class GsmModemSerialPort extends CommonUsbSerialPort { | ||||
| 
 | ||||
|         private UsbInterface mDataInterface; | ||||
| 
 | ||||
|         public GsmModemSerialPort(UsbDevice device, int portNumber) { | ||||
|             super(device, portNumber); | ||||
|         } | ||||
| 
 | ||||
|         @Override | ||||
|         protected void openInt() throws IOException { | ||||
|             Log.d(TAG, "claiming interfaces, count=" + mDevice.getInterfaceCount()); | ||||
|             mDataInterface = mDevice.getInterface(0); | ||||
|             if (!mConnection.claimInterface(mDataInterface, true)) { | ||||
|                 throw new IOException("Could not claim shared control/data interface"); | ||||
|             } | ||||
|             Log.d(TAG, "endpoint count=" + mDataInterface.getEndpointCount()); | ||||
|             for (int i = 0; i < mDataInterface.getEndpointCount(); ++i) { | ||||
|                 UsbEndpoint ep = mDataInterface.getEndpoint(i); | ||||
|                 if ((ep.getDirection() == UsbConstants.USB_DIR_IN) && (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK)) { | ||||
|                     mReadEndpoint = ep; | ||||
|                 } else if ((ep.getDirection() == UsbConstants.USB_DIR_OUT) && (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK)) { | ||||
|                     mWriteEndpoint = ep; | ||||
|                 } | ||||
|             } | ||||
|             initGsmModem(); | ||||
|         } | ||||
| 
 | ||||
|         @Override | ||||
|         protected void closeInt() { | ||||
|             try { | ||||
|                 mConnection.releaseInterface(mDataInterface); | ||||
|             } catch(Exception ignored) {} | ||||
| 
 | ||||
|         } | ||||
| 
 | ||||
|         private int initGsmModem() throws IOException { | ||||
|             int len = mConnection.controlTransfer( | ||||
|                     0x21, 0x22, 0x01, 0, null, 0, 5000); | ||||
|             if(len < 0) { | ||||
|                 throw new IOException("init failed"); | ||||
|             } | ||||
|             return len; | ||||
|         } | ||||
| 
 | ||||
|         @Override | ||||
|         public UsbSerialDriver getDriver() { | ||||
|             return GsmModemSerialDriver.this; | ||||
|         } | ||||
| 
 | ||||
|         @Override | ||||
|         public void setParameters(int baudRate, int dataBits, int stopBits, int parity) throws IOException { | ||||
|             throw new UnsupportedOperationException(); | ||||
|         } | ||||
| 
 | ||||
|         @Override | ||||
|         public EnumSet<ControlLine> getControlLines() throws IOException { | ||||
|             throw  new UnsupportedOperationException(); | ||||
|         } | ||||
| 
 | ||||
|         @Override | ||||
|         public EnumSet<ControlLine> getSupportedControlLines() throws IOException { | ||||
|             throw  new UnsupportedOperationException(); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     public static Map<Integer, int[]> getSupportedDevices() { | ||||
|         final Map<Integer, int[]> supportedDevices = new LinkedHashMap<>(); | ||||
|         supportedDevices.put(UsbId.VENDOR_UNISOC, new int[]{ | ||||
|                 UsbId.FIBOCOM_L610, | ||||
|                 UsbId.FIBOCOM_L612, | ||||
|         }); | ||||
|         return supportedDevices; | ||||
|     } | ||||
| } | ||||
| @ -41,6 +41,10 @@ public final class UsbId { | ||||
|     public static final int QINHENG_CH340 = 0x7523; | ||||
|     public static final int QINHENG_CH341A = 0x5523; | ||||
| 
 | ||||
|     public static final int VENDOR_UNISOC = 0x1782; | ||||
|     public static final int FIBOCOM_L610 = 0x4D10; | ||||
|     public static final int FIBOCOM_L612 = 0x4D12; | ||||
| 
 | ||||
| 
 | ||||
|     private UsbId() { | ||||
|         throw new IllegalAccessError("Non-instantiable class"); | ||||
|  | ||||
| @ -37,6 +37,7 @@ public class UsbSerialProber { | ||||
|         probeTable.addDriver(FtdiSerialDriver.class); | ||||
|         probeTable.addDriver(ProlificSerialDriver.class); | ||||
|         probeTable.addDriver(Ch34xSerialDriver.class); | ||||
|         probeTable.addDriver(GsmModemSerialDriver.class); | ||||
|         return probeTable; | ||||
|     } | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user