Skip to content

Commit

Permalink
Merge pull request #13 from melihyarikkaya/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
melihyarikkaya authored Apr 29, 2019
2 parents 023ba53 + 1266344 commit bf6e6b8
Show file tree
Hide file tree
Showing 5 changed files with 323 additions and 256 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,9 @@ public void stopUsbService() {
}

@ReactMethod
public void getDeviceList(Callback callback) {
public void getDeviceList(Promise promise) {
if(!usbServiceStarted) {
callback.invoke(createError(Definitions.ERROR_USB_SERVICE_NOT_STARTED, Definitions.ERROR_USB_SERVICE_NOT_STARTED_MESSAGE));
promise.reject(String.valueOf(Definitions.ERROR_USB_SERVICE_NOT_STARTED), Definitions.ERROR_USB_SERVICE_NOT_STARTED_MESSAGE);
return;
}

Expand All @@ -287,7 +287,8 @@ public void getDeviceList(Callback callback) {
HashMap<String, UsbDevice> devices = manager.getDeviceList();

if(devices.isEmpty()) {
callback.invoke(createError(Definitions.ERROR_DEVICE_NOT_FOUND, Definitions.ERROR_DEVICE_NOT_FOUND_MESSAGE));
//promise.reject(String.valueOf(Definitions.ERROR_DEVICE_NOT_FOUND), Definitions.ERROR_DEVICE_NOT_FOUND_MESSAGE);
promise.resolve(Arguments.createArray());
return;
}

Expand All @@ -303,11 +304,7 @@ public void getDeviceList(Callback callback) {
deviceList.pushMap(map);
}

WritableMap map = Arguments.createMap();
map.putBoolean("status", true);
map.putArray("devices", deviceList);

callback.invoke(map);
promise.resolve(deviceList);
}

@ReactMethod
Expand Down
31 changes: 18 additions & 13 deletions doc-wiki/Manual-Connection.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ componentDidMount() {
**Some precautions**

```javascript
componentWillUnmount = async() => {
componentWillUnmount = async () => {
DeviceEventEmitter.removeAllListeners();
const isOpen = await RNSerialport.isOpen();
if (isOpen) {
Alert.alert("isOpen", isOpen);
RNSerialport.disconnect();
}
RNSerialport.stopUsbService();
}
};
```

_Installation Successfuly_
Expand Down Expand Up @@ -163,7 +163,7 @@ class ManualConnection extends Component {
RNSerialport.setReturnedDataType(this.state.returnedDataType);
RNSerialport.setAutoConnect(false);
RNSerialport.startUsbService();
};
}

stopUsbListener = async () => {
DeviceEventEmitter.removeAllListeners();
Expand Down Expand Up @@ -235,18 +235,23 @@ class ManualConnection extends Component {
}
this.setState({ output: data });
}
fillDeviceList() {
RNSerialport.getDeviceList(response => {
if (response.status) {
this.setState({ deviceList: response.devices });
fillDeviceList = async () => {
try {
const deviceList = await RNSerialport.getDeviceList();
if (deviceList.length > 0) {
this.setState({ deviceList });
} else {
Alert.alert(
"Error from getDeviceList()",
response.errorCode + " " + response.errorMessage
);
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 ? (
Expand Down
Loading

0 comments on commit bf6e6b8

Please sign in to comment.