forked from melihyarikkaya/react-native-serialport
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
71 lines (66 loc) · 1.6 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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 };