-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathtest11.js
More file actions
41 lines (35 loc) · 1011 Bytes
/
test11.js
File metadata and controls
41 lines (35 loc) · 1011 Bytes
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
console.log('-------------------');
const value = 0;
let buffer;
// if (value == 0) {
// chargehex1 = 0;
// chargehex2 = 0;
// } else if (value == 500) {
// chargehex1 = 0;
// chargehex2 = 17402;
// } else if (value == 1000) {
// chargehex1 = 0;
// chargehex2 = 17530;
// } else if (value == 1500) {
// chargehex1 = 32768;
// chargehex2 = 17595;
if (value < -3.4028234663852886e38 || value > 3.4028234663852886e38) {
throw new Error(`Value out of range for FLOAT32: ${value}`);
}
// buffer = Buffer.allocUnsafe(4);
// buffer.writeFloatLE(value);
buffer = Buffer.allocUnsafe(4);
buffer.writeFloatBE(value);
buffer.swap32().swap16();
const bytes = buffer
.toString('hex')
.toUpperCase()
.replace(/(.{2})/g, '$1 ')
.trimEnd();
console.log(`Write register: Bytes: ${bytes}`);
console.log(`Write register: ${buffer.toString('hex')}`);
if (buffer.byteLength > 2) {
console.log('---------2----------');
} else {
console.log('----------1---------');
}