Browse Source

first commit

Devel 3 years ago
commit
fb1c928704

+ 1 - 0
.gitattributes

@@ -0,0 +1 @@
+*.pbxproj -text

+ 50 - 0
.gitignore

@@ -0,0 +1,50 @@
+
+# OSX
+#
+.DS_Store
+
+# node.js
+#
+node_modules/
+npm-debug.log
+yarn-error.log
+yarn.lock
+.npm/
+
+# Xcode
+#
+build/
+*.pbxuser
+!default.pbxuser
+*.mode1v3
+!default.mode1v3
+*.mode2v3
+!default.mode2v3
+*.perspectivev3
+!default.perspectivev3
+xcuserdata
+*.xccheckout
+*.moved-aside
+DerivedData
+*.hmap
+*.ipa
+*.xcuserstate
+project.xcworkspace
+      
+
+# Android/IntelliJ
+android/.classpath
+android/.project
+android/.settings
+#
+build/
+.idea
+.gradle
+local.properties
+*.iml
+
+# BUCK
+buck-out/
+\.buckd/
+*.keystore
+      

+ 21 - 0
LICENSE.md

@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2018 Melih YARIKKAYA
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.

+ 35 - 0
README.md

@@ -0,0 +1,35 @@
+
+# react-native-serialport
+
+#### This library is for usb serial port communication on android platform 
+
+### This module uses the [felHR85/UsbSerial](https://github.com/felHR85/UsbSerial) library
+
+### Documents
+1. [Download & Installation](https://github.com/melihyarikkaya/react-native-serialport/wiki/Download-&-Installation)  
+2. [Auto Connection](https://github.com/melihyarikkaya/react-native-serialport/wiki/Auto-Connection)  
+3. [Manual Connection](https://github.com/melihyarikkaya/react-native-serialport/wiki/Manual-Connection)  
+4. [Methods](https://github.com/melihyarikkaya/react-native-serialport/wiki/Methods)  
+5. [Error Descriptions](https://github.com/melihyarikkaya/react-native-serialport/wiki/Error-Descriptions)  
+
+### Use to write data to port
+```javascript
+ RNSerialport.writeString("HELLO");
+ RNSerialport.writeBase64("SEVMTE8=");
+ RNSerialport.writeHexString("48454C4C4F");
+```
+### DEFAULT DEFINITIONS
+| KEY                    | VALUE                                    |
+|------------------------|------------------------------------------|
+| RETURNED DATA TYPE     | INT ARRAY (Options: INTARRAY, HEXSTRING) |
+| BAUND RATE             | 9600                                     |
+| AUTO CONNECT BAUD RATE | 9600                                     |
+| PORT INTERFACE         | -1                                       |
+| DATA BIT               | 8                                        |
+| STOP BIT               | 1                                        |
+| PARITY                 | NONE                                     |
+| FLOW CONTROL           | OFF                                      |
+| DRIVER                 | AUTO                                     |
+
+### Java Package Name
+ _com.melihyarikkaya.rnserialport_

+ 38 - 0
android/build.gradle

@@ -0,0 +1,38 @@
+
+buildscript {
+    repositories {
+        google()
+        jcenter()
+    }
+
+    dependencies {
+        classpath 'com.android.tools.build:gradle:3.3.1'
+    }
+}
+
+apply plugin: 'com.android.library'
+
+android {
+    compileSdkVersion 28
+    buildToolsVersion "28.0.3"
+
+    defaultConfig {
+        minSdkVersion 16
+        targetSdkVersion 28
+        versionCode 1
+        versionName "1.0"
+    }
+    lintOptions {
+        abortOnError false
+    }
+}
+
+repositories {
+    mavenCentral()
+}
+
+dependencies {
+    implementation 'com.google.guava:guava:20.0'
+    implementation 'com.facebook.react:react-native:+'
+    implementation fileTree(dir: 'libs', include: ['usbserial-6.0.5-release.aar'])
+}

BIN
android/libs/usbserial-6.0.5-release.aar


+ 7 - 0
android/src/main/AndroidManifest.xml

@@ -0,0 +1,7 @@
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+          package="com.melihyarikkaya.rnserialport">
+    <uses-feature android:name="android.hardware.usb.host"
+        android:required="true"/>
+</manifest>
+  

+ 67 - 0
android/src/main/java/com/melihyarikkaya/rnserialport/Definitions.java

@@ -0,0 +1,67 @@
+package com.melihyarikkaya.rnserialport;
+
+/**
+ * Created by melih on 12.10.2018.
+ */
+
+public class Definitions {
+
+    ////////////////////////// Errors //////////////////////////
+
+    public static final int ERROR_DEVICE_NOT_FOUND                = 1;
+    public static final int ERROR_CONNECT_DEVICE_NAME_INVALID     = 2;
+    public static final int ERROR_CONNECT_BAUDRATE_EMPTY          = 3;
+    public static final int ERROR_CONNECTION_FAILED               = 4;
+    public static final int ERROR_COULD_NOT_OPEN_SERIALPORT       = 5;
+    public static final int ERROR_DISCONNECT_FAILED               = 6;
+    public static final int ERROR_SERIALPORT_ALREADY_CONNECTED    = 7;
+    public static final int ERROR_SERIALPORT_ALREADY_DISCONNECTED = 8;
+    public static final int ERROR_USB_SERVICE_NOT_STARTED         = 9;
+    public static final int ERROR_X_DEVICE_NOT_FOUND              = 10;
+    public static final int ERROR_USER_DID_NOT_ALLOW_TO_CONNECT   = 11;
+    public static final int ERROR_SERVICE_STOP_FAILED             = 12;
+    public static final int ERROR_THERE_IS_NO_CONNECTION          = 13;
+    public static final int ERROR_NOT_READED_DATA                 = 14;
+    public static final int ERROR_DRIVER_TYPE_NOT_FOUND           = 15;
+    public static final int ERROR_DEVICE_NOT_SUPPORTED            = 16;
+    public static final int ERROR_SERVICE_ALREADY_STARTED         = 17;
+    public static final int ERROR_SERVICE_ALREADY_STOPPED         = 18;
+
+
+    public static final String ERROR_DEVICE_NOT_FOUND_MESSAGE                   = "Device not found!";
+    public static final String ERROR_CONNECT_DEVICE_NAME_INVALID_MESSAGE        = "Device name cannot be invalid or empty!";
+    public static final String ERROR_CONNECT_BAUDRATE_EMPTY_MESSAGE             = "BaudRate cannot be invalid!";
+    public static final String ERROR_CONNECTION_FAILED_MESSAGE                  = "Connection Failed!";
+    public static final String ERROR_COULD_NOT_OPEN_SERIALPORT_MESSAGE          = "Could not open Serial Port!";
+    public static final String ERROR_DISCONNECT_FAILED_MESSAGE                  = "Disconnect Failed!";
+    public static final String ERROR_SERIALPORT_ALREADY_CONNECTED_MESSAGE       = "Serial Port is already connected";
+    public static final String ERROR_SERIALPORT_ALREADY_DISCONNECTED_MESSAGE    = "Serial Port is already disconnected";
+    public static final String ERROR_USB_SERVICE_NOT_STARTED_MESSAGE            = "Usb service not started. Please first start Usb service!";
+    public static final String ERROR_X_DEVICE_NOT_FOUND_MESSAGE                 = "No device with name ";
+    public static final String ERROR_USER_DID_NOT_ALLOW_TO_CONNECT_MESSAGE      = "User did not allow to connect";
+    public static final String ERROR_SERVICE_STOP_FAILED_MESSAGE                = "Service could not stopped. Please first close connection";
+    public static final String ERROR_THERE_IS_NO_CONNECTION_MESSAGE             = "There is no connection";
+    public static final String ERROR_NOT_READED_DATA_MESSAGE                    = "Error reading from port";
+    public static final String ERROR_DRIVER_TYPE_NOT_FOUND_MESSAGE              = "Driver type is not defined";
+    public static final String ERROR_DEVICE_NOT_SUPPORTED_MESSAGE               = "Device not supported";
+    public static final String ERROR_SERVICE_ALREADY_STARTED_MESSAGE            = "Usb service is already started";;
+    public static final String ERROR_SERVICE_ALREADY_STOPPED_MESSAGE            = "Usb service is already stopped";;
+    ///////////////////////////////////////////////////////////
+
+    public static final int RETURNED_DATA_TYPE_INTARRAY = 1;
+    public static final int RETURNED_DATA_TYPE_HEXSTRING = 2;
+
+    public final static String hexChars = "0123456789ABCDEF";
+    private final static char[] hexArray = hexChars.toCharArray();
+
+    public static String bytesToHex(byte[] bytes) {
+        char[] hexChars = new char[bytes.length * 2];
+        for ( int j = 0; j < bytes.length; j++ ) {
+            int v = bytes[j] & 0xFF;
+            hexChars[j * 2] = hexArray[v >>> 4];
+            hexChars[j * 2 + 1] = hexArray[v & 0x0F];
+        }
+        return new String(hexChars);
+    }
+
+}

+ 625 - 0
android/src/main/java/com/melihyarikkaya/rnserialport/RNSerialportModule.java

@@ -0,0 +1,625 @@
+package com.melihyarikkaya.rnserialport;
+
+import android.app.PendingIntent;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+
+import com.facebook.react.bridge.Callback;
+import com.facebook.react.bridge.Promise;
+import com.facebook.react.bridge.ReactApplicationContext;
+import com.facebook.react.bridge.ReactContextBaseJavaModule;
+import com.facebook.react.bridge.Arguments;
+import com.facebook.react.bridge.ReactMethod;
+import com.facebook.react.bridge.WritableArray;
+import com.facebook.react.bridge.WritableMap;
+import com.facebook.react.modules.core.DeviceEventManagerModule;
+import com.facebook.react.bridge.WritableNativeArray;
+
+import android.util.Base64;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import com.google.common.primitives.UnsignedBytes;
+
+import android.hardware.usb.UsbDevice;
+import android.hardware.usb.UsbDeviceConnection;
+import android.hardware.usb.UsbManager;
+
+import com.felhr.usbserial.UsbSerialDevice;
+import com.felhr.usbserial.UsbSerialInterface;
+
+public class RNSerialportModule extends ReactContextBaseJavaModule {
+
+  private final ReactApplicationContext reactContext;
+  public RNSerialportModule(ReactApplicationContext reactContext) {
+    super(reactContext);
+    this.reactContext = reactContext;
+    fillDriverList();
+  }
+
+  @Override
+  public String getName() {
+    return "RNSerialport";
+  }
+
+  private final String ACTION_USB_READY = "com.felhr.connectivityservices.USB_READY";
+  private final String ACTION_USB_ATTACHED = "android.hardware.usb.action.USB_DEVICE_ATTACHED";
+  private final String ACTION_USB_DETACHED = "android.hardware.usb.action.USB_DEVICE_DETACHED";
+  private final String ACTION_USB_NOT_SUPPORTED = "com.felhr.usbservice.USB_NOT_SUPPORTED";
+  private final String ACTION_NO_USB = "com.felhr.usbservice.NO_USB";
+  private final String ACTION_USB_PERMISSION_GRANTED = "com.felhr.usbservice.USB_PERMISSION_GRANTED";
+  private final String ACTION_USB_PERMISSION_NOT_GRANTED = "com.felhr.usbservice.USB_PERMISSION_NOT_GRANTED";
+  private final String ACTION_USB_DISCONNECTED = "com.felhr.usbservice.USB_DISCONNECTED";
+  private final String ACTION_USB_PERMISSION = "com.android.example.USB_PERMISSION";
+  private final String ACTION_USB_NOT_OPENED = "com.melihyarikkaya.rnserialport.USB_NOT_OPENED";
+  private final String ACTION_USB_CONNECT = "com.melihyarikkaya.rnserialport.USB_CONNECT";
+
+  //react-native events
+  private final String onErrorEvent              = "onError";
+  private final String onConnectedEvent          = "onConnected";
+  private final String onDisconnectedEvent       = "onDisconnected";
+  private final String onDeviceAttachedEvent     = "onDeviceAttached";
+  private final String onDeviceDetachedEvent     = "onDeviceDetached";
+  private final String onServiceStarted          = "onServiceStarted";
+  private final String onServiceStopped          = "onServiceStopped";
+  private final String onReadDataFromPort        = "onReadDataFromPort";
+  private final String onUsbPermissionGranted    = "onUsbPermissionGranted";
+
+  //SUPPORTED DRIVER LIST
+
+  private List<String> driverList;
+
+  private UsbManager usbManager;
+  private UsbDevice device;
+  private UsbDeviceConnection connection;
+  private UsbSerialDevice serialPort;
+  private boolean serialPortConnected;
+
+  //Connection Settings
+  private int DATA_BIT     = UsbSerialInterface.DATA_BITS_8;
+  private int STOP_BIT     = UsbSerialInterface.STOP_BITS_1;
+  private int PARITY       =  UsbSerialInterface.PARITY_NONE;
+  private int FLOW_CONTROL = UsbSerialInterface.FLOW_CONTROL_OFF;
+  private int BAUD_RATE = 9600;
+
+
+  private boolean autoConnect = false;
+  private String autoConnectDeviceName;
+  private int autoConnectBaudRate = 9600;
+  private int portInterface = -1;
+  private int returnedDataType = Definitions.RETURNED_DATA_TYPE_INTARRAY;
+  private String driver = "AUTO";
+
+
+  private boolean usbServiceStarted = false;
+
+  private final BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {
+    @Override
+    public void onReceive(Context arg0, Intent arg1) {
+      Intent intent;
+      switch (arg1.getAction()) {
+        case ACTION_USB_CONNECT:
+          eventEmit(onConnectedEvent, null);
+          break;
+        case ACTION_USB_DISCONNECTED:
+          eventEmit(onDisconnectedEvent, null);
+          break;
+        case ACTION_USB_NOT_SUPPORTED:
+          eventEmit(onErrorEvent, createError(Definitions.ERROR_DEVICE_NOT_SUPPORTED, Definitions.ERROR_DEVICE_NOT_SUPPORTED_MESSAGE));
+          break;
+        case ACTION_USB_NOT_OPENED:
+          eventEmit(onErrorEvent, createError(Definitions.ERROR_COULD_NOT_OPEN_SERIALPORT, Definitions.ERROR_COULD_NOT_OPEN_SERIALPORT_MESSAGE));
+          break;
+        case ACTION_USB_ATTACHED:
+          eventEmit(onDeviceAttachedEvent, null);
+          if(autoConnect && chooseFirstDevice()) {
+            connectDevice(autoConnectDeviceName, autoConnectBaudRate);
+          }
+          break;
+        case ACTION_USB_DETACHED:
+          eventEmit(onDeviceDetachedEvent, null);
+          if(serialPortConnected) {
+            stopConnection();
+          }
+          break;
+        case ACTION_USB_PERMISSION :
+          boolean granted = arg1.getExtras().getBoolean(UsbManager.EXTRA_PERMISSION_GRANTED);
+          startConnection(granted);
+          break;
+        case ACTION_USB_PERMISSION_GRANTED:
+          eventEmit(onUsbPermissionGranted, null);
+          break;
+        case ACTION_USB_PERMISSION_NOT_GRANTED:
+          eventEmit(onErrorEvent, createError(Definitions.ERROR_USER_DID_NOT_ALLOW_TO_CONNECT, Definitions.ERROR_USER_DID_NOT_ALLOW_TO_CONNECT_MESSAGE));
+          break;
+      }
+    }
+  };
+
+  private void eventEmit(String eventName, Object data) {
+    try {
+      if(reactContext.hasActiveCatalystInstance()) {
+        reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(eventName, data);
+      }
+    }
+    catch (Exception error) {}
+  }
+
+  private WritableMap createError(int code, String message) {
+    WritableMap err = Arguments.createMap();
+    err.putBoolean("status", false);
+    err.putInt("errorCode", code);
+    err.putString("errorMessage", message);
+
+    return err;
+  }
+
+  private void setFilters() {
+    IntentFilter filter = new IntentFilter();
+    filter.addAction(ACTION_USB_PERMISSION_GRANTED);
+    filter.addAction(ACTION_NO_USB);
+    filter.addAction(ACTION_USB_CONNECT);
+    filter.addAction(ACTION_USB_DISCONNECTED);
+    filter.addAction(ACTION_USB_NOT_SUPPORTED);
+    filter.addAction(ACTION_USB_PERMISSION_NOT_GRANTED);
+    filter.addAction(ACTION_USB_PERMISSION);
+    filter.addAction(ACTION_USB_ATTACHED);
+    filter.addAction(ACTION_USB_DETACHED);
+    reactContext.registerReceiver(mUsbReceiver, filter);
+  }
+
+  private void fillDriverList() {
+    driverList = new ArrayList<>();
+    driverList.add("ftdi");
+    driverList.add("cp210x");
+    driverList.add("pl2303");
+    driverList.add("ch34x");
+    driverList.add("cdc");
+  }
+
+  /******************************* BEGIN PUBLIC SETTER METHODS **********************************/
+
+  @ReactMethod
+  public void setDataBit(int DATA_BIT) {
+    this.DATA_BIT = DATA_BIT;
+  }
+  @ReactMethod
+  public void setStopBit(int STOP_BIT) {
+    this.STOP_BIT = STOP_BIT;
+  }
+  @ReactMethod
+  public void setParity(int PARITY) {
+    this.PARITY = PARITY;
+  }
+  @ReactMethod
+  public void setFlowControl(int FLOW_CONTROL) {
+    this.FLOW_CONTROL = FLOW_CONTROL;
+  }
+
+  @ReactMethod
+  public void loadDefaultConnectionSetting() {
+    DATA_BIT     = UsbSerialInterface.DATA_BITS_8;
+    STOP_BIT     = UsbSerialInterface.STOP_BITS_1;
+    PARITY       =  UsbSerialInterface.PARITY_NONE;
+    FLOW_CONTROL = UsbSerialInterface.FLOW_CONTROL_OFF;
+  }
+  @ReactMethod
+  public void setAutoConnect(boolean autoConnect) {
+    this.autoConnect = autoConnect;
+  }
+  @ReactMethod
+  public void setAutoConnectBaudRate(int baudRate) {
+    this.autoConnectBaudRate = baudRate;
+  }
+  @ReactMethod
+  public void setInterface(int iFace) {
+    this.portInterface = iFace;
+  }
+  @ReactMethod
+  public void setReturnedDataType(int type) {
+    if(type == Definitions.RETURNED_DATA_TYPE_HEXSTRING || type == Definitions.RETURNED_DATA_TYPE_INTARRAY) {
+      this.returnedDataType = type;
+    }
+  }
+
+  @ReactMethod
+  public void setDriver(String driver) {
+    if(driver.isEmpty() || !driverList.contains(driver.trim())) {
+      eventEmit(onErrorEvent, createError(Definitions.ERROR_DRIVER_TYPE_NOT_FOUND, Definitions.ERROR_DRIVER_TYPE_NOT_FOUND_MESSAGE));
+      return;
+    }
+
+    this.driver = driver;
+  }
+
+  /********************************************* END **********************************************/
+
+  @ReactMethod
+  public void startUsbService() {
+    if(usbServiceStarted) {
+      return;
+    }
+    setFilters();
+
+    usbManager = (UsbManager) reactContext.getSystemService(Context.USB_SERVICE);
+
+    usbServiceStarted = true;
+
+    //Return usb status when service is started.
+    WritableMap map = Arguments.createMap();
+
+    map.putBoolean("deviceAttached", !usbManager.getDeviceList().isEmpty());
+
+    eventEmit(onServiceStarted, map);
+
+    checkAutoConnect();
+  }
+
+  @ReactMethod
+  public void stopUsbService() {
+    if(serialPortConnected) {
+      eventEmit(onErrorEvent, createError(Definitions.ERROR_SERVICE_STOP_FAILED, Definitions.ERROR_SERVICE_STOP_FAILED_MESSAGE));
+      return;
+    }
+    if(!usbServiceStarted) {
+      return;
+    }
+    reactContext.unregisterReceiver(mUsbReceiver);
+    usbServiceStarted = false;
+    eventEmit(onServiceStopped, null);
+  }
+
+  @ReactMethod
+  public void getDeviceList(Promise promise) {
+    if(!usbServiceStarted) {
+      promise.reject(String.valueOf(Definitions.ERROR_USB_SERVICE_NOT_STARTED), Definitions.ERROR_USB_SERVICE_NOT_STARTED_MESSAGE);
+      return;
+    }
+
+    UsbManager manager = (UsbManager) reactContext.getSystemService(Context.USB_SERVICE);
+
+    HashMap<String, UsbDevice> devices = manager.getDeviceList();
+
+    if(devices.isEmpty()) {
+      //promise.reject(String.valueOf(Definitions.ERROR_DEVICE_NOT_FOUND), Definitions.ERROR_DEVICE_NOT_FOUND_MESSAGE);
+      promise.resolve(Arguments.createArray());
+      return;
+    }
+
+    WritableArray deviceList = Arguments.createArray();
+    for(Map.Entry<String, UsbDevice> entry: devices.entrySet()) {
+      UsbDevice d = entry.getValue();
+
+      WritableMap map = Arguments.createMap();
+      map.putString("name", d.getDeviceName());
+      map.putInt("vendorId", d.getVendorId());
+      map.putInt("productId", d.getProductId());
+
+      deviceList.pushMap(map);
+    }
+
+    promise.resolve(deviceList);
+  }
+
+  @ReactMethod
+  public void connectDevice(String deviceName, int baudRate) {
+    try {
+      if(!usbServiceStarted){
+        eventEmit(onErrorEvent, createError(Definitions.ERROR_USB_SERVICE_NOT_STARTED, Definitions.ERROR_USB_SERVICE_NOT_STARTED_MESSAGE));
+        return;
+      }
+
+      if(serialPortConnected) {
+        eventEmit(onErrorEvent, createError(Definitions.ERROR_SERIALPORT_ALREADY_CONNECTED, Definitions.ERROR_SERIALPORT_ALREADY_CONNECTED_MESSAGE));
+        return;
+      }
+
+      if(deviceName.isEmpty() || deviceName.length() < 0) {
+        eventEmit(onErrorEvent, createError(Definitions.ERROR_CONNECT_DEVICE_NAME_INVALID, Definitions.ERROR_CONNECT_DEVICE_NAME_INVALID_MESSAGE));
+        return;
+      }
+
+      if(baudRate < 1){
+        eventEmit(onErrorEvent, createError(Definitions.ERROR_CONNECT_BAUDRATE_EMPTY, Definitions.ERROR_CONNECT_BAUDRATE_EMPTY_MESSAGE));
+        return;
+      }
+
+      if(!autoConnect) {
+        this.BAUD_RATE = baudRate;
+      }
+
+      if(!chooseDevice(deviceName)) {
+        eventEmit(onErrorEvent, createError(Definitions.ERROR_X_DEVICE_NOT_FOUND, Definitions.ERROR_X_DEVICE_NOT_FOUND_MESSAGE + deviceName));
+        return;
+      }
+
+      requestUserPermission();
+
+    } catch (Exception err) {
+      eventEmit(onErrorEvent, createError(Definitions.ERROR_CONNECTION_FAILED, Definitions.ERROR_CONNECTION_FAILED_MESSAGE + " Catch Error Message:" + err.getMessage()));
+    }
+  }
+
+  @ReactMethod
+  public void disconnect() {
+    if(!usbServiceStarted){
+      eventEmit(onErrorEvent, createError(Definitions.ERROR_USB_SERVICE_NOT_STARTED, Definitions.ERROR_USB_SERVICE_NOT_STARTED_MESSAGE));
+      return;
+    }
+
+    if(!serialPortConnected) {
+      eventEmit(onErrorEvent, createError(Definitions.ERROR_SERIALPORT_ALREADY_DISCONNECTED, Definitions.ERROR_SERIALPORT_ALREADY_DISCONNECTED_MESSAGE));
+      return;
+    }
+    stopConnection();
+  }
+
+  @ReactMethod
+  public void isOpen(Promise promise) {
+    promise.resolve(serialPortConnected);
+  }
+
+ @ReactMethod
+ public void isServiceStarted(Promise promise) {
+    promise.resolve(usbServiceStarted);
+ }
+
+  @ReactMethod
+  public void isSupported(String deviceName, Promise promise) {
+    if(!chooseDevice(deviceName)) {
+      promise.reject(String.valueOf(Definitions.ERROR_DEVICE_NOT_FOUND), Definitions.ERROR_DEVICE_NOT_FOUND_MESSAGE);
+    } else {
+      promise.resolve(UsbSerialDevice.isSupported(device));
+    }
+  }
+
+  @ReactMethod
+  public void writeBytes(byte[] bytes) {
+    if(!usbServiceStarted){
+      eventEmit(onErrorEvent, createError(Definitions.ERROR_USB_SERVICE_NOT_STARTED, Definitions.ERROR_USB_SERVICE_NOT_STARTED_MESSAGE));
+      return;
+    }
+    if(!serialPortConnected || serialPort == null) {
+      eventEmit(onErrorEvent, createError(Definitions.ERROR_THERE_IS_NO_CONNECTION, Definitions.ERROR_THERE_IS_NO_CONNECTION_MESSAGE));
+      return;
+    }
+    serialPort.write(bytes);
+  }
+
+  @ReactMethod
+  public void writeString(String message) {
+    if(!usbServiceStarted){
+      eventEmit(onErrorEvent, createError(Definitions.ERROR_USB_SERVICE_NOT_STARTED, Definitions.ERROR_USB_SERVICE_NOT_STARTED_MESSAGE));
+      return;
+    }
+    if(!serialPortConnected || serialPort == null) {
+      eventEmit(onErrorEvent, createError(Definitions.ERROR_THERE_IS_NO_CONNECTION, Definitions.ERROR_THERE_IS_NO_CONNECTION_MESSAGE));
+      return;
+    }
+
+    serialPort.write(message.getBytes());
+  }
+
+  @ReactMethod
+  public void writeBase64(String message) {
+    if(!usbServiceStarted){
+      eventEmit(onErrorEvent, createError(Definitions.ERROR_USB_SERVICE_NOT_STARTED, Definitions.ERROR_USB_SERVICE_NOT_STARTED_MESSAGE));
+      return;
+    }
+    if(!serialPortConnected || serialPort == null) {
+      eventEmit(onErrorEvent, createError(Definitions.ERROR_THERE_IS_NO_CONNECTION, Definitions.ERROR_THERE_IS_NO_CONNECTION_MESSAGE));
+      return;
+    }
+
+    byte [] data = Base64.decode(message, Base64.DEFAULT);
+    serialPort.write(data);
+  }
+
+  @ReactMethod
+  public void writeHexString(String message) {
+    if(!usbServiceStarted){
+      eventEmit(onErrorEvent, createError(Definitions.ERROR_USB_SERVICE_NOT_STARTED, Definitions.ERROR_USB_SERVICE_NOT_STARTED_MESSAGE));
+      return;
+    }
+    if(!serialPortConnected || serialPort == null) {
+      eventEmit(onErrorEvent, createError(Definitions.ERROR_THERE_IS_NO_CONNECTION, Definitions.ERROR_THERE_IS_NO_CONNECTION_MESSAGE));
+      return;
+    }
+
+    if(message.length() < 1) {
+      return;
+    }
+
+    byte[] data = new byte[message.length() / 2];
+    for (int i = 0; i < data.length; i++) {
+      int index = i * 2;
+
+      String hex = message.substring(index, index + 2);
+
+      if(Definitions.hexChars.indexOf(hex.substring(0, 1)) == -1 || Definitions.hexChars.indexOf(hex.substring(1, 1)) == -1) {
+          return;
+      }
+
+      int v = Integer.parseInt(hex, 16);
+      data[i] = (byte) v;
+    }
+    serialPort.write(data);
+  }
+
+  ///////////////////////////////////////////////USB SERVICE /////////////////////////////////////////////////////////
+  ///////////////////////////////////////////////USB SERVICE /////////////////////////////////////////////////////////
+
+  private boolean chooseDevice(String deviceName) {
+    HashMap<String, UsbDevice> usbDevices = usbManager.getDeviceList();
+    if(usbDevices.isEmpty()) {
+      return false;
+    }
+
+    boolean selected = false;
+
+    for (Map.Entry<String, UsbDevice> entry: usbDevices.entrySet()) {
+      UsbDevice d = entry.getValue();
+
+      if(d.getDeviceName().equals(deviceName)) {
+        device = d;
+        selected = true;
+        break;
+      }
+    }
+
+    return selected;
+  }
+
+  private boolean chooseFirstDevice() {
+    HashMap<String, UsbDevice> usbDevices = usbManager.getDeviceList();
+    if(usbDevices.isEmpty()) {
+      return false;
+    }
+
+    boolean selected = false;
+
+    for (Map.Entry<String, UsbDevice> entry: usbDevices.entrySet()) {
+      UsbDevice d = entry.getValue();
+
+      int deviceVID = d.getVendorId();
+      int devicePID = d.getProductId();
+
+      if (deviceVID != 0x1d6b && (devicePID != 0x0001 && devicePID != 0x0002 && devicePID != 0x0003) && deviceVID != 0x5c6 && devicePID != 0x904c)
+      {
+        device = d;
+        autoConnectDeviceName = d.getDeviceName();
+        selected = true;
+        break;
+      }
+    }
+    return selected;
+  }
+
+  private void checkAutoConnect() {
+    if(!autoConnect || serialPortConnected)
+      return;
+
+    if(chooseFirstDevice()) {
+      connectDevice(autoConnectDeviceName, autoConnectBaudRate);
+    }
+  }
+  private class ConnectionThread extends Thread {
+    @Override
+    public void run() {
+      try {
+        if(driver.equals("AUTO")) {
+          serialPort = UsbSerialDevice.createUsbSerialDevice(device, connection, portInterface);
+        } else {
+          serialPort = UsbSerialDevice.createUsbSerialDevice(driver, device, connection, portInterface);
+        }
+        if(serialPort == null) {
+          // No driver for given device
+          Intent intent = new Intent(ACTION_USB_NOT_SUPPORTED);
+          reactContext.sendBroadcast(intent);
+          return;
+        }
+
+        if(!serialPort.open()){
+          Intent intent = new Intent(ACTION_USB_NOT_OPENED);
+          reactContext.sendBroadcast(intent);
+          return;
+        }
+
+        serialPortConnected = true;
+        int baud;
+        if(autoConnect){
+          baud = autoConnectBaudRate;
+        }else {
+          baud = BAUD_RATE;
+        }
+        serialPort.setBaudRate(baud);
+        serialPort.setDataBits(DATA_BIT);
+        serialPort.setStopBits(STOP_BIT);
+        serialPort.setParity(PARITY);
+        serialPort.setFlowControl(FLOW_CONTROL);
+        serialPort.read(mCallback);
+
+        Intent intent = new Intent(ACTION_USB_READY);
+        reactContext.sendBroadcast(intent);
+        intent = new Intent(ACTION_USB_CONNECT);
+        reactContext.sendBroadcast(intent);
+      } catch (Exception error) {
+        WritableMap map = createError(Definitions.ERROR_CONNECTION_FAILED, Definitions.ERROR_CONNECTION_FAILED_MESSAGE);
+        map.putString("exceptionErrorMessage", error.getMessage());
+        eventEmit(onErrorEvent, map);
+      }
+    }
+  }
+
+  private void requestUserPermission() {
+    if(device == null)
+      return;
+    PendingIntent mPendingIntent = PendingIntent.getBroadcast(reactContext, 0 , new Intent(ACTION_USB_PERMISSION), 0);
+    usbManager.requestPermission(device, mPendingIntent);
+  }
+
+  private void startConnection(boolean granted) {
+    if(granted) {
+      Intent intent = new Intent(ACTION_USB_PERMISSION_GRANTED);
+      reactContext.sendBroadcast(intent);
+      connection = usbManager.openDevice(device);
+      new ConnectionThread().start();
+    } else {
+      connection = null;
+      device = null;
+      Intent intent = new Intent(ACTION_USB_PERMISSION_NOT_GRANTED);
+      reactContext.sendBroadcast(intent);
+    }
+  }
+
+  private void stopConnection() {
+    if (serialPortConnected) {
+      serialPort.close();
+      connection = null;
+      device = null;
+      Intent intent = new Intent(ACTION_USB_DISCONNECTED);
+      reactContext.sendBroadcast(intent);
+      serialPortConnected = false;
+    } else {
+      Intent intent = new Intent(ACTION_USB_DETACHED);
+      reactContext.sendBroadcast(intent);
+    }
+  }
+
+  private UsbSerialInterface.UsbReadCallback mCallback = new UsbSerialInterface.UsbReadCallback() {
+    @Override
+    public void onReceivedData(byte[] bytes) {
+      try {
+
+        String payloadKey = "payload";
+
+        WritableMap params = Arguments.createMap();
+
+        if(returnedDataType == Definitions.RETURNED_DATA_TYPE_INTARRAY) {
+
+          WritableArray intArray = new WritableNativeArray();
+          for(byte b: bytes) {
+            intArray.pushInt(UnsignedBytes.toInt(b));
+          }
+          params.putArray(payloadKey, intArray);
+
+        } else if(returnedDataType == Definitions.RETURNED_DATA_TYPE_HEXSTRING) {
+          String hexString = Definitions.bytesToHex(bytes);
+          params.putString(payloadKey, hexString);
+        } else
+          return;
+
+        eventEmit(onReadDataFromPort, params);
+
+      } catch (Exception err) {
+        eventEmit(onErrorEvent, createError(Definitions.ERROR_NOT_READED_DATA, Definitions.ERROR_NOT_READED_DATA_MESSAGE + " System Message: " + err.getMessage()));
+      }
+    }
+  };
+}

+ 28 - 0
android/src/main/java/com/melihyarikkaya/rnserialport/RNSerialportPackage.java

@@ -0,0 +1,28 @@
+
+package com.melihyarikkaya.rnserialport;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import com.facebook.react.ReactPackage;
+import com.facebook.react.bridge.NativeModule;
+import com.facebook.react.bridge.ReactApplicationContext;
+import com.facebook.react.uimanager.ViewManager;
+import com.facebook.react.bridge.JavaScriptModule;
+public class RNSerialportPackage implements ReactPackage {
+    @Override
+    public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
+      return Arrays.<NativeModule>asList(new RNSerialportModule(reactContext));
+    }
+
+    // Deprecated from RN 0.47
+    public List<Class<? extends JavaScriptModule>> createJSModules() {
+      return Collections.emptyList();
+    }
+
+    @Override
+    public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
+      return Collections.emptyList();
+    }
+}

+ 177 - 0
doc-wiki/Auto-Connection.md

@@ -0,0 +1,177 @@
+### Should be see for open the connection when the service is started or the usb device is attached.
+
+**Import Library and Requirements**
+
+```javascript
+import { RNSerialport, definitions, actions } from "react-native-serialport";
+import { DeviceEventEmitter } from "react-native";
+```
+
+**Set Your Callback Methods**
+
+```javascript
+componentDidMount() {
+  DeviceEventEmitter.addListener(
+    actions.ON_SERVICE_STARTED,
+    this.onServiceStarted,
+    this
+  );
+  DeviceEventEmitter.addListener(
+    actions.ON_SERVICE_STOPPED,
+    this.onServiceStopped,
+    this
+  );
+  DeviceEventEmitter.addListener(
+    actions.ON_DEVICE_ATTACHED,
+    this.onDeviceAttached,
+    this
+  );
+  DeviceEventEmitter.addListener(
+    actions.ON_DEVICE_DETACHED,
+    this.onDeviceDetached,
+    this
+  );
+  DeviceEventEmitter.addListener(actions.ON_ERROR, this.onError, this);
+  DeviceEventEmitter.addListener(actions.ON_CONNECTED, this.onConnected, this);
+  DeviceEventEmitter.addListener(
+    actions.ON_DISCONNECTED,
+    this.onDisconnected,
+    this
+  );
+  DeviceEventEmitter.addListener(actions.ON_READ_DATA, this.onReadData, this);
+}
+```
+
+**Set Serialport Settings**
+
+```javascript
+componentDidMount() {
+  //.
+  // Set Your Callback Methods in here
+  //.
+  RNSerialport.setReturnedDataType(definitions.RETURNED_DATA_TYPES.HEXSTRING);
+  RNSerialport.setAutoConnect(true);
+  RNSerialport.setAutoConnectBaudRate(9600);
+  RNSerialport.startUsbService();
+  //Started usb listener
+}
+```
+**Some precautions**
+
+```javascript
+componentWillUnmount = async() => {
+  DeviceEventEmitter.removeAllListeners();
+  const isOpen = await RNSerialport.isOpen();
+  if (isOpen) {
+    Alert.alert("isOpen", isOpen);
+    RNSerialport.disconnect();
+  }
+  RNSerialport.stopUsbService();
+}
+```
+
+_Installation Successfuly_
+
+[See for methods](https://github.com/melihyarikkaya/react-native-serialport/wiki/Methods)
+
+### Full Example
+
+```javascript
+import { DeviceEventEmitter } from "react-native";
+import { 
+  RNSerialport,
+  definitions,
+  actions 
+} from "react-native-serialport";
+
+export default class App extends Component<Props> {
+
+  componentDidMount() {
+    DeviceEventEmitter.addListener(
+      actions.ON_SERVICE_STARTED,
+      this.onServiceStarted,
+      this
+    );
+    DeviceEventEmitter.addListener(
+      actions.ON_SERVICE_STOPPED,
+      this.onServiceStopped,
+      this
+    );
+    DeviceEventEmitter.addListener(
+      actions.ON_DEVICE_ATTACHED,
+      this.onDeviceAttached,
+      this
+    );
+    DeviceEventEmitter.addListener(
+      actions.ON_DEVICE_DETACHED,
+      this.onDeviceDetached,
+      this
+    );
+    DeviceEventEmitter.addListener(
+      actions.ON_ERROR,
+      this.onError,
+      this
+    );
+    DeviceEventEmitter.addListener(
+      actions.ON_CONNECTED,
+      this.onConnected,
+      this
+    );
+    DeviceEventEmitter.addListener(
+      actions.ON_DISCONNECTED,
+      this.onDisconnected,
+      this
+    );
+    DeviceEventEmitter.addListener(
+      actions.ON_READ_DATA,
+      this.onReadData,
+      this
+    );
+    RNSerialport.setInterface(-1); //default -1
+    RNSerialport.setReturnedDataType(definitions.RETURNED_DATA_TYPES.HEXSTRING); //default INTARRAY
+    RNSerialport.setAutoConnectBaudRate(9600)
+    RNSerialport.setAutoConnect(true) // must be true for auto connect
+    RNSerialport.startUsbService(); //start usb listener
+  }
+
+  componentWillUnmount = async() => {
+    DeviceEventEmitter.removeAllListeners();
+    RNSerialport.isOpen(isOpen => {
+      if(isOpen) {
+        RNSerialport.disconnect();
+        RNSerialport.stopUsbService();
+      } else {
+        RNSerialport.stopUsbService();
+      }
+    });
+  }
+
+  /* BEGIN Listener Methods */
+
+  onDeviceAttached() { console.log("Device Attached"); }
+
+  onDeviceDetached() { console.log("Device Detached") }
+
+  onError(error) { console.log("Code: " + error.errorCode + " Message: " + error.errorMessage)}
+
+  onConnected() { console.log("Connected") }
+
+  onDisconnected() { console.log("Disconnected") }
+
+  onServiceStarted(response) {
+    //returns usb status when service started
+    if(response.deviceAttached) { 
+      this.onDeviceAttached();
+    }
+  }
+
+  onServiceStopped() { console.log("Service stopped") }
+
+  onReadData(data) {
+   console.log(data.payload)
+  }
+
+  /* END Listener Methods */
+
+}
+```

+ 20 - 0
doc-wiki/Errors.md

@@ -0,0 +1,20 @@
+### Error Descriptions
+| CODE |                            MESSAGE                           |
+|:----:|:------------------------------------------------------------:|
+|   1  | Device not found!                                            |
+|   2  | Device name cannot be invalid or empty!                      |
+|   3  | BaudRate cannot be invalid!                                  |
+|   4  | Connection Failed!                                           |
+|   5  | Could not open Serial Port!                                  |
+|   6  | Disconnect Failed!                                           |
+|   7  | Serial Port is already connected                             |
+|   8  | Serial Port is already disconnected                          |
+|   9  | Usb service not started. Please first start Usb service!     |
+|  10  | No device with name {Device name}                            |
+|  11  | User did not allow to connect                                |
+|  12  | Service could not stopped off. Please close connection first |
+|  13  | There is no connection                                       |
+|  14  | Error reading from port                                      |
+|  15  | Driver type is not defined                                   |
+|  16  | Device not supported                                         |
+

+ 497 - 0
doc-wiki/Manual-Connection.md

@@ -0,0 +1,497 @@
+**Import Library and Requirements**
+
+```javascript
+import { RNSerialport, definitions, actions } from "react-native-serialport";
+import { DeviceEventEmitter } from "react-native";
+```
+
+**Set Your Callback Methods**
+
+```javascript
+componentDidMount() {
+  DeviceEventEmitter.addListener(
+    actions.ON_SERVICE_STARTED,
+    this.onServiceStarted,
+    this
+  );
+  DeviceEventEmitter.addListener(
+    actions.ON_SERVICE_STOPPED,
+    this.onServiceStopped,
+    this
+  );
+  DeviceEventEmitter.addListener(
+    actions.ON_DEVICE_ATTACHED,
+    this.onDeviceAttached,
+    this
+  );
+  DeviceEventEmitter.addListener(
+    actions.ON_DEVICE_DETACHED,
+    this.onDeviceDetached,
+    this
+  );
+  DeviceEventEmitter.addListener(actions.ON_ERROR, this.onError, this);
+  DeviceEventEmitter.addListener(actions.ON_CONNECTED, this.onConnected, this);
+  DeviceEventEmitter.addListener(
+    actions.ON_DISCONNECTED,
+    this.onDisconnected,
+    this
+  );
+  DeviceEventEmitter.addListener(actions.ON_READ_DATA, this.onReadData, this);
+}
+```
+
+**Set Serialport Settings**
+
+```javascript
+componentDidMount() {
+  //.
+  // Set Your Callback Methods in here
+  //.
+  RNSerialport.setReturnedDataType(definitions.RETURNED_DATA_TYPES.HEXSTRING);
+  RNSerialport.setAutoConnect(false);
+  RNSerialport.startUsbService();
+  //Started usb listener
+}
+```
+
+**Some precautions**
+
+```javascript
+componentWillUnmount = async () => {
+  DeviceEventEmitter.removeAllListeners();
+  const isOpen = await RNSerialport.isOpen();
+  if (isOpen) {
+    Alert.alert("isOpen", isOpen);
+    RNSerialport.disconnect();
+  }
+  RNSerialport.stopUsbService();
+};
+```
+
+_Installation Successfuly_
+
+[See for methods](https://github.com/melihyarikkaya/react-native-serialport/wiki/Methods)
+
+### Full Example
+
+```javascript
+/**
+ * Sample React Native App
+ * https://github.com/facebook/react-native
+ *
+ * @format
+ * @flow
+ */
+
+import React, { Component } from "react";
+import {
+  StyleSheet,
+  Text,
+  View,
+  TextInput,
+  Picker,
+  TouchableOpacity,
+  ScrollView,
+  Alert,
+  DeviceEventEmitter
+} from "react-native";
+import { RNSerialport, definitions, actions } from "react-native-serialport";
+//type Props = {};
+class ManualConnection extends Component {
+  constructor(props) {
+    super(props);
+
+    this.state = {
+      servisStarted: false,
+      connected: false,
+      usbAttached: false,
+      output: "",
+      outputArray: [],
+      baudRate: "115200",
+      interface: "-1",
+      selectedDevice: null,
+      deviceList: [{ name: "Device Not Found", placeholder: true }],
+      sendText: "HELLO",
+      returnedDataType: definitions.RETURNED_DATA_TYPES.HEXSTRING
+    };
+
+    this.startUsbListener = this.startUsbListener.bind(this);
+    this.stopUsbListener = this.stopUsbListener.bind(this);
+  }
+
+  componentDidMount() {
+    this.startUsbListener();
+  }
+
+  componentWillUnmount() {
+    this.stopUsbListener();
+  }
+
+  startUsbListener() {
+    DeviceEventEmitter.addListener(
+      actions.ON_SERVICE_STARTED,
+      this.onServiceStarted,
+      this
+    );
+    DeviceEventEmitter.addListener(
+      actions.ON_SERVICE_STOPPED,
+      this.onServiceStopped,
+      this
+    );
+    DeviceEventEmitter.addListener(
+      actions.ON_DEVICE_ATTACHED,
+      this.onDeviceAttached,
+      this
+    );
+    DeviceEventEmitter.addListener(
+      actions.ON_DEVICE_DETACHED,
+      this.onDeviceDetached,
+      this
+    );
+    DeviceEventEmitter.addListener(actions.ON_ERROR, this.onError, this);
+    DeviceEventEmitter.addListener(
+      actions.ON_CONNECTED,
+      this.onConnected,
+      this
+    );
+    DeviceEventEmitter.addListener(
+      actions.ON_DISCONNECTED,
+      this.onDisconnected,
+      this
+    );
+    DeviceEventEmitter.addListener(actions.ON_READ_DATA, this.onReadData, this);
+    RNSerialport.setReturnedDataType(this.state.returnedDataType);
+    RNSerialport.setAutoConnect(false);
+    RNSerialport.startUsbService();
+  }
+
+  stopUsbListener = async () => {
+    DeviceEventEmitter.removeAllListeners();
+    const isOpen = await RNSerialport.isOpen();
+    if (isOpen) {
+      Alert.alert("isOpen", isOpen);
+      RNSerialport.disconnect();
+    }
+    RNSerialport.stopUsbService();
+  };
+
+  onServiceStarted(response) {
+    this.setState({ servisStarted: true });
+    if (response.deviceAttached) {
+      this.onDeviceAttached();
+    }
+  }
+  onServiceStopped() {
+    this.setState({ servisStarted: false });
+    Alert.alert("service stopped");
+  }
+  onDeviceAttached() {
+    this.setState({ usbAttached: true });
+    this.fillDeviceList();
+  }
+  onDeviceDetached() {
+    this.setState({ usbAttached: false });
+    this.setState({ selectedDevice: null });
+    this.setState({
+      deviceList: [{ name: "Device Not Found", placeholder: true }]
+    });
+  }
+  onConnected() {
+    this.setState({ connected: true });
+  }
+  onDisconnected() {
+    this.setState({ connected: false });
+  }
+  onReadData(data) {
+    if (
+      this.state.returnedDataType === definitions.RETURNED_DATA_TYPES.INTARRAY
+    ) {
+      const payload = RNSerialport.intArrayToUtf16(data.payload);
+      this.setState({ output: this.state.output + payload });
+    } else if (
+      this.state.returnedDataType === definitions.RETURNED_DATA_TYPES.HEXSTRING
+    ) {
+      const payload = RNSerialport.hexToUtf16(data.payload);
+      this.setState({ output: this.state.output + payload });
+    }
+  }
+
+  onError(error) {
+    console.error(error);
+  }
+
+  handleConvertButton() {
+    let data = "";
+    if (
+      this.state.returnedDataType === definitions.RETURNED_DATA_TYPES.HEXSTRING
+    ) {
+      data = RNSerialport.hexToUtf16(this.state.output);
+    } else if (
+      this.state.returnedDataType === definitions.RETURNED_DATA_TYPES.INTARRAY
+    ) {
+      data = RNSerialport.intArrayToUtf16(this.state.outputArray);
+    } else {
+      return;
+    }
+    this.setState({ output: data });
+  }
+  fillDeviceList = async () => {
+    try {
+      const deviceList = await RNSerialport.getDeviceList();
+      if (deviceList.length > 0) {
+        this.setState({ deviceList });
+      } else {
+        this.setState({
+          deviceList: [{ name: "Device Not Found", placeholder: true }]
+        });
+      }
+    } catch (err) {
+      Alert.alert(
+        "Error from getDeviceList()",
+        err.errorCode + " " + err.errorMessage
+      );
+    }
+  };
+  devicePickerItems() {
+    return this.state.deviceList.map((device, index) =>
+      !device.placeholder ? (
+        <Picker.Item key={index} label={device.name} value={device} />
+      ) : (
+        <Picker.Item key={index} label={device.name} value={null} />
+      )
+    );
+  }
+
+  handleSendButton() {
+    RNSerialport.writeString(this.state.sendText);
+  }
+  handleClearButton() {
+    this.setState({ output: "" });
+    this.setState({ outputArray: [] });
+  }
+
+  checkSupport() {
+    if (
+      this.state.selectedDevice.name === undefined ||
+      this.state.selectedDevice === null
+    )
+      return;
+    RNSerialport.isSupported(this.state.selectedDevice.name)
+      .then(status => {
+        alert(status ? "Supported" : "Not Supported");
+      })
+      .catch(error => {
+        alert(JSON.stringify(error));
+      });
+  }
+
+  handleConnectButton = async () => {
+    const isOpen = await RNSerialport.isOpen();
+    if (isOpen) {
+      RNSerialport.disconnect();
+    } else {
+      if (!this.state.selectedDevice) {
+        alert("Please choose device");
+        return;
+      }
+      RNSerialport.setInterface(parseInt(this.state.interface, 10));
+      RNSerialport.connectDevice(
+        this.state.selectedDevice.name,
+        parseInt(this.state.baudRate, 10)
+      );
+    }
+  };
+
+  buttonStyle = status => {
+    return status
+      ? styles.button
+      : Object.assign({}, styles.button, { backgroundColor: "#C0C0C0" });
+  };
+
+  render() {
+    return (
+      <ScrollView style={styles.body}>
+        <View style={styles.container}>
+          <View style={styles.header}>
+            <View style={styles.line}>
+              <Text style={styles.title}>Service:</Text>
+              <Text style={styles.value}>
+                {this.state.servisStarted ? "Started" : "Not Started"}
+              </Text>
+            </View>
+            <View style={styles.line}>
+              <Text style={styles.title}>Usb:</Text>
+              <Text style={styles.value}>
+                {this.state.usbAttached ? "Attached" : "Not Attached"}
+              </Text>
+            </View>
+            <View style={styles.line}>
+              <Text style={styles.title}>Connection:</Text>
+              <Text style={styles.value}>
+                {this.state.connected ? "Connected" : "Not Connected"}
+              </Text>
+            </View>
+          </View>
+          <ScrollView style={styles.output} nestedScrollEnabled={true}>
+            <Text style={styles.full}>
+              {this.state.output === "" ? "No Content" : this.state.output}
+            </Text>
+          </ScrollView>
+
+          <View style={styles.inputContainer}>
+            <Text>Send</Text>
+            <TextInput
+              style={styles.textInput}
+              onChangeText={text => this.setState({ sendText: text })}
+              value={this.state.sendText}
+              placeholder={"Send Text"}
+            />
+          </View>
+          <View style={styles.line2}>
+            <TouchableOpacity
+              style={this.buttonStyle(this.state.connected)}
+              onPress={() => this.handleSendButton()}
+              disabled={!this.state.connected}
+            >
+              <Text style={styles.buttonText}>Send</Text>
+            </TouchableOpacity>
+            <TouchableOpacity
+              style={styles.button}
+              onPress={() => this.handleClearButton()}
+            >
+              <Text style={styles.buttonText}>Clear</Text>
+            </TouchableOpacity>
+            <TouchableOpacity
+              style={styles.button}
+              onPress={() => this.handleConvertButton()}
+            >
+              <Text style={styles.buttonText}>Convert</Text>
+            </TouchableOpacity>
+          </View>
+
+          <View style={styles.line2}>
+            <View style={styles.inputContainer}>
+              <Text>Baud Rate</Text>
+              <TextInput
+                style={styles.textInput}
+                onChangeText={text => this.setState({ baudRate: text })}
+                value={this.state.baudRate}
+                placeholder={"Baud Rate"}
+              />
+            </View>
+            <View style={styles.inputContainer}>
+              <Text>Interface</Text>
+              <TextInput
+                style={styles.textInput}
+                onChangeText={text => this.setState({ interface: text })}
+                value={this.state.interface}
+                placeholder={"Interface"}
+              />
+            </View>
+          </View>
+          <View style={styles.inputContainer}>
+            <Text>Device List</Text>
+            <Picker
+              enabled={
+                this.state.deviceList.length > 0 &&
+                !this.state.deviceList[0].placeholder
+              }
+              selectedValue={this.state.selectedDevice}
+              onValueChange={(value, index) =>
+                this.setState({ selectedDevice: value })
+              }
+            >
+              {this.devicePickerItems()}
+            </Picker>
+          </View>
+          <TouchableOpacity
+            style={this.buttonStyle(this.state.selectedDevice)}
+            disabled={!this.state.selectedDevice}
+            onPress={() => this.handleConnectButton()}
+          >
+            <Text style={styles.buttonText}>
+              {this.state.connected ? "Disconnect" : "Connect"}
+            </Text>
+          </TouchableOpacity>
+          <TouchableOpacity
+            style={this.buttonStyle(this.state.selectedDevice)}
+            disabled={!this.state.selectedDevice}
+            onPress={() => {
+              this.checkSupport();
+            }}
+          >
+            <Text style={styles.buttonText}>Check Support</Text>
+          </TouchableOpacity>
+        </View>
+      </ScrollView>
+    );
+  }
+}
+
+const styles = StyleSheet.create({
+  full: {
+    flex: 1
+  },
+  body: {
+    flex: 1
+  },
+  container: {
+    flex: 1,
+    marginTop: 20,
+    marginLeft: 16,
+    marginRight: 16
+  },
+  header: {
+    display: "flex",
+    justifyContent: "center"
+    //alignItems: "center"
+  },
+  line: {
+    display: "flex",
+    flexDirection: "row"
+  },
+  line2: {
+    display: "flex",
+    flexDirection: "row",
+    justifyContent: "space-between"
+  },
+  title: {
+    width: 100
+  },
+  value: {
+    marginLeft: 20
+  },
+  output: {
+    marginTop: 10,
+    height: 300,
+    padding: 10,
+    backgroundColor: "#FFFFFF",
+    borderWidth: 1
+  },
+  inputContainer: {
+    marginTop: 10,
+    borderBottomWidth: 2
+  },
+  textInput: {
+    paddingLeft: 10,
+    paddingRight: 10,
+    height: 40
+  },
+  button: {
+    marginTop: 16,
+    marginBottom: 16,
+    paddingLeft: 15,
+    paddingRight: 15,
+    height: 40,
+    justifyContent: "center",
+    alignItems: "center",
+    backgroundColor: "#147efb",
+    borderRadius: 3
+  },
+  buttonText: {
+    color: "#FFFFFF"
+  }
+});
+
+export default ManualConnection;
+```

+ 448 - 0
doc-wiki/Methods.md

@@ -0,0 +1,448 @@
+[startUsbService](https://github.com/melihyarikkaya/react-native-serialport/wiki/Methods/#startUsbService)  
+[stopUsbService](https://github.com/melihyarikkaya/react-native-serialport/wiki/Methods/#stopUsbService)  
+[getDeviceList](https://github.com/melihyarikkaya/react-native-serialport/wiki/Methods/#getDeviceList)  
+[connectDevice](https://github.com/melihyarikkaya/react-native-serialport/wiki/Methods/#connectDevice)  
+[disconnect](https://github.com/melihyarikkaya/react-native-serialport/wiki/Methods/#disconnect)  
+[isOpen](https://github.com/melihyarikkaya/react-native-serialport/wiki/Methods/#isOpen)  
+[isSupported](https://github.com/melihyarikkaya/react-native-serialport/wiki/Methods/#isSupported)  
+[isServiceStarted](https://github.com/melihyarikkaya/react-native-serialport/wiki/Methods/#isServiceStarted)  
+[writeString](https://github.com/melihyarikkaya/react-native-serialport/wiki/Methods/#writeString)  
+[writeBase64](https://github.com/melihyarikkaya/react-native-serialport/wiki/Methods/#writeBase64)  
+[writeHexString](https://github.com/melihyarikkaya/react-native-serialport/wiki/Methods/#writeHexString)
+
+#### Setter Methods
+
+[setReturnedDataType](https://github.com/melihyarikkaya/react-native-serialport/wiki/Methods/#setReturnedDataType)  
+[setDriver](https://github.com/melihyarikkaya/react-native-serialport/wiki/Methods/#setDriver)  
+[setInterface](https://github.com/melihyarikkaya/react-native-serialport/wiki/Methods/#setInterface)  
+[setAutoConnect](https://github.com/melihyarikkaya/react-native-serialport/wiki/Methods/#setAutoConnect)  
+[setAutoConnectBaudRate](https://github.com/melihyarikkaya/react-native-serialport/wiki/Methods/#setAutoConnectBaudRate)  
+[setDataBit](https://github.com/melihyarikkaya/react-native-serialport/wiki/Methods/#setDataBit)  
+[setStopBit](https://github.com/melihyarikkaya/react-native-serialport/wiki/Methods/#setStopBit)  
+[setParity](https://github.com/melihyarikkaya/react-native-serialport/wiki/Methods/#setParity)  
+[setFlowControl](https://github.com/melihyarikkaya/react-native-serialport/wiki/Methods/#setFlowControl)  
+[loadDefaultConnectionSetting](https://github.com/melihyarikkaya/react-native-serialport/wiki/Methods/#loadDefaultConnectionSetting)
+
+### startUsbService
+
+_Starts the service and usb broadcast receivers_
+
+No Params
+
+```javascript
+RNSerialport.startUsbService();
+```
+
+---
+
+### stopUsbService
+
+_Stops the service and usb broadcast receivers_
+
+No Params
+
+```javascript
+RNSerialport.stopUsbService();
+```
+
+---
+
+### getDeviceList
+
+_Receives device list_
+
+No Param
+
+```javascript
+try {
+  const deviceList = await RNSerialport.getDeviceList();
+  if (deviceList.length > 0) {
+    console.log(deviceList);
+  } else {
+    console.log("Device Not Found");
+  }
+} catch (err) {
+  Alert.alert(
+    "Error from getDeviceList()",
+    err.errorCode + " " + err.errorMessage
+  );
+}
+```
+
+---
+
+### connectDevice
+
+_Use to manual connection_
+
+Params:
+
+| Name       | TYPE   | REQUIRED     |
+| ---------- | ------ | ------------ |
+| deviceName | string | yes for call |
+| baudRate   | number | yes for call |
+
+```javascript
+RNSerialport.connectDevice("deviceName", 9600);
+```
+
+---
+
+### disconnect
+
+_Closes the connection_
+
+No Params
+
+```javascript
+RNSerialport.disconnect();
+```
+
+---
+
+### isOpen
+
+_Returns connection status_
+
+Params:
+
+_No param_
+
+```javascript
+//1st way
+try {
+  const isOpen = await RNSerialport.isOpen();
+
+  if (isOpen) console.log("Is open?", "yes");
+  else console.log("Is open?", "no");
+} catch (err) {
+  console.log(err);
+}
+
+//2st way
+RNSerialport.isOpen()
+  .then(isOpen => {
+    if (isOpen) {
+      console.log("Is open?", "yes");
+    } else {
+      console.log("Is oprn?", "no");
+    }
+  })
+  .catch(err => {
+    console.log(err);
+  });
+```
+
+---
+
+### isSupported
+
+_Returns support status_
+
+Params:
+
+| Name       | TYPE   | REQUIRED     |
+| ---------- | ------ | ------------ |
+| deviceName | string | yes for call |
+
+```javascript
+//1st way
+try {
+  const isSupported = await RNSerialport.isSupported("deviceName");
+
+  if (isSupported) console.log("Is supported?", "yes");
+  else console.log("Is supported?", "no");
+} catch (err) {}
+
+//2st way
+RNSerialport.isSupported("deviceName")
+  .then(isSupported => {
+    if (isSupported) {
+      console.log("Is supported?", "yes");
+    } else {
+      console.log("Is supported?", "no");
+    }
+  })
+  .catch(err => {
+    console.log(err);
+  });
+```
+
+---
+
+### isServiceStarted
+
+_Returns service status_
+
+No param
+
+```javascript
+//1st way
+try {
+  const isServiceStarted = await RNSerialport.isServiceStarted();
+
+  if (isServiceStarted) console.log("Is ServiceStarted?", "yes");
+  else console.log("Is ServiceStarted?", "no");
+} catch (err) {}
+
+//2st way
+RNSerialport.isServiceStarted()
+  .then(isServiceStarted => {
+    if (isServiceStarted) {
+      console.log("Is service started?", "yes");
+    } else {
+      console.log("Is service started?", "no");
+    }
+  })
+  .catch(err => {
+    console.log(err);
+  });
+```
+
+---
+
+### writeString
+
+_Writes data to serial port_
+
+| Name | TYPE   | REQUIRED     |
+| ---- | ------ | ------------ |
+| data | string | yes for call |
+
+```javascript
+RNSerialport.writeString("HELLO");
+```
+
+---
+
+### writeBase64
+
+_Writes data to serial port_
+
+| Name | TYPE   | REQUIRED     |
+| ---- | ------ | ------------ |
+| data | string | yes for call |
+
+```javascript
+RNSerialport.writeBase64("SEVMTE8=");
+```
+
+---
+
+### writeHexString
+
+_Writes data to serial port_
+
+`Note: Make sure the text has a valid hexadecimal number system! Otherwise this does nothing.`
+
+| Name | TYPE   | REQUIRED     |
+| ---- | ------ | ------------ |
+| data | string | yes for call |
+
+```javascript
+RNSerialport.writeHexString("0F"); // 1 byte
+RNSerialport.writeHexString("FF0F"); // 2 btye
+RNSerialport.writeHexString("48454C4C4F"); // 5 byte
+
+//The following are not recommended.
+RNSerialport.writeHexString("F");
+RNSerialport.writeHexString("FFF");
+```
+
+---
+
+### setReturnedDataType
+
+_Changes the data type in "ON_READ_DATA" event_
+
+> Default: INTARRAY
+
+Params:
+
+| TYPE   | REQUIRED     |
+| ------ | ------------ |
+| number | yes for call |
+
+```javascript
+import { definitions } from "react-native-serialport
+RNSerialport.setReturnedDataType(
+  definitions.RETURNED_DATA_TYPES.HEXSTRING
+)
+// or
+RNSerialport.setReturnedDataType(
+  definitions.RETURNED_DATA_TYPES.INTARRAY
+)
+```
+
+---
+
+### setDriver
+
+_Changes the driver_
+
+[Why it is necessary? Using createUsbSerialDevice method specifying the driver](https://github.com/felHR85/UsbSerial/wiki/3.-Create-UsbSerialDevice#using-createusbserialdevice-method-specifying-the-driver)
+
+> Default: AUTO
+
+Params:
+
+| TYPE   | REQUIRED     |
+| ------ | ------------ |
+| string | yes for call |
+
+```javascript
+import { definitions } from "react-native-serialport
+RNSerialport.setDriver(definitions.DRIVER_TYPES.AUTO)
+```
+
+---
+
+### setInterface
+
+_Changes the serial interface_
+
+> Default: -1
+
+Params:
+
+| TYPE   | REQUIRED     |
+| ------ | ------------ |
+| number | yes for call |
+
+```javascript
+RNSerialport.setInterface(1);
+```
+
+---
+
+### setAutoConnectBaudRate
+
+_Changes baud rate to be used on automatic connection_
+
+`Used before starting the service.`
+
+> Default: 9600
+
+Params:
+
+| TYPE   | REQUIRED     |
+| ------ | ------------ |
+| number | yes for call |
+
+```javascript
+RNSerialport.setAutoConnectBaudRate(115200);
+```
+
+---
+
+### setAutoConnect
+
+_Turns automatic connection on or off_
+
+> Default: off
+
+Params:
+
+| TYPE    | REQUIRED     |
+| ------- | ------------ |
+| boolean | yes for call |
+
+```javascript
+RNSerialport.setAutoConnect(true);
+```
+
+---
+
+### setDataBit
+
+_Changes the data bit_
+
+> Default: DATA_BITS_8
+
+Params:
+
+| TYPE   | REQUIRED     |
+| ------ | ------------ |
+| number | yes for call |
+
+```javascript
+import { definitions } from "react-native-serialport
+RNSerialport.setDataBit(definitions.DATA_BITS.DATA_BITS_8)
+```
+
+---
+
+### setStopBit
+
+_Changes the stop bit_
+
+> Default: STOP_BITS_1
+
+Params:
+
+| TYPE   | REQUIRED     |
+| ------ | ------------ |
+| number | yes for call |
+
+```javascript
+import { definitions } from "react-native-serialport";
+RNSerialport.setStopBit(definitions.STOP_BITS.STOP_BITS_1);
+```
+
+---
+
+### setParity
+
+_Changes the parity_
+
+> Default: PARITY_NONE
+
+Params:
+
+| TYPE   | REQUIRED     |
+| ------ | ------------ |
+| number | yes for call |
+
+```javascript
+import { definitions } from "react-native-serialport";
+RNSerialport.setParity(definitions.PARITIES.PARITY_NONE);
+```
+
+---
+
+### setFlowControl
+
+_Changes the flow control mode_
+
+> Default: FLOW_CONTROL_OFF
+
+Params:
+
+| TYPE   | REQUIRED     |
+| ------ | ------------ |
+| number | yes for call |
+
+```javascript
+import { definitions } from "react-native-serialport";
+RNSerialport.setFlowControl(definitions.FLOW_CONTROLS.FLOW_CONTROL_OFF);
+```
+
+---
+
+### loadDefaultConnectionSetting
+
+_Loads the default settings_
+
+> Defaults:  
+> DATA_BIT: DATA_BITS_8  
+> STOP_BIT: STOP_BITS_1  
+> PARITY: PARITY_NONE  
+> FLOW_CONTROL: FLOW_CONTROL_OFF
+
+No Params
+
+```javascript
+RNSerialport.loadDefaultConnectionSetting();
+```
+
+---

+ 71 - 0
index.js

@@ -0,0 +1,71 @@
+import { NativeModules } from 'react-native';
+
+const { RNSerialport } = NativeModules;
+
+const definitions = {
+  DATA_BITS :{
+    DATA_BITS_5: 5,
+    DATA_BITS_6: 6,
+    DATA_BITS_7: 7,
+    DATA_BITS_8: 8
+  },
+  STOP_BITS: {
+    STOP_BITS_1 : 1,
+    STOP_BITS_15: 3,
+    STOP_BITS_2 : 2
+  },
+  PARITIES: {
+    PARITY_NONE : 0,
+    PARITY_ODD  : 1,
+    PARITY_EVEN : 2,
+    PARITY_MARK : 3,
+    PARITY_SPACE: 4
+  },
+  FLOW_CONTROLS: {
+    FLOW_CONTROL_OFF     : 0,
+    FLOW_CONTROL_RTS_CTS : 1,
+    FLOW_CONTROL_DSR_DTR : 2,
+    FLOW_CONTROL_XON_XOFF: 3
+  },
+  RETURNED_DATA_TYPES: {
+    INTARRAY : 1,
+    HEXSTRING: 2
+  },
+  DRIVER_TYPES: {
+    AUTO    : "AUTO",
+    CDC     : "cdc",
+    CH34x   : "ch34x",
+    CP210x  : "cp210x",
+    FTDI    : "ftdi",
+    PL2303  : "pl2303"
+  }
+};
+
+const actions = {
+  ON_SERVICE_STARTED      : 'onServiceStarted',
+  ON_SERVICE_STOPPED      : 'onServiceStopped',
+  ON_DEVICE_ATTACHED      : 'onDeviceAttached',
+  ON_DEVICE_DETACHED      : 'onDeviceDetached',
+  ON_ERROR                : 'onError',
+  ON_CONNECTED            : 'onConnected',
+  ON_DISCONNECTED         : 'onDisconnected',
+  ON_READ_DATA            : 'onReadDataFromPort'
+};
+
+RNSerialport.intArrayToUtf16 = (intArray) => {
+  var str = "";
+  for (var i = 0; i < intArray.length; i++) {
+    str += String.fromCharCode(intArray[i]);
+  }
+  return str;
+}
+RNSerialport.hexToUtf16 = (hex) => {
+  var str = "";
+  var radix = 16;
+  for (var i = 0; i < hex.length && hex.substr(i, 2) !== "00"; i += 2) {
+    str += String.fromCharCode(parseInt(hex.substr(i, 2), radix));
+  }
+  return str;
+}
+
+module.exports = { RNSerialport, definitions, actions };

+ 25 - 0
package.json

@@ -0,0 +1,25 @@
+{
+  "name": "react-native-serialport",
+  "version": "1.3.0",
+  "description": "This library is for usb serial port communication on android platforms",
+  "main": "index.js",
+  "scripts": {
+    "test": "echo \"Error: no test specified\" && exit 1"
+  },
+  "keywords": [
+    "react-native-serialport",
+    "android serialport",
+    "react native usb serialport communication"
+  ],
+  "author": "Melih YARIKKAYA",
+  "license": "MIT",
+  "peerDependencies": {
+    "react-native": "^0.59.0"
+  },
+  "repository": {
+    "type": "git",
+    "url": "https://github.com/melihyarikkaya/react-native-serialport.git"
+  },
+  "homepage": "https://github.com/melihyarikkaya/react-native-serialport.git",
+  "types": "./types/index.d.ts"
+}

+ 269 - 0
types/index.d.ts

@@ -0,0 +1,269 @@
+export interface IDevice {
+  name: string;
+  vendorId: number;
+  productId: number;
+}
+
+export type Devices = Array<IDevice> | null;
+
+export interface IOnReadData {
+  payload: string | Array<number>
+}
+export interface IOnError {
+  status: boolean;
+  errorCode: number;
+  errorMessage: string;
+  exceptionErrorMessage?: string;
+}
+export interface IOnServiceStarted {
+  deviceAttached: boolean
+}
+
+interface DefinitionsStatic {
+  DATA_BITS: {
+    DATA_BITS_5: number
+    DATA_BITS_6: number;
+    DATA_BITS_7: number;
+    DATA_BITS_8: number;
+  };
+  STOP_BITS: {
+    STOP_BITS_1: number;
+    STOP_BITS_15: number;
+    STOP_BITS_2: number;
+  };
+  PARITIES: {
+    PARITY_NONE: number;
+    PARITY_ODD: number;
+    PARITY_EVEN: number;
+    PARITY_MARK: number;
+    PARITY_SPACE: number;
+  };
+  FLOW_CONTROLS: {
+    FLOW_CONTROL_OFF: number;
+    FLOW_CONTROL_RTS_CTS: number;
+    FLOW_CONTROL_DSR_DTR: number;
+    FLOW_CONTROL_XON_XOFF: number;
+  };
+  RETURNED_DATA_TYPES: {
+    INTARRAY: number;
+    HEXSTRING: number;
+  };
+  DRIVER_TYPES: {
+    AUTO: string,
+    CDC: string,
+    CH34x: string,
+    CP210x: string,
+    FTDI: string,
+    PL2303: string
+  };
+}
+export var definitions: DefinitionsStatic;
+
+interface ActionsStatic {
+  ON_SERVICE_STARTED: string,
+  ON_SERVICE_STOPPED: string,
+  ON_DEVICE_ATTACHED: string,
+  ON_DEVICE_DETACHED: string,
+  ON_ERROR: string,
+  ON_CONNECTED: string,
+  ON_DISCONNECTED: string,
+  ON_READ_DATA: string
+}
+export var actions: ActionsStatic;
+
+type DataBits = 5 | 6 | 7 | 8;
+type StopBits = 1 | 2 | 3;
+type Parities = 0 | 1 | 2 | 3 | 4;
+type FlowControls = 0 | 1 | 2 | 3;
+type ReturnedDataTypes = 1 | 2;
+type Drivers = "AUTO" | "cdc" | "ch34x" | "cp210x" | "ftdi" | "pl2303";
+
+interface RNSerialportStatic {
+  /**
+   * Starts the service and Usb listener
+   *
+   * @memberof RNSerialportStatic
+   */
+  startUsbService(): void;
+  /**
+   * Stops the service and Usb listener
+   *
+   * @memberof RNSerialportStatic
+   */
+  stopUsbService(): void;
+
+  /**
+   * Returns status via Promise
+   *
+   * @returns {Promise<boolean>}
+   * @memberof RNSerialportStatic
+   */
+  isOpen(): Promise<boolean>
+
+  /**
+   * Returns status boolean via Promise
+   *
+   * @returns {Promise<boolean>}
+   * @memberof RNSerialportStatic
+   */
+  isServiceStarted(): Promise<boolean>
+
+  /**
+   * Returns support status
+   * 
+   * @param {string} deviceName
+   * @returns {Promise<boolean>}
+   * @memberof RNSerialportStatic
+   */
+  isSupported(deviceName: string): Promise<boolean>;
+
+  //Begin setter methods
+
+  /**
+   * Set the returned data type
+   *
+   * @param {ReturnedDataTypes} type
+   * @memberof RNSerialportStatic
+   */
+  setReturnedDataType(type: ReturnedDataTypes): void;
+
+  /**
+   * Set the interface
+   *
+   * @param {number} iFace
+   * @memberof RNSerialportStatic
+   */
+  setInterface(iFace: number): void;
+
+  /**
+   * Set the data bit
+   *
+   * @param {DataBits} bit
+   * @memberof RNSerialportStatic
+   */
+  setDataBit(bit: DataBits): void;
+
+  /**
+   * Set the stop bit
+   *
+   * @param {StopBits} bit
+   * @memberof RNSerialportStatic
+   */
+  setStopBit(bit: StopBits): void;
+
+  /**
+   * Set the parity
+   *
+   * @param {Parities} parity
+   * @memberof RNSerialportStatic
+   */
+  setParity(parity: Parities): void;
+
+  /**
+   *  Set the flow control
+   *
+   * @param {FlowControls} control
+   * @memberof RNSerialportStatic
+   */
+  setFlowControl(control: FlowControls): void;
+
+  /**
+   * Set the auto connection baudrate
+   *
+   * @param {number} baudRate
+   * @memberof RNSerialportStatic
+   */
+  setAutoConnectBaudRate(baudRate: number): void;
+
+  /**
+   * Set the auto connection status
+   *
+   * @param {boolean} status
+   * @memberof RNSerialportStatic
+   */
+  setAutoConnect(status: boolean): void;
+
+  /**
+   * Set the driver type
+   *
+   * @param {Drivers} driver
+   * @memberof RNSerialportStatic
+   */
+  setDriver(driver: Drivers): void;
+
+  //End setter methods
+
+  /**
+   * Load the default connection settings
+   *
+   * @memberof RNSerialportStatic
+   */
+  loadDefaultConnectionSetting(): void;
+
+  /**
+   * Returns the device list via Promise
+   *
+   * @returns {Promise<Device>}
+   * @memberof RNSerialportStatic
+   */
+  getDeviceList(): Promise<Devices>;
+
+  /**
+   * Connect to device with device name and baud rate
+   *
+   * @param {string} deviceName
+   * @param {number} baudRate
+   * @memberof RNSerialportStatic
+   */
+  connectDevice(deviceName: string, baudRate: number): void;
+
+  /**
+   * Closes the connection
+   *
+   * @memberof RNSerialportStatic
+   */
+  disconnect(): void;
+
+  /**
+   * Writes string to port
+   *
+   * @param {string} data
+   * @memberof RNSerialportStatic
+   */
+  writeString(data: string): void;
+
+  /**
+   * Writes Base64 string to port
+   *
+   * @param {string} data
+   * @memberof RNSerialportStatic
+   */
+  writeBase64(data: string): void;
+
+  /**
+   * Writes hex string to port
+   *
+   * @param {string} data
+   * @memberof RNSerialportStatic
+   */
+  writeHexString(data: string): void
+
+  /**
+   * Integer array convert to Utf16 string
+   *
+   * @param {Array<number>} intArray
+   * @returns {string}
+   * @memberof RNSerialportStatic
+   */
+  intArrayToUtf16(intArray: Array<number>): string
+
+  /**
+   * Hex string convert to Utf16 string
+   *
+   * @param {string} hex
+   * @returns {string}
+   * @memberof RNSerialportStatic
+   */
+  hexToUtf16(hex: string): string
+}
+export var RNSerialport: RNSerialportStatic;