-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
51 lines (45 loc) · 1.35 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
import { NativeModules } from 'react-native';
const { RNModbus } = NativeModules;
/**
*
* @param {*串口编程口} path
* @param {*波特率} baudrate
* @param {*数据位} dataBits
* @param {*校验位} parity
* @param {*停止位} stopBits 0 (NONE), 1 (ODD), 2 (EVEN)
*/
function openDevice(path, baudrate, dataBits, parity, stopBits) {
RNModbus.openDevice(path, baudrate, dataBits, parity, stopBits);
}
/**
* 写多个寄存器
* @param {*从机地址} slaveId
* @param {*写入的地址} start
* @param {*写入的值} values
* @param {*写入成功或者失败回调} Callback
*/
function writeRegisters(slaveId, start, values) {
RNModbus.writeRegisters(slaveId, start, values);
}
/**
* 写单个寄存器
* @param {* 从机地址} slaveId
* @param {* 寄存器地址} start
* @param {* 写入的值} value
* @param {* 回调} Callback
*/
function writeSingleRegister(slaveId, start, value) {
RNModbus.writeRegisters(slaveId, start, value);
}
/**
* 读寄存器数据
* @param {*从机地址} slaveId
* @param {*读取的寄存器地址} start
* @param {*读取的长度} len
* @param {*读取的回调} Callback
*/
function readHoldingRegisters(slaveId, start, len) {
RNModbus.readHoldingRegisters(slaveId, start, len);
}
export { openDevice, writeRegisters, readHoldingRegisters };
export default RNModbus;