@@ -37,11 +37,12 @@ function DriveInterface(ip, config) {
37
37
this . ip = ip ;
38
38
this . port = 48556 ;
39
39
this . PROTOCOL_DEVICE = 0x81 ;
40
- this . LEN_WRAPPER = 4 ;
40
+ this . LEN_WRAPPER = 0x04 ;
41
41
this . REQ_GET = 0x84 ;
42
- this . LEN_GET = 4 ;
42
+ this . LEN_GET = 0x04 ;
43
43
this . REQ_SET = 0x86 ;
44
- this . LEN_SET = 6 ;
44
+ this . LEN_FLOAT_SET = 0x08 ;
45
+ this . LEN_SET = 0x06 ;
45
46
this . EX_TYPE = 0xff ;
46
47
this . EX_LOCK_FAIL = 0xff ;
47
48
this . EX_LOCK_TIMEOUT = 0xfe ;
@@ -62,14 +63,7 @@ function DriveInterface(ip, config) {
62
63
return this ;
63
64
}
64
65
65
- DriveInterface . prototype . getParameter = async function getParameter (
66
- paramId ,
67
- pure
68
- ) {
69
- if ( Array . isArray ( paramId ) ) {
70
- return this . getParameters ( paramId ) ;
71
- }
72
-
66
+ async function _getParameter ( paramId , pure ) {
73
67
const data = Buffer . alloc ( this . LEN_WRAPPER + this . LEN_GET ) ;
74
68
data [ 3 ] = this . PROTOCOL_DEVICE ;
75
69
data [ 4 ] = this . LEN_GET ;
@@ -84,6 +78,31 @@ DriveInterface.prototype.getParameter = async function getParameter(
84
78
85
79
const n = Buffer . from ( [ rslt [ 6 ] , rslt [ 7 ] ] ) ;
86
80
return n . readInt16BE ( ) ;
81
+ }
82
+
83
+ DriveInterface . prototype . getParameter = async function getParameter (
84
+ paramId ,
85
+ pure
86
+ ) {
87
+ if ( Array . isArray ( paramId ) ) {
88
+ return this . getParameters ( paramId ) ;
89
+ }
90
+
91
+ let retry = 3 ;
92
+ let v ;
93
+ while ( retry !== 0 ) {
94
+ try {
95
+ return await _getParameter . bind ( this ) ( paramId , pure ) ;
96
+ } catch ( e ) {
97
+ retry = retry - 1 ;
98
+ }
99
+ }
100
+
101
+ if ( v ) {
102
+ return v ;
103
+ }
104
+
105
+ throw new SocketTimeout ( ) ;
87
106
} ;
88
107
89
108
DriveInterface . prototype . getParameters = function getParameters ( paramIds ) {
@@ -98,10 +117,7 @@ DriveInterface.prototype.getParameters = function getParameters(paramIds) {
98
117
return new Promise ( ( resolve ) => resolve ( null ) ) ;
99
118
} ;
100
119
101
- DriveInterface . prototype . setParameter = async function setParameter (
102
- paramId ,
103
- value
104
- ) {
120
+ async function _setParameter ( paramId , value ) {
105
121
if ( paramId !== null && typeof paramId === `object` ) {
106
122
return this . setParameters ( paramId ) ;
107
123
}
@@ -117,12 +133,32 @@ DriveInterface.prototype.setParameter = async function setParameter(
117
133
v . writeInt16BE ( value ) ;
118
134
[ data [ 8 ] , data [ 9 ] ] = v ;
119
135
await this . deviceTransaction ( data ) ;
120
- const t = await this . getParameter ( paramId ) ;
121
- if ( t !== value ) {
122
- throw new Error ( `Value not set.` ) ;
136
+ return undefined ;
137
+ }
138
+
139
+ DriveInterface . prototype . setParameter = async function setParameter (
140
+ paramId ,
141
+ value
142
+ ) {
143
+ if ( paramId !== null && typeof paramId === `object` ) {
144
+ return this . setParameters ( paramId ) ;
123
145
}
124
146
125
- return t ;
147
+ let retry = 3 ;
148
+ let v ;
149
+ while ( retry !== 0 ) {
150
+ try {
151
+ return await _setParameter . bind ( this ) ( paramId , value ) ;
152
+ } catch ( e ) {
153
+ retry = retry - 1 ;
154
+ }
155
+ }
156
+
157
+ if ( v ) {
158
+ return v ;
159
+ }
160
+
161
+ throw new SocketTimeout ( ) ;
126
162
} ;
127
163
128
164
DriveInterface . prototype . setParameters = function setParameters ( obj ) {
@@ -145,6 +181,38 @@ DriveInterface.prototype.getFloatParameter = async function getFloatParameter(
145
181
return n . readFloatBE ( ) ;
146
182
} ;
147
183
184
+ async function _setFloatParameter ( paramId , value ) {
185
+ const data = Buffer . alloc ( this . LEN_WRAPPER + this . LEN_FLOAT_SET ) ;
186
+ data [ 3 ] = this . PROTOCOL_DEVICE ;
187
+ data [ 4 ] = this . LEN_FLOAT_SET ;
188
+ data [ 5 ] = this . REQ_SET ;
189
+ data . writeUInt16BE ( paramId , 6 ) ;
190
+ data . writeFloatBE ( value , 8 ) ;
191
+ await this . deviceTransaction ( data ) ;
192
+ return undefined ;
193
+ }
194
+
195
+ DriveInterface . prototype . setFloatParameter = async function setFloatParameter (
196
+ paramId ,
197
+ value
198
+ ) {
199
+ let retry = 3 ;
200
+ let v ;
201
+ while ( retry !== 0 ) {
202
+ try {
203
+ return await _setFloatParameter . bind ( this ) ( paramId , value ) ;
204
+ } catch ( e ) {
205
+ retry = retry - 1 ;
206
+ }
207
+ }
208
+
209
+ if ( v ) {
210
+ return v ;
211
+ }
212
+
213
+ throw new SocketTimeout ( ) ;
214
+ } ;
215
+
148
216
DriveInterface . prototype . deviceTransaction = function deviceTransaction ( pkt ) {
149
217
return new Promise ( async ( resolve , reject ) => {
150
218
const self = this ;
0 commit comments