修訂 | f1a34aabf691ea938759c784f65055b4374feac3 (tree) |
---|---|
時間 | 2014-07-10 18:16:07 |
作者 | nyatla <nyatla@4719...> |
Commiter | nyatla |
2.0.2
ペリフェラルクラスのコールバック引数対応。
MCUは未実施
git-svn-id: http://svn.osdn.jp/svnroot/mimic/trunk@384 47198e57-cb75-475f-84c4-a814cd6f29e0
@@ -13,7 +13,7 @@ var MiMicJS={}; | ||
13 | 13 | * MiMicJsAPIのバージョン文字列。 |
14 | 14 | * @name MiMicJS#VERSION |
15 | 15 | */ |
16 | - NS.VERSION="MiMicJsAPI/2.0.1"; | |
16 | + NS.VERSION="MiMicJsAPI/2.0.2"; | |
17 | 17 | /** |
18 | 18 | * 配列要素、又は値がすべてInt値でない場合に例外を起こします。 |
19 | 19 | * @name MiMicJS.assertInt |
@@ -76,8 +76,8 @@ var MiMicJS={}; | ||
76 | 76 | }; |
77 | 77 | |
78 | 78 | /** |
79 | - * @private | |
80 | 79 | * オブジェクトがジェネレータクラスであるかを返します。 |
80 | + * @private | |
81 | 81 | */ |
82 | 82 | NS.isGenerator=function isGenerator(o) |
83 | 83 | { |
@@ -85,6 +85,13 @@ var MiMicJS={}; | ||
85 | 85 | return o.toString().indexOf('Generator')!=-1; |
86 | 86 | }; |
87 | 87 | /** |
88 | + * オブジェクトが関数であるかを返します。 | |
89 | + * @private | |
90 | + */ | |
91 | + NS.isFunction=function isFunction(o){ | |
92 | + return (typeof o == 'function'); | |
93 | + } | |
94 | + /** | |
88 | 95 | * @private |
89 | 96 | * 現在の時刻を返します。 |
90 | 97 | */ |
@@ -247,8 +254,70 @@ var MiMicJS={}; | ||
247 | 254 | window[key]=v[key]; |
248 | 255 | } |
249 | 256 | } |
257 | + /** | |
258 | + * MiMicSDK向けの内部関数です。 | |
259 | + * 末尾引数が関数の場合にはその関数を、異なる場合はi_cbを返却します。 | |
260 | + * @private | |
261 | + * @param i_arg | |
262 | + * 引数配列を指定します。 | |
263 | + * @param i_default_cb | |
264 | + * 引数配列に関数がなかった場合に返す値を指定します。 | |
265 | + */ | |
266 | + NS._getCb=function _getCb(i_arg,i_default_cb) | |
267 | + { | |
268 | + if(i_arg.length==0){ | |
269 | + return i_default_cb; | |
270 | + } | |
271 | + return NS.isFunction(i_arg[i_arg.length-1])?i_arg[i_arg.length-1]:i_default_cb; | |
272 | + } | |
273 | + /** | |
274 | + * MiMicSDK向けの関数です。 | |
275 | + * 末尾の拡張変数を取り除いたarguments引数の数を返します。 | |
276 | + * @private | |
277 | + */ | |
278 | + NS._getBaseArgsLen=function _getBaseArgsLen(i_arg) | |
279 | + { | |
280 | + if(i_arg.length==0 || (!NS.isFunction(i_arg[i_arg.length-1]))){ | |
281 | + return i_arg.length; | |
282 | + } | |
283 | + return i_arg.length==1?0:i_arg.length-1; | |
284 | + } | |
285 | + | |
286 | + /** | |
287 | + * MiMicSDK向けの関数です。 | |
288 | + * インスタンスがyieldコール可能かをチェックし、可能ならコール関数を記録します。 | |
289 | + * 関数は、インスタンスの_gen,_lcをチェックして、yieldが不可能な場合に例外を発生します。 | |
290 | + * _assertYield.call(this)でコールして下さい。 | |
291 | + * @private | |
292 | + */ | |
293 | + NS._assertYield=function _assertYield() | |
294 | + { | |
295 | + if(this._gen && this._lc){ | |
296 | + throw new NS.MiMicException(NS.Error.NG_YIELD_NOT_COMPLETED); | |
297 | + } | |
298 | + } | |
299 | + /** | |
300 | + * MiMicSDK向けの関数です。コンストラクタでイベントハンドラをセットアップする定型処理です。 | |
301 | + * i_handlerにセットされたオブジェクトに従って_gen,_eventメンバをセットします。 | |
302 | + * _initHandler.call(this,i_handler)でコールして下さい。 | |
303 | + * @private | |
304 | + */ | |
305 | + NS._initHandler=function _initHandler(i_handler) | |
306 | + { | |
307 | + if(NS.isGenerator(i_handler)){ | |
308 | + this._gen=i_handler; | |
309 | + }else if(NS.isFunction(i_handler)){ | |
310 | + return i_handler; | |
311 | + }else if(i_handler){ | |
312 | + this._event=i_handler; | |
313 | + return i_handler.onNew; | |
314 | + } | |
315 | + return null; | |
316 | + } | |
317 | + | |
318 | + | |
250 | 319 | }()); |
251 | - | |
320 | + | |
252 | 321 | (function(){ |
253 | 322 | var NS=MiMicJS; |
254 | 323 |
@@ -542,7 +611,7 @@ var MiMicJS={}; | ||
542 | 611 | rx+='})'; |
543 | 612 | rxst=0; |
544 | 613 | { |
545 | - log(rx);//Debug | |
614 | +// log(rx);//Debug | |
546 | 615 | //JSONがたぶん確定 |
547 | 616 | var j=eval(rx); |
548 | 617 | for(var i2=q.length-1;i2>=0;i2--){ |
@@ -611,7 +680,7 @@ var MiMicJS={}; | ||
611 | 680 | sendMethod:function callJsonRpc(i_method,i_params,i_callback) |
612 | 681 | { |
613 | 682 | var v="{\"jsonrpc\":\"2.0\",\"method\":\""+i_method+"\",\"params\":["+i_params+"],\"id\":"+this._method_id+"}"; |
614 | - log(v);//Debug | |
683 | +// log(v);//Debug | |
615 | 684 | this._ws.send(v); |
616 | 685 | this._q.push([this._method_id,i_callback]);//キューに記録 |
617 | 686 | this._method_id=(this._method_id+1)&0x0fffffff;//IDインクリメント |
@@ -14,8 +14,8 @@ var MI=MiMicJS; | ||
14 | 14 | * インスタンスをバインドするMCUオブジェクトです。 |
15 | 15 | * @param {PinName} i_params |
16 | 16 | * ピンIDを指定します。 |
17 | - * @param {HashMap|Generator} i_event | |
18 | - * 非同期イベントハンドラの連想配列、又はGeneratorです。 | |
17 | + * @param {HashMap|Generator|function} i_handler | |
18 | + * 非同期イベントハンドラの連想配列、Generator、コールバック関数の何れかを指定します。 | |
19 | 19 | * <p> |
20 | 20 | * 非同期イベントハンドラの場合、関数はイベントハンドラで結果を通知します。 |
21 | 21 | * <ul> |
@@ -37,7 +37,10 @@ var MI=MiMicJS; | ||
37 | 37 | * </ul> |
38 | 38 | * <p> |
39 | 39 | * Generatorを指定した場合、コールバック関数の引数はyiledの戻り値として取得できます。 |
40 | + * </p> | |
40 | 41 | * <p> |
42 | + * コールバック関数を指定した場合、RPCが完了したときに呼び出されます。メンバ関数のイベントハンドラは個別に設定する必要があります。 | |
43 | + * </p> | |
41 | 44 | * @return {mbedJS.AnalogIn} |
42 | 45 | * @example //Callback |
43 | 46 | * var mcu=new mbedJS.Mcu("192.168.128.39", |
@@ -79,17 +82,17 @@ var CLASS=function AnalogIn(i_mcu,i_params,i_handler) | ||
79 | 82 | var _t=this; |
80 | 83 | _t._mcu=i_mcu; |
81 | 84 | _t._lc=CLASS; |
82 | - if(MI.isGenerator(i_handler)){_t._gen=i_handler;} | |
83 | - else if(i_handler){_t._event=i_handler} | |
84 | - function cb(j) | |
85 | - { | |
86 | - _t._oid=j.result[0]; | |
87 | - if(_t._event.onNew){_t._event.onNew();} | |
88 | - if(_t._gen){_t._gen.next(_t);} | |
89 | - _t._lc=null; | |
90 | - } | |
85 | + var cb=MI._initHandler.call(_t,i_handler); | |
91 | 86 | MI.assertInt(i_params); |
92 | - return _t._mcu.rpc(_t.RPC_NS+":_new1",i_params,cb); | |
87 | + _t._mcu.rpc(_t.RPC_NS+":_new1",i_params, | |
88 | + function(j) | |
89 | + { | |
90 | + _t._oid=j.result[0]; | |
91 | + if(cb){cb();} | |
92 | + if(_t._gen){_t._gen.next(_t);} | |
93 | + _t._lc=null; | |
94 | + } | |
95 | + ); | |
93 | 96 | }catch(e){ |
94 | 97 | throw new MI.MiMicException(e); |
95 | 98 | } |
@@ -136,16 +139,17 @@ CLASS.prototype= | ||
136 | 139 | { |
137 | 140 | try{ |
138 | 141 | var _t=this; |
139 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
142 | + var cb=MI._getCb(arguments,_t._event.onRead); | |
143 | + MI._assertYield.call(_t); | |
140 | 144 | _t._lc=CLASS.read; |
141 | 145 | return _t._mcu.rpc(_t.RPC_NS+":read_fx",_t._oid, |
142 | - function (j) | |
143 | - { | |
144 | - var v=j.result[0]/10000; | |
145 | - if(_t._event.onRead){_t._event.onRead(v);} | |
146 | - if(_t._gen){_t._gen.next(v);} | |
147 | - _t._lc=null; | |
148 | - } | |
146 | + function (j) | |
147 | + { | |
148 | + var v=j.result[0]/10000; | |
149 | + if(cb){cb(v);} | |
150 | + if(_t._gen){_t._gen.next(v);} | |
151 | + _t._lc=null; | |
152 | + } | |
149 | 153 | ); |
150 | 154 | }catch(e){ |
151 | 155 | throw new MI.MiMicException(e); |
@@ -166,16 +170,17 @@ CLASS.prototype= | ||
166 | 170 | { |
167 | 171 | try{ |
168 | 172 | var _t=this; |
169 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
173 | + var cb=MI._getCb(arguments,_t._event.onRead_u16); | |
174 | + MI._assertYield.call(_t); | |
170 | 175 | _t._lc=CLASS.read_u16; |
171 | 176 | return _t._mcu.rpc(_t.RPC_NS+":read_u16",_t._oid, |
172 | - function (j) | |
173 | - { | |
174 | - var v=j.result[0]; | |
175 | - if(_t._event.onRead_u16){_t._event.onRead_u16(v);} | |
176 | - if(_t._gen){_t._gen.next(v);} | |
177 | - _t._lc=null; | |
178 | - } | |
177 | + function (j) | |
178 | + { | |
179 | + var v=j.result[0]; | |
180 | + if(cb){cb(v);} | |
181 | + if(_t._gen){_t._gen.next(v);} | |
182 | + _t._lc=null; | |
183 | + } | |
179 | 184 | ); |
180 | 185 | }catch(e){ |
181 | 186 | throw new MI.MiMicException(e); |
@@ -14,8 +14,8 @@ var MI=MiMicJS; | ||
14 | 14 | * インスタンスをバインドするMCUオブジェクトです。 |
15 | 15 | * @param {PinName} i_params |
16 | 16 | * ピンIDを指定します。 |
17 | - * @param {HashMap|Generator} i_event | |
18 | - * 非同期イベントハンドラの連想配列、又はGeneratorです。 | |
17 | + * @param {HashMap|Generator|function} i_handler | |
18 | + * 非同期イベントハンドラの連想配列、Generator、コールバック関数の何れかを指定します。 | |
19 | 19 | * <p> |
20 | 20 | * 非同期イベントハンドラの場合、関数はイベントハンドラで結果を通知します。 |
21 | 21 | * <ul> |
@@ -37,7 +37,10 @@ var MI=MiMicJS; | ||
37 | 37 | * </ul> |
38 | 38 | * <p> |
39 | 39 | * Generatorを指定した場合、コールバック関数の引数はyiledの戻り値として取得できます。 |
40 | + * </p> | |
40 | 41 | * <p> |
42 | + * コールバック関数を指定した場合、RPCが完了したときに呼び出されます。メンバ関数のイベントハンドラは個別に設定する必要があります。 | |
43 | + * </p> | |
41 | 44 | * @return {mbedJS.AnalogOut} |
42 | 45 | * @example //Callback |
43 | 46 | * var mcu=new mbedJS.Mcu("192.168.128.39", |
@@ -89,17 +92,17 @@ var CLASS=function AnalogOut(i_mcu,i_params,i_handler) | ||
89 | 92 | var _t=this; |
90 | 93 | _t._mcu=i_mcu; |
91 | 94 | _t._lc=CLASS; |
92 | - if(MI.isGenerator(i_handler)){_t._gen=i_handler;} | |
93 | - else if(i_handler){_t._event=i_handler} | |
94 | - function cb(j) | |
95 | - { | |
96 | - _t._oid=j.result[0]; | |
97 | - if(_t._event.onNew){_t._event.onNew();} | |
98 | - if(_t._gen){_t._gen.next(_t);} | |
99 | - _t._lc=null; | |
100 | - } | |
95 | + var cb=MI._initHandler.call(_t,i_handler); | |
101 | 96 | MI.assertInt(i_params); |
102 | - return _t._mcu.rpc(_t.RPC_NS+":_new1",i_params,cb); | |
97 | + _t._mcu.rpc(_t.RPC_NS+":_new1",i_params, | |
98 | + function(j) | |
99 | + { | |
100 | + _t._oid=j.result[0]; | |
101 | + if(cb){cb();} | |
102 | + if(_t._gen){_t._gen.next(_t);} | |
103 | + _t._lc=null; | |
104 | + } | |
105 | + ); | |
103 | 106 | }catch(e){ |
104 | 107 | throw new MI.MiMicException(e); |
105 | 108 | } |
@@ -146,15 +149,17 @@ CLASS.prototype= | ||
146 | 149 | { |
147 | 150 | try{ |
148 | 151 | var _t=this; |
149 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
152 | + var cb=MI._getCb(arguments,_t._event.onWrite); | |
153 | + MI._assertYield.call(_t); | |
150 | 154 | _t._lc=CLASS.write; |
151 | 155 | MI.assertNumber(i_value); |
152 | 156 | return _t._mcu.rpc(_t.RPC_NS+":write_fx",_t._oid+","+Math.round(i_value*10000), |
153 | - function(j){ | |
154 | - if(_t._event.onWrite){_t._event.onWrite();} | |
155 | - if(_t._gen){_t._gen.next();} | |
156 | - _t._lc=null; | |
157 | - }); | |
157 | + function(j){ | |
158 | + if(cb){cb();} | |
159 | + if(_t._gen){_t._gen.next();} | |
160 | + _t._lc=null; | |
161 | + } | |
162 | + ); | |
158 | 163 | }catch(e){ |
159 | 164 | throw new MI.MiMicException(e); |
160 | 165 | } |
@@ -174,15 +179,17 @@ CLASS.prototype= | ||
174 | 179 | { |
175 | 180 | try{ |
176 | 181 | var _t=this; |
177 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
182 | + var cb=MI._getCb(arguments,_t._event.onWrite_u16); | |
183 | + MI._assertYield.call(_t); | |
178 | 184 | _t._lc=CLASS.write; |
179 | 185 | MI.assertInt(i_value); |
180 | 186 | return _t._mcu.rpc(_t.RPC_NS+":write_fx",_t._oid+","+i_value, |
181 | - function(j){ | |
182 | - if(_t._event.onWrite_u16){_t._event.onWrite_u16();} | |
183 | - if(_t._gen){_t._gen.next();} | |
184 | - _t._lc=null; | |
185 | - }); | |
187 | + function(j){ | |
188 | + if(cb){cb();} | |
189 | + if(_t._gen){_t._gen.next();} | |
190 | + _t._lc=null; | |
191 | + } | |
192 | + ); | |
186 | 193 | }catch(e){ |
187 | 194 | throw new MI.MiMicException(e); |
188 | 195 | } |
@@ -202,16 +209,17 @@ CLASS.prototype= | ||
202 | 209 | { |
203 | 210 | try{ |
204 | 211 | var _t=this; |
205 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
212 | + var cb=MI._getCb(arguments,_t._event.onRead); | |
213 | + MI._assertYield.call(_t); | |
206 | 214 | _t._lc=CLASS.read; |
207 | 215 | return _t._mcu.rpc(_t.RPC_NS+":read_fx",_t._oid, |
208 | - function (j) | |
209 | - { | |
210 | - var v=j.result[0]/10000; | |
211 | - if(_t._event.onRead){_t._event.onRead(v);} | |
212 | - if(_t._gen){_t._gen.next(v);} | |
213 | - _t._lc=null; | |
214 | - } | |
216 | + function (j) | |
217 | + { | |
218 | + var v=j.result[0]/10000; | |
219 | + if(cb){cb(v);} | |
220 | + if(_t._gen){_t._gen.next(v);} | |
221 | + _t._lc=null; | |
222 | + } | |
215 | 223 | ); |
216 | 224 | }catch(e){ |
217 | 225 | throw new MI.MiMicException(e); |
@@ -14,8 +14,8 @@ var MI=MiMicJS; | ||
14 | 14 | * インスタンスをバインドするMCUオブジェクトです。 |
15 | 15 | * @param {[PinName...]} i_params |
16 | 16 | * ピンIDの配列を指定します。要素数の最大値は16です。 |
17 | - * @param {HashMap|Generator} i_event | |
18 | - * 非同期イベントハンドラの連想配列、又はGeneratorです。 | |
17 | + * @param {HashMap|Generator|function} i_handler | |
18 | + * 非同期イベントハンドラの連想配列、Generator、コールバック関数の何れかを指定します。 | |
19 | 19 | * <p> |
20 | 20 | * 非同期イベントハンドラの場合、関数はイベントハンドラで結果を通知します。 |
21 | 21 | * <ul> |
@@ -34,7 +34,10 @@ var MI=MiMicJS; | ||
34 | 34 | * </ul> |
35 | 35 | * <p> |
36 | 36 | * Generatorを指定した場合、コールバック関数の引数はyiledの戻り値として取得できます。 |
37 | + * </p> | |
37 | 38 | * <p> |
39 | + * コールバック関数を指定した場合、RPCが完了したときに呼び出されます。メンバ関数のイベントハンドラは個別に設定する必要があります。 | |
40 | + * </p> | |
38 | 41 | * @return {mbedJS.BusIn} |
39 | 42 | * @example //Callback |
40 | 43 | * var mcu=new mbedJS.Mcu("192.168.128.39", |
@@ -78,15 +81,7 @@ var CLASS=function BusIn(i_mcu,i_params,i_handler) | ||
78 | 81 | var _t=this; |
79 | 82 | _t._mcu=i_mcu; |
80 | 83 | _t._lc=CLASS; |
81 | - if(MI.isGenerator(i_handler)){_t._gen=i_handler;} | |
82 | - else if(i_handler){_t._event=i_handler} | |
83 | - function cb(j) | |
84 | - { | |
85 | - _t._oid=j.result[0]; | |
86 | - if(_t._event.onNew){_t._event.onNew();} | |
87 | - if(_t._gen){_t._gen.next(_t);} | |
88 | - _t._lc=null; | |
89 | - } | |
84 | + var cb=MI._initHandler.call(_t,i_handler); | |
90 | 85 | //Pin配列の正規化 |
91 | 86 | var ap=i_params; |
92 | 87 | if(ap.length<1 ||ap.length>16){ |
@@ -102,7 +97,15 @@ var CLASS=function BusIn(i_mcu,i_params,i_handler) | ||
102 | 97 | for(;i<16;i++){ |
103 | 98 | pins+=","+NS.PinName.NC; |
104 | 99 | } |
105 | - return _t._mcu.rpc(_t.RPC_NS+":_new1",pins,cb); | |
100 | + _t._mcu.rpc(_t.RPC_NS+":_new1",pins, | |
101 | + function(j) | |
102 | + { | |
103 | + _t._oid=j.result[0]; | |
104 | + if(cb){cb();} | |
105 | + if(_t._gen){_t._gen.next(_t);} | |
106 | + _t._lc=null; | |
107 | + } | |
108 | + ); | |
106 | 109 | }catch(e){ |
107 | 110 | throw new MI.MiMicException(e); |
108 | 111 | } |
@@ -149,16 +152,17 @@ CLASS.prototype= | ||
149 | 152 | { |
150 | 153 | try{ |
151 | 154 | var _t=this; |
152 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
155 | + var cb=MI._getCb(arguments,_t._event.onRead); | |
156 | + MI._assertYield.call(_t); | |
153 | 157 | _t._lc=CLASS.read; |
154 | 158 | return _t._mcu.rpc(_t.RPC_NS+":read",_t._oid, |
155 | - function (j) | |
156 | - { | |
157 | - var v=j.result[0]; | |
158 | - if(_t._event.onRead){_t._event.onRead(v);} | |
159 | - if(_t._gen){_t._gen.next(v);} | |
160 | - _t._lc=null; | |
161 | - } | |
159 | + function (j) | |
160 | + { | |
161 | + var v=j.result[0]; | |
162 | + if(cb){cb(v);} | |
163 | + if(_t._gen){_t._gen.next(v);} | |
164 | + _t._lc=null; | |
165 | + } | |
162 | 166 | ); |
163 | 167 | }catch(e){ |
164 | 168 | throw new MI.MiMicException(e); |
@@ -179,17 +183,17 @@ CLASS.prototype= | ||
179 | 183 | { |
180 | 184 | try{ |
181 | 185 | var _t=this; |
182 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
183 | - _t._lc=CLASS.mode; | |
186 | + var cb=MI._getCb(arguments,_t._event.onMode); | |
187 | + MI._assertYield.call(_t); | |
184 | 188 | MI.assertInt(i_value); |
185 | 189 | return _t._mcu.rpc(_t.RPC_NS+":mode",_t._oid+","+i_value, |
186 | - function (j) | |
187 | - { | |
188 | - var v=j.result[0]; | |
189 | - if(_t._event.onMode){_t._event.onMode(v);} | |
190 | - if(_t._gen){_t._gen.next(v);} | |
191 | - _t._lc=null; | |
192 | - } | |
190 | + function (j) | |
191 | + { | |
192 | + var v=j.result[0]; | |
193 | + if(cb){cb(v);} | |
194 | + if(_t._gen){_t._gen.next(v);} | |
195 | + _t._lc=null; | |
196 | + } | |
193 | 197 | ); |
194 | 198 | }catch(e){ |
195 | 199 | throw new MI.MiMicException(e); |
@@ -14,8 +14,8 @@ var MI=MiMicJS; | ||
14 | 14 | * インスタンスをバインドするMCUオブジェクトです。 |
15 | 15 | * @param {[PinName...]} i_params |
16 | 16 | * ピンIDの配列を指定します。要素数の最大値は16です。 |
17 | - * @param {HashMap|Generator} i_event | |
18 | - * 非同期イベントハンドラの連想配列、又はGeneratorです。 | |
17 | + * @param {HashMap|Generator|function} i_handler | |
18 | + * 非同期イベントハンドラの連想配列、Generator、コールバック関数の何れかを指定します。 | |
19 | 19 | * <p> |
20 | 20 | * 非同期イベントハンドラの場合、関数はイベントハンドラで結果を通知します。 |
21 | 21 | * <ul> |
@@ -44,7 +44,10 @@ var MI=MiMicJS; | ||
44 | 44 | * |
45 | 45 | * <p> |
46 | 46 | * Generatorを指定した場合、コールバック関数の引数はyiledの戻り値として取得できます。 |
47 | + * </p> | |
47 | 48 | * <p> |
49 | + * コールバック関数を指定した場合、RPCが完了したときに呼び出されます。メンバ関数のイベントハンドラは個別に設定する必要があります。 | |
50 | + * </p> | |
48 | 51 | * @return {mbedJS.BusIn} |
49 | 52 | * @example //Callback |
50 | 53 | * var mcu=new mbedJS.Mcu("192.168.128.39", |
@@ -105,15 +108,7 @@ var CLASS=function BusInOut(i_mcu,i_params,i_handler) | ||
105 | 108 | var _t=this; |
106 | 109 | _t._mcu=i_mcu; |
107 | 110 | _t._lc=CLASS; |
108 | - if(MI.isGenerator(i_handler)){_t._gen=i_handler;} | |
109 | - else if(i_handler){_t._event=i_handler} | |
110 | - function cb(j) | |
111 | - { | |
112 | - _t._oid=j.result[0]; | |
113 | - if(_t._event.onNew){_t._event.onNew();} | |
114 | - if(_t._gen){_t._gen.next(_t);} | |
115 | - _t._lc=null; | |
116 | - } | |
111 | + var cb=MI._initHandler.call(_t,i_handler); | |
117 | 112 | //Pin配列の正規化 |
118 | 113 | var ap=i_params; |
119 | 114 | //数値のみの配列かな? |
@@ -129,7 +124,15 @@ var CLASS=function BusInOut(i_mcu,i_params,i_handler) | ||
129 | 124 | for(;i<16;i++){ |
130 | 125 | pins+=","+NS.PinName.NC; |
131 | 126 | } |
132 | - return _t._mcu.rpc(_t.RPC_NS+":_new1",pins,cb); | |
127 | + _t._mcu.rpc(_t.RPC_NS+":_new1",pins, | |
128 | + function(j) | |
129 | + { | |
130 | + _t._oid=j.result[0]; | |
131 | + if(cb){cb();} | |
132 | + if(_t._gen){_t._gen.next(_t);} | |
133 | + _t._lc=null; | |
134 | + } | |
135 | + ); | |
133 | 136 | }catch(e){ |
134 | 137 | throw new MI.MiMicException(e); |
135 | 138 | } |
@@ -175,15 +178,17 @@ CLASS.prototype= | ||
175 | 178 | { |
176 | 179 | try{ |
177 | 180 | var _t=this; |
178 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
181 | + var cb=MI._getCb(arguments,_t._event.onWrite); | |
182 | + MI._assertYield.call(_t); | |
179 | 183 | _t._lc=CLASS.write; |
180 | 184 | MI.assertInt(i_value); |
181 | 185 | return _t._mcu.rpc(_t.RPC_NS+":write",_t._oid+","+i_value, |
182 | - function(j){ | |
183 | - if(_t._event.onWrite){_t._event.onWrite();} | |
184 | - if(_t._gen){_t._gen.next();} | |
185 | - _t._lc=null; | |
186 | - }); | |
186 | + function(j){ | |
187 | + if(cb){cb();} | |
188 | + if(_t._gen){_t._gen.next();} | |
189 | + _t._lc=null; | |
190 | + } | |
191 | + ); | |
187 | 192 | }catch(e){ |
188 | 193 | throw new MI.MiMicException(e); |
189 | 194 | } |
@@ -203,16 +208,17 @@ CLASS.prototype= | ||
203 | 208 | { |
204 | 209 | try{ |
205 | 210 | var _t=this; |
206 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
211 | + var cb=MI._getCb(arguments,_t._event.onRead); | |
212 | + MI._assertYield.call(_t); | |
207 | 213 | _t._lc=CLASS.read; |
208 | 214 | return _t._mcu.rpc(_t.RPC_NS+":read",_t._oid, |
209 | - function (j) | |
210 | - { | |
211 | - var v=j.result[0]; | |
212 | - if(_t._event.onRead){_t._event.onRead(v);} | |
213 | - if(_t._gen){_t._gen.next(v);} | |
214 | - _t._lc=null; | |
215 | - } | |
215 | + function (j) | |
216 | + { | |
217 | + var v=j.result[0]; | |
218 | + if(cb){cb(v);} | |
219 | + if(_t._gen){_t._gen.next(v);} | |
220 | + _t._lc=null; | |
221 | + } | |
216 | 222 | ); |
217 | 223 | }catch(e){ |
218 | 224 | throw new MI.MiMicException(e); |
@@ -233,17 +239,19 @@ CLASS.prototype= | ||
233 | 239 | { |
234 | 240 | try{ |
235 | 241 | var _t=this; |
236 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
242 | + var cb=MI._getCb(arguments,_t._event.onMode); | |
243 | + MI._assertYield.call(_t); | |
237 | 244 | _t._lc=CLASS.mode; |
238 | 245 | MI.assertInt(i_value); |
239 | 246 | return _t._mcu.rpc(_t.RPC_NS+":mode",_t._oid+","+i_value, |
240 | - function (j) | |
241 | - { | |
242 | - var v=j.result[0]; | |
243 | - if(_t._event.onMode){_t._event.onMode(v);} | |
244 | - if(_t._gen){_t._gen.next(v);} | |
245 | - _t._lc=null; | |
246 | - }); | |
247 | + function (j) | |
248 | + { | |
249 | + var v=j.result[0]; | |
250 | + if(cb){cb(v);} | |
251 | + if(_t._gen){_t._gen.next(v);} | |
252 | + _t._lc=null; | |
253 | + } | |
254 | + ); | |
247 | 255 | }catch(e){ |
248 | 256 | throw new MI.MiMicException(e); |
249 | 257 | } |
@@ -261,12 +269,13 @@ CLASS.prototype= | ||
261 | 269 | { |
262 | 270 | try{ |
263 | 271 | var _t=this; |
264 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
272 | + var cb=MI._getCb(arguments,_t._event.onInput); | |
273 | + MI._assertYield.call(_t); | |
265 | 274 | _t._lc=CLASS.input; |
266 | 275 | return _t._mcu.rpc(_t.RPC_NS+":input",_t._oid, |
267 | 276 | function (j) |
268 | 277 | { |
269 | - if(_t._event.onInput){_t._event.onInput();} | |
278 | + if(cb){cb();} | |
270 | 279 | if(_t._gen){_t._gen.next();} |
271 | 280 | _t._lc=null; |
272 | 281 | }); |
@@ -287,12 +296,13 @@ CLASS.prototype= | ||
287 | 296 | { |
288 | 297 | try{ |
289 | 298 | var _t=this; |
290 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
299 | + var cb=MI._getCb(arguments,_t._event.onOutput); | |
300 | + MI._assertYield.call(_t); | |
291 | 301 | _t._lc=CLASS.mode; |
292 | 302 | return _t._mcu.rpc(_t.RPC_NS+":output",_t._oid, |
293 | 303 | function (j) |
294 | 304 | { |
295 | - if(_t._event.onOutput){_t._event.onOutput();} | |
305 | + if(cb){cb();} | |
296 | 306 | if(_t._gen){_t._gen.next();} |
297 | 307 | _t._lc=null; |
298 | 308 | }); |
@@ -14,8 +14,8 @@ var MI=MiMicJS; | ||
14 | 14 | * インスタンスをバインドするMCUオブジェクトです。 |
15 | 15 | * @param {[PinName...]} i_params |
16 | 16 | * ピンIDの配列を指定します。要素数の最大値は16です。 |
17 | - * @param {HashMap|Generator} i_event | |
18 | - * 非同期イベントハンドラの連想配列、又はGeneratorです。 | |
17 | + * @param {HashMap|Generator|function} i_handler | |
18 | + * 非同期イベントハンドラの連想配列、Generator、コールバック関数の何れかを指定します。 | |
19 | 19 | * <p> |
20 | 20 | * 非同期イベントハンドラの場合、関数はイベントハンドラで結果を通知します。 |
21 | 21 | * <ul> |
@@ -34,7 +34,10 @@ var MI=MiMicJS; | ||
34 | 34 | * </ul> |
35 | 35 | * <p> |
36 | 36 | * Generatorを指定した場合、コールバック関数の引数はyiledの戻り値として取得できます。 |
37 | + * </p> | |
37 | 38 | * <p> |
39 | + * コールバック関数を指定した場合、RPCが完了したときに呼び出されます。メンバ関数のイベントハンドラは個別に設定する必要があります。 | |
40 | + * </p> | |
38 | 41 | * @return {mbedJS.BusOut} |
39 | 42 | * @example //Callback |
40 | 43 | * var mcu=new mbedJS.Mcu("192.168.128.39", |
@@ -80,15 +83,7 @@ var CLASS=function BusOut(i_mcu,i_params,i_handler) | ||
80 | 83 | var _t=this; |
81 | 84 | _t._mcu=i_mcu; |
82 | 85 | _t._lc=CLASS; |
83 | - if(MI.isGenerator(i_handler)){_t._gen=i_handler;} | |
84 | - else if(i_handler){_t._event=i_handler} | |
85 | - function cb(j) | |
86 | - { | |
87 | - _t._oid=j.result[0]; | |
88 | - if(_t._event.onNew){_t._event.onNew();} | |
89 | - if(_t._gen){_t._gen.next(_t);} | |
90 | - _t._lc=null; | |
91 | - } | |
86 | + var cb=MI._initHandler.call(_t,i_handler); | |
92 | 87 | //Pin配列の正規化 |
93 | 88 | var ap=i_params; |
94 | 89 | if(ap.length<1 ||ap.length>16){ |
@@ -104,7 +99,15 @@ var CLASS=function BusOut(i_mcu,i_params,i_handler) | ||
104 | 99 | for(;i<16;i++){ |
105 | 100 | pins+=","+NS.PinName.NC; |
106 | 101 | } |
107 | - return _t._mcu.rpc(_t.RPC_NS+":_new1",pins,cb); | |
102 | + _t._mcu.rpc(_t.RPC_NS+":_new1",pins, | |
103 | + function(j) | |
104 | + { | |
105 | + _t._oid=j.result[0]; | |
106 | + if(cb){cb();} | |
107 | + if(_t._gen){_t._gen.next(_t);} | |
108 | + _t._lc=null; | |
109 | + } | |
110 | + ); | |
108 | 111 | }catch(e){ |
109 | 112 | throw new MI.MiMicException(e); |
110 | 113 | } |
@@ -151,15 +154,17 @@ CLASS.prototype= | ||
151 | 154 | { |
152 | 155 | try{ |
153 | 156 | var _t=this; |
154 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
157 | + var cb=MI._getCb(arguments,_t._event.onWrite); | |
158 | + MI._assertYield.call(_t); | |
155 | 159 | _t._lc=CLASS.write; |
156 | 160 | MI.assertInt(i_value); |
157 | 161 | return _t._mcu.rpc(_t.RPC_NS+":write",_t._oid+","+i_value, |
158 | - function(j){ | |
159 | - if(_t._event.onWrite){_t._event.onWrite();} | |
160 | - if(_t._gen){_t._gen.next();} | |
161 | - _t._lc=null; | |
162 | - }); | |
162 | + function(j){ | |
163 | + if(cb){cb();} | |
164 | + if(_t._gen){_t._gen.next();} | |
165 | + _t._lc=null; | |
166 | + } | |
167 | + ); | |
163 | 168 | }catch(e){ |
164 | 169 | throw new MI.MiMicException(e); |
165 | 170 | } |
@@ -179,16 +184,18 @@ CLASS.prototype= | ||
179 | 184 | { |
180 | 185 | try{ |
181 | 186 | var _t=this; |
182 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
187 | + var cb=MI._getCb(arguments,_t._event.onRead); | |
188 | + MI._assertYield.call(_t); | |
183 | 189 | _t._lc=CLASS.read; |
184 | 190 | return _t._mcu.rpc(_t.RPC_NS+":read",_t._oid, |
185 | - function (j) | |
186 | - { | |
187 | - var v=j.result[0]; | |
188 | - if(_t._event.onRead){_t._event.onRead(v);} | |
189 | - if(_t._gen){_t._gen.next(v);} | |
190 | - _t._lc=null; | |
191 | - }); | |
191 | + function (j) | |
192 | + { | |
193 | + var v=j.result[0]; | |
194 | + if(cb){cb(v);} | |
195 | + if(_t._gen){_t._gen.next(v);} | |
196 | + _t._lc=null; | |
197 | + } | |
198 | + ); | |
192 | 199 | }catch(e){ |
193 | 200 | throw new MI.MiMicException(e); |
194 | 201 | } |
@@ -14,8 +14,8 @@ var MI=MiMicJS; | ||
14 | 14 | * インスタンスをバインドするMCUオブジェクトです。 |
15 | 15 | * @param {PinName} i_params |
16 | 16 | * ピンIDを指定します。 |
17 | - * @param {HashMap|Generator} i_event | |
18 | - * 非同期イベントハンドラの連想配列、又はGeneratorです。 | |
17 | + * @param {HashMap|Generator|function} i_handler | |
18 | + * 非同期イベントハンドラの連想配列、Generator、コールバック関数の何れかを指定します。 | |
19 | 19 | * <p> |
20 | 20 | * 非同期イベントハンドラの場合、関数はイベントハンドラで結果を通知します。 |
21 | 21 | * <ul> |
@@ -34,7 +34,10 @@ var MI=MiMicJS; | ||
34 | 34 | * </ul> |
35 | 35 | * <p> |
36 | 36 | * Generatorを指定した場合、コールバック関数の引数はyiledの戻り値として取得できます。 |
37 | + * </p> | |
37 | 38 | * <p> |
39 | + * コールバック関数を指定した場合、RPCが完了したときに呼び出されます。メンバ関数のイベントハンドラは個別に設定する必要があります。 | |
40 | + * </p> | |
38 | 41 | * @return {mbedJS.DigitalIn} |
39 | 42 | * @example //Callback |
40 | 43 | * var mcu=new mbedJS.Mcu("192.168.128.39", |
@@ -78,17 +81,18 @@ var CLASS=function DigitalIn(i_mcu,i_params,i_handler) | ||
78 | 81 | var _t=this; |
79 | 82 | _t._mcu=i_mcu; |
80 | 83 | _t._lc=CLASS; |
81 | - if(MI.isGenerator(i_handler)){_t._gen=i_handler;} | |
82 | - else if(i_handler){_t._event=i_handler} | |
83 | - function cb(j) | |
84 | - { | |
85 | - _t._oid=j.result[0]; | |
86 | - if(_t._event.onNew){_t._event.onNew();} | |
87 | - if(_t._gen){_t._gen.next(_t);} | |
88 | - _t._lc=null; | |
89 | - } | |
84 | + var cb=MI._initHandler.call(_t,i_handler); | |
90 | 85 | MI.assertInt(i_params); |
91 | - return _t._mcu.rpc(_t.RPC_NS+":_new1",i_params,cb); | |
86 | + _t._mcu.rpc(_t.RPC_NS+":_new1",i_params, | |
87 | + function(j) | |
88 | + { | |
89 | + _t._oid=j.result[0]; | |
90 | + if(cb){cb();} | |
91 | + if(_t._gen){_t._gen.next(_t);} | |
92 | + _t._lc=null; | |
93 | + } | |
94 | + ); | |
95 | + | |
92 | 96 | }catch(e){ |
93 | 97 | throw new MI.MiMicException(e); |
94 | 98 | } |
@@ -135,13 +139,14 @@ CLASS.prototype= | ||
135 | 139 | { |
136 | 140 | try{ |
137 | 141 | var _t=this; |
138 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
142 | + var cb=MI._getCb(arguments,_t._event.onRead); | |
143 | + MI._assertYield.call(_t); | |
139 | 144 | _t._lc=CLASS.read; |
140 | 145 | return _t._mcu.rpc(_t.RPC_NS+":read",_t._oid, |
141 | 146 | function (j) |
142 | 147 | { |
143 | 148 | var v=j.result[0]; |
144 | - if(_t._event.onRead){_t._event.onRead(v);} | |
149 | + if(cb){cb(v);} | |
145 | 150 | if(_t._gen){_t._gen.next(v);} |
146 | 151 | _t._lc=null; |
147 | 152 | } |
@@ -165,14 +170,15 @@ CLASS.prototype= | ||
165 | 170 | { |
166 | 171 | try{ |
167 | 172 | var _t=this; |
168 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
173 | + var cb=MI._getCb(arguments,_t._event.onMode); | |
174 | + MI._assertYield.call(_t); | |
169 | 175 | _t._lc=CLASS.mode; |
170 | 176 | MI.assertInt(i_value); |
171 | 177 | return _t._mcu.rpc(_t.RPC_NS+":mode",_t._oid+","+i_value, |
172 | 178 | function (j) |
173 | 179 | { |
174 | 180 | var v=j.result[0]; |
175 | - if(_t._event.onMode){_t._event.onMode(v);} | |
181 | + if(cb){cb(v);} | |
176 | 182 | if(_t._gen){_t._gen.next(v);} |
177 | 183 | _t._lc=null; |
178 | 184 | } |
@@ -28,8 +28,8 @@ var MI=MiMicJS; | ||
28 | 28 | * <p>配列の場合は次の順番でパラメータを指定します。 |
29 | 29 | * <pre>{pin,value}</pre> |
30 | 30 | * </p> |
31 | - * @param {HashMap|Generator} i_event | |
32 | - * 非同期イベントハンドラの連想配列、又はGeneratorです。 | |
31 | + * @param {HashMap|Generator|function} i_handler | |
32 | + * 非同期イベントハンドラの連想配列、Generator、コールバック関数の何れかを指定します。 | |
33 | 33 | * <p> |
34 | 34 | * 非同期イベントハンドラの場合、関数はイベントハンドラで結果を通知します。 |
35 | 35 | * |
@@ -49,7 +49,10 @@ var MI=MiMicJS; | ||
49 | 49 | * </ul> |
50 | 50 | * <p> |
51 | 51 | * Generatorを指定した場合、コールバック関数の引数はyiledの戻り値として取得できます。 |
52 | + * </p> | |
52 | 53 | * <p> |
54 | + * コールバック関数を指定した場合、RPCが完了したときに呼び出されます。メンバ関数のイベントハンドラは個別に設定する必要があります。 | |
55 | + * </p> | |
53 | 56 | * @return {mbedJS.DigitalOut} |
54 | 57 | * @example //Callback |
55 | 58 | * var mcu=new mbedJS.Mcu("192.168.128.39", |
@@ -95,12 +98,11 @@ var CLASS=function DigitalOut(i_mcu,i_params,i_handler) | ||
95 | 98 | var _t=this; |
96 | 99 | _t._mcu=i_mcu; |
97 | 100 | _t._lc=CLASS; |
98 | - if(MI.isGenerator(i_handler)){_t._gen=i_handler;} | |
99 | - else if(i_handler){_t._event=i_handler} | |
100 | - function cb(j) | |
101 | + var cb=MI._initHandler.call(_t,i_handler); | |
102 | + function rcb(j) | |
101 | 103 | { |
102 | 104 | _t._oid=j.result[0]; |
103 | - if(_t._event.onNew){_t._event.onNew();} | |
105 | + if(cb){cb();} | |
104 | 106 | if(_t._gen){_t._gen.next(_t);} |
105 | 107 | _t._lc=null; |
106 | 108 | } |
@@ -116,9 +118,9 @@ var CLASS=function DigitalOut(i_mcu,i_params,i_handler) | ||
116 | 118 | MI.assertInt(pr[0]); |
117 | 119 | if(pr[1]){ |
118 | 120 | MI.assertInt(pr[1]); |
119 | - return _t._mcu.rpc(_t.RPC_NS+":_new2",pr[0]+","+pr[1],cb); | |
121 | + _t._mcu.rpc(_t.RPC_NS+":_new2",pr[0]+","+pr[1],rcb); | |
120 | 122 | }else{ |
121 | - return _t._mcu.rpc(_t.RPC_NS+":_new1",pr[0],cb); | |
123 | + _t._mcu.rpc(_t.RPC_NS+":_new1",pr[0],rcb); | |
122 | 124 | } |
123 | 125 | }catch(e){ |
124 | 126 | throw new MI.MiMicException(e); |
@@ -165,12 +167,13 @@ CLASS.prototype= | ||
165 | 167 | { |
166 | 168 | try{ |
167 | 169 | var _t=this; |
168 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
170 | + var cb=MI._getCb(arguments,_t._event.onWrite); | |
171 | + MI._assertYield.call(_t); | |
169 | 172 | _t._lc=CLASS.write; |
170 | 173 | MI.assertInt(i_value); |
171 | 174 | return _t._mcu.rpc(_t.RPC_NS+":write",_t._oid+","+i_value, |
172 | 175 | function(j){ |
173 | - if(_t._event.onWrite){_t._event.onWrite();} | |
176 | + if(cb){cb();} | |
174 | 177 | if(_t._gen){_t._gen.next();} |
175 | 178 | _t._lc=null; |
176 | 179 | }); |
@@ -193,13 +196,14 @@ CLASS.prototype= | ||
193 | 196 | { |
194 | 197 | try{ |
195 | 198 | var _t=this; |
196 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
199 | + var cb=MI._getCb(arguments,_t._event.onRead); | |
200 | + MI._assertYield.call(_t); | |
197 | 201 | _t._lc=CLASS.read; |
198 | 202 | return _t._mcu.rpc(_t.RPC_NS+":read",_t._oid, |
199 | 203 | function (j) |
200 | 204 | { |
201 | 205 | var v=j.result[0]; |
202 | - if(_t._event.onRead){_t._event.onRead(v);} | |
206 | + if(cb){cb(v);} | |
203 | 207 | if(_t._gen){_t._gen.next(v);} |
204 | 208 | _t._lc=null; |
205 | 209 | } |
@@ -14,8 +14,8 @@ var MI=MiMicJS; | ||
14 | 14 | * インスタンスをバインドするMCUオブジェクトです。 |
15 | 15 | * @param {[PinName,PinName]} i_params |
16 | 16 | * i2Cバスを構成するピンIDを指定します。sda,sclの順番です。 |
17 | - * @param {HashMap|Generator} i_event | |
18 | - * 非同期イベントハンドラの連想配列、又はGeneratorです。 | |
17 | + * @param {HashMap|Generator|function} i_handler | |
18 | + * 非同期イベントハンドラの連想配列、Generator、コールバック関数の何れかを指定します。 | |
19 | 19 | * <p> |
20 | 20 | * 非同期イベントハンドラの場合、関数はイベントハンドラで結果を通知します。 |
21 | 21 | * <ul> |
@@ -49,7 +49,10 @@ var MI=MiMicJS; | ||
49 | 49 | * </ul> |
50 | 50 | * <p> |
51 | 51 | * Generatorを指定した場合、コールバック関数の引数はyiledの戻り値として取得できます。 |
52 | + * </p> | |
52 | 53 | * <p> |
54 | + * コールバック関数を指定した場合、RPCが完了したときに呼び出されます。メンバ関数のイベントハンドラは個別に設定する必要があります。 | |
55 | + * </p> | |
53 | 56 | * @return {mbedJS.I2C} |
54 | 57 | * @example //Callback |
55 | 58 | * var st=0; |
@@ -126,17 +129,17 @@ var CLASS=function I2C(i_mcu,i_params,i_handler) | ||
126 | 129 | var _t=this; |
127 | 130 | _t._mcu=i_mcu; |
128 | 131 | _t._lc=CLASS; |
129 | - if(MI.isGenerator(i_handler)){_t._gen=i_handler;} | |
130 | - else if(i_handler){_t._event=i_handler} | |
131 | - function cb(j) | |
132 | - { | |
133 | - _t._oid=j.result[0]; | |
134 | - if(_t._event.onNew){_t._event.onNew();} | |
135 | - if(_t._gen){_t._gen.next(_t);} | |
136 | - _t._lc=null; | |
137 | - } | |
132 | + var cb=MI._initHandler.call(_t,i_handler); | |
138 | 133 | MI.assertInt(i_params); |
139 | - return _t._mcu.rpc(_t.RPC_NS+":_new1",i_params[0]+","+i_params[1],cb); | |
134 | + _t._mcu.rpc(_t.RPC_NS+":_new1",i_params[0]+","+i_params[1], | |
135 | + function (j) | |
136 | + { | |
137 | + _t._oid=j.result[0]; | |
138 | + if(cb){cb();} | |
139 | + if(_t._gen){_t._gen.next(_t);} | |
140 | + _t._lc=null; | |
141 | + } | |
142 | + ); | |
140 | 143 | }catch(e){ |
141 | 144 | throw new MI.MiMicException(e); |
142 | 145 | } |
@@ -183,16 +186,17 @@ CLASS.prototype= | ||
183 | 186 | { |
184 | 187 | try{ |
185 | 188 | var _t=this; |
186 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
189 | + var cb=MI._getCb(arguments,_t._event.onFrequency); | |
190 | + MI._assertYield.call(_t); | |
187 | 191 | _t._lc=CLASS.frequency; |
188 | 192 | MI.assertInt(i_hz); |
189 | 193 | return _t._mcu.rpc(_t.RPC_NS+":frequency",_t._oid+","+i_hz, |
190 | - function (j) | |
191 | - { | |
192 | - if(_t._event.onFrequency){_t._event.onFrequency();} | |
193 | - if(_t._gen){_t._gen.next();} | |
194 | - _t._lc=null; | |
195 | - } | |
194 | + function (j) | |
195 | + { | |
196 | + if(cb){cb();} | |
197 | + if(_t._gen){_t._gen.next();} | |
198 | + _t._lc=null; | |
199 | + } | |
196 | 200 | ); |
197 | 201 | }catch(e){ |
198 | 202 | throw new MI.MiMicException(e); |
@@ -243,21 +247,23 @@ CLASS.prototype= | ||
243 | 247 | { |
244 | 248 | try{ |
245 | 249 | var _t=this; |
246 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
250 | + var cb=MI._getCb(arguments,_t._event.onRead); | |
251 | + MI._assertYield.call(_t); | |
247 | 252 | _t._lc=CLASS.read; |
248 | - function cb(j){ | |
253 | + function rcb(j){ | |
249 | 254 | var v=j.result.length>1?{ret:j.result[0],data:MI.bstr2byteArray(j.result[1])}:j.result[0]; |
250 | - if(_t._event.onRead){_t._event.onRead(v);} | |
255 | + if(cb){cb(v);} | |
251 | 256 | if(_t._gen){_t._gen.next(v);} |
252 | 257 | _t._lc=null; |
253 | 258 | } |
254 | - if(arguments.length==1){ | |
259 | + //ベース引数の数で処理の切り替え | |
260 | + if(MI._getBaseArgsLen(arguments)==1){ | |
255 | 261 | MI.assertInt(arguments[0]); |
256 | - return _t._mcu.rpc(_t.RPC_NS+":read2",_t._oid+","+arguments[0],cb); | |
262 | + return _t._mcu.rpc(_t.RPC_NS+":read2",_t._oid+","+arguments[0],rcb); | |
257 | 263 | }else{ |
258 | 264 | var a=arguments; |
259 | 265 | MI.assertInt([a[0],a[1]]); |
260 | - return _t._mcu.rpc(_t.RPC_NS+":read1",_t._oid+","+a[0]+","+a[1]+","+(a[2]?1:0),cb); | |
266 | + return _t._mcu.rpc(_t.RPC_NS+":read1",_t._oid+","+a[0]+","+a[1]+","+(a[2]?1:0),rcb); | |
261 | 267 | } |
262 | 268 | }catch(e){ |
263 | 269 | throw new MI.MiMicException(e); |
@@ -303,21 +309,22 @@ CLASS.prototype= | ||
303 | 309 | { |
304 | 310 | try{ |
305 | 311 | var _t=this; |
306 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
312 | + var cb=MI._getCb(arguments,_t._event.onWrite); | |
313 | + MI._assertYield.call(_t); | |
307 | 314 | _t._lc=CLASS.write; |
308 | - function cb(j){ | |
315 | + function rcb(j){ | |
309 | 316 | var v=j.result[0]; |
310 | - if(_t._event.onWrite){_t._event.onWrite(v);} | |
317 | + if(cb){cb(v);} | |
311 | 318 | if(_t._gen){_t._gen.next(v);} |
312 | 319 | _t._lc=null; |
313 | 320 | } |
314 | - if(arguments.length==1){ | |
321 | + if(MI._getBaseArgsLen(arguments)==1){ | |
315 | 322 | MI.assertInt(arguments[0]); |
316 | - return _t._mcu.rpc(_t.RPC_NS+":write2",_t._oid+","+arguments[0],cb); | |
323 | + return _t._mcu.rpc(_t.RPC_NS+":write2",_t._oid+","+arguments[0],rcb); | |
317 | 324 | }else{ |
318 | 325 | var a=arguments; |
319 | 326 | MI.assertInt(a[0]); |
320 | - return _t._mcu.rpc(_t.RPC_NS+":write1",_t._oid+","+a[0]+",\""+MI.byteArray2bstr(a[1])+"\","+(a[2]?1:0),cb); | |
327 | + return _t._mcu.rpc(_t.RPC_NS+":write1",_t._oid+","+a[0]+",\""+MI.byteArray2bstr(a[1])+"\","+(a[2]?1:0),rcb); | |
321 | 328 | } |
322 | 329 | }catch(e){ |
323 | 330 | throw new MI.MiMicException(e); |
@@ -336,15 +343,16 @@ CLASS.prototype= | ||
336 | 343 | { |
337 | 344 | try{ |
338 | 345 | var _t=this; |
339 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
346 | + var cb=MI._getCb(arguments,_t._event.onStart); | |
347 | + MI._assertYield.call(_t); | |
340 | 348 | _t._lc=CLASS.start; |
341 | 349 | return _t._mcu.rpc(_t.RPC_NS+":start",_t._oid, |
342 | - function (j) | |
343 | - { | |
344 | - if(_t._event.onStart){_t._event.onStart();} | |
345 | - if(_t._gen){_t._gen.next();} | |
346 | - _t._lc=null; | |
347 | - } | |
350 | + function (j) | |
351 | + { | |
352 | + if(cb){cb();} | |
353 | + if(_t._gen){_t._gen.next();} | |
354 | + _t._lc=null; | |
355 | + } | |
348 | 356 | ); |
349 | 357 | }catch(e){ |
350 | 358 | throw new MI.MiMicException(e); |
@@ -363,15 +371,16 @@ CLASS.prototype= | ||
363 | 371 | { |
364 | 372 | try{ |
365 | 373 | var _t=this; |
366 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
367 | - _t._lc=CLASS.stop; | |
374 | + var cb=MI._getCb(arguments,_t._event.onStop); | |
375 | + MI._assertYield.call(_t); | |
376 | + _t._lc=CLASS.stop; | |
368 | 377 | return _t._mcu.rpc(_t.RPC_NS+":stop",_t._oid, |
369 | - function (j) | |
370 | - { | |
371 | - if(_t._event.onStop){_t._event.onStop();} | |
372 | - if(_t._gen){_t._gen.next();} | |
373 | - _t._lc=null; | |
374 | - } | |
378 | + function (j) | |
379 | + { | |
380 | + if(cb){cb();} | |
381 | + if(_t._gen){_t._gen.next();} | |
382 | + _t._lc=null; | |
383 | + } | |
375 | 384 | ); |
376 | 385 | }catch(e){ |
377 | 386 | throw new MI.MiMicException(e); |
@@ -14,8 +14,8 @@ var MI=MiMicJS; | ||
14 | 14 | * インスタンスをバインドするMCUオブジェクトです。 |
15 | 15 | * @param {[PinName,PinName]} i_params |
16 | 16 | * i2Cバスを構成するピンIDを指定します。sda,sclの順番です。 |
17 | - * @param {HashMap|Generator} i_event | |
18 | - * 非同期イベントハンドラの連想配列、又はGeneratorです。 | |
17 | + * @param {HashMap|Generator|function} i_handler | |
18 | + * 非同期イベントハンドラの連想配列、Generator、コールバック関数の何れかを指定します。 | |
19 | 19 | * <p> |
20 | 20 | * 非同期イベントハンドラの場合、関数はイベントハンドラで結果を通知します。 |
21 | 21 | * <ul> |
@@ -54,7 +54,10 @@ var MI=MiMicJS; | ||
54 | 54 | * </ul> |
55 | 55 | * <p> |
56 | 56 | * Generatorを指定した場合、コールバック関数の引数はyiledの戻り値として取得できます。 |
57 | + * </p> | |
57 | 58 | * <p> |
59 | + * コールバック関数を指定した場合、RPCが完了したときに呼び出されます。メンバ関数のイベントハンドラは個別に設定する必要があります。 | |
60 | + * </p> | |
58 | 61 | * @return {mbedJS.I2CSlave} |
59 | 62 | * @example //Callback |
60 | 63 | * var mcu=new mbedJS.Mcu("192.168.128.39", |
@@ -138,17 +141,17 @@ var CLASS=function I2CSlave(i_mcu,i_params,i_handler) | ||
138 | 141 | var _t=this; |
139 | 142 | _t._mcu=i_mcu; |
140 | 143 | _t._lc=CLASS; |
141 | - if(MI.isGenerator(i_handler)){_t._gen=i_handler;} | |
142 | - else if(i_handler){_t._event=i_handler} | |
143 | - function cb(j) | |
144 | - { | |
145 | - _t._oid=j.result[0]; | |
146 | - if(_t._event.onNew){_t._event.onNew();} | |
147 | - if(_t._gen){_t._gen.next(_t);} | |
148 | - _t._lc=null; | |
149 | - } | |
150 | - MI.assertInt(i_params); | |
151 | - return _t._mcu.rpc(_t.RPC_NS+":_new1",i_params[0]+","+i_params[1],cb); | |
144 | + var cb=MI._initHandler.call(_t,i_handler); | |
145 | + MI.assertInt(i_params); | |
146 | + _t._mcu.rpc(_t.RPC_NS+":_new1",i_params[0]+","+i_params[1], | |
147 | + function(j) | |
148 | + { | |
149 | + _t._oid=j.result[0]; | |
150 | + if(cb){cb();} | |
151 | + if(_t._gen){_t._gen.next(_t);} | |
152 | + _t._lc=null; | |
153 | + } | |
154 | + ); | |
152 | 155 | }catch(e){ |
153 | 156 | throw new MI.MiMicException(e); |
154 | 157 | } |
@@ -202,15 +205,17 @@ CLASS.prototype= | ||
202 | 205 | { |
203 | 206 | try{ |
204 | 207 | var _t=this; |
205 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
208 | + var cb=MI._getCb(arguments,_t._event.onAddress); | |
209 | + MI._assertYield.call(_t); | |
206 | 210 | _t._lc=CLASS.write; |
207 | 211 | MI.assertInt(i_value); |
208 | 212 | return _t._mcu.rpc(_t.RPC_NS+":address",_t._oid+","+i_value, |
209 | - function(j){ | |
210 | - if(_t._event.onAddress){_t._event.onAddress();} | |
211 | - if(_t._gen){_t._gen.next();} | |
212 | - _t._lc=null; | |
213 | - }); | |
213 | + function(j){ | |
214 | + if(cb){cb();} | |
215 | + if(_t._gen){_t._gen.next();} | |
216 | + _t._lc=null; | |
217 | + } | |
218 | + ); | |
214 | 219 | }catch(e){ |
215 | 220 | throw new MI.MiMicException(e); |
216 | 221 | } |
@@ -230,16 +235,17 @@ CLASS.prototype= | ||
230 | 235 | { |
231 | 236 | try{ |
232 | 237 | var _t=this; |
233 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
238 | + var cb=MI._getCb(arguments,_t._event.onFrequency); | |
239 | + MI._assertYield.call(_t); | |
234 | 240 | _t._lc=CLASS.frequency; |
235 | 241 | MI.assertInt(i_hz); |
236 | 242 | return _t._mcu.rpc(_t.RPC_NS+":frequency",_t._oid+","+i_hz, |
237 | - function (j) | |
238 | - { | |
239 | - if(_t._event.onFrequency){_t._event.onFrequency();} | |
240 | - if(_t._gen){_t._gen.next();} | |
241 | - _t._lc=null; | |
242 | - } | |
243 | + function (j) | |
244 | + { | |
245 | + if(cb){cb();} | |
246 | + if(_t._gen){_t._gen.next();} | |
247 | + _t._lc=null; | |
248 | + } | |
243 | 249 | ); |
244 | 250 | }catch(e){ |
245 | 251 | throw new MI.MiMicException(e); |
@@ -283,19 +289,20 @@ CLASS.prototype= | ||
283 | 289 | { |
284 | 290 | try{ |
285 | 291 | var _t=this; |
286 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
292 | + var cb=MI._getCb(arguments,_t._event.onRead); | |
293 | + MI._assertYield.call(_t); | |
287 | 294 | _t._lc=CLASS.read; |
288 | - function cb(j){ | |
295 | + function rcb(j){ | |
289 | 296 | var v=j.result.length>1?{ret:j.result[0],data:MI.bstr2byteArray(j.result[1])}:j.result[0]; |
290 | - if(_t._event.onRead){_t._event.onRead(v);} | |
297 | + if(cb){cb(v);} | |
291 | 298 | if(_t._gen){_t._gen.next(v);} |
292 | 299 | _t._lc=null; |
293 | 300 | } |
294 | - if(arguments.length==0){ | |
295 | - return _t._mcu.rpc(_t.RPC_NS+":read2",_t._oid,cb); | |
301 | + if(MI._getBaseArgsLen(arguments)==0){ | |
302 | + return _t._mcu.rpc(_t.RPC_NS+":read2",_t._oid,rcb); | |
296 | 303 | }else{ |
297 | 304 | MI.assertInt(arguments[0]); |
298 | - return _t._mcu.rpc(_t.RPC_NS+":read1",_t._oid+","+arguments[0],cb); | |
305 | + return _t._mcu.rpc(_t.RPC_NS+":read1",_t._oid+","+arguments[0],rcb); | |
299 | 306 | } |
300 | 307 | }catch(e){ |
301 | 308 | throw new MI.MiMicException(e); |
@@ -316,16 +323,17 @@ CLASS.prototype= | ||
316 | 323 | { |
317 | 324 | try{ |
318 | 325 | var _t=this; |
319 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
326 | + var cb=MI._getCb(arguments,_t._event.onReceive); | |
327 | + MI._assertYield.call(_t); | |
320 | 328 | _t._lc=CLASS.start; |
321 | 329 | return _t._mcu.rpc(_t.RPC_NS+":receive",_t._oid, |
322 | - function (j) | |
323 | - { | |
324 | - var v=j.result[0]; | |
325 | - if(_t._event.onReceive){_t._event.onReceive(v);} | |
326 | - if(_t._gen){_t._gen.next(v);} | |
327 | - _t._lc=null; | |
328 | - } | |
330 | + function (j) | |
331 | + { | |
332 | + var v=j.result[0]; | |
333 | + if(cb){cb(v);} | |
334 | + if(_t._gen){_t._gen.next(v);} | |
335 | + _t._lc=null; | |
336 | + } | |
329 | 337 | ); |
330 | 338 | }catch(e){ |
331 | 339 | throw new MI.MiMicException(e); |
@@ -335,8 +343,6 @@ CLASS.prototype= | ||
335 | 343 | * 引数が3個の場合 |
336 | 344 | * @name mbedJS.I2CSlave#write.1 |
337 | 345 | * @function |
338 | - * @param {int} address | |
339 | - * 8ビットのI2CSlaveSlaveアドレスです。 | |
340 | 346 | * @param {byte[]} data |
341 | 347 | * 送信するデータを格納したバイト配列です。 |
342 | 348 | * @return {int} |
@@ -368,20 +374,21 @@ CLASS.prototype= | ||
368 | 374 | { |
369 | 375 | try{ |
370 | 376 | var _t=this; |
371 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
377 | + var cb=MI._getCb(arguments,_t._event.onWrite); | |
378 | + MI._assertYield.call(_t); | |
372 | 379 | _t._lc=CLASS.write; |
373 | - function cb(j){ | |
380 | + function rcb(j){ | |
374 | 381 | var v=j.result[0]; |
375 | - if(_t._event.onWrite){_t._event.onWrite(v);} | |
382 | + if(cb){cb(v);} | |
376 | 383 | if(_t._gen){_t._gen.next(v);} |
377 | 384 | _t._lc=null; |
378 | 385 | } |
379 | 386 | if(!MI.isArray(arguments[0])){ |
380 | 387 | MI.assertInt(arguments[0]); |
381 | - return _t._mcu.rpc(_t.RPC_NS+":write2",_t._oid+","+arguments[0],cb); | |
388 | + return _t._mcu.rpc(_t.RPC_NS+":write2",_t._oid+","+arguments[0],rcb); | |
382 | 389 | }else{ |
383 | 390 | var a=arguments; |
384 | - return _t._mcu.rpc(_t.RPC_NS+":write1",_t._oid+",\""+MI.byteArray2bstr(a[0])+"\"",cb); | |
391 | + return _t._mcu.rpc(_t.RPC_NS+":write1",_t._oid+",\""+MI.byteArray2bstr(a[0])+"\"",rcb); | |
385 | 392 | } |
386 | 393 | }catch(e){ |
387 | 394 | throw new MI.MiMicException(e); |
@@ -400,15 +407,16 @@ CLASS.prototype= | ||
400 | 407 | { |
401 | 408 | try{ |
402 | 409 | var _t=this; |
403 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
410 | + var cb=MI._getCb(arguments,_t._event.onStop); | |
411 | + MI._assertYield.call(_t); | |
404 | 412 | _t._lc=CLASS.stop; |
405 | 413 | return _t._mcu.rpc(_t.RPC_NS+":stop",_t._oid, |
406 | - function (j) | |
407 | - { | |
408 | - if(_t._event.onStop){_t._event.onStop();} | |
409 | - if(_t._gen){_t._gen.next();} | |
410 | - _t._lc=null; | |
411 | - } | |
414 | + function (j) | |
415 | + { | |
416 | + if(cb){cb();} | |
417 | + if(_t._gen){_t._gen.next();} | |
418 | + _t._lc=null; | |
419 | + } | |
412 | 420 | ); |
413 | 421 | }catch(e){ |
414 | 422 | throw new MI.MiMicException(e); |
@@ -157,6 +157,7 @@ CLASS.prototype= | ||
157 | 157 | }, |
158 | 158 | /** |
159 | 159 | * コールバック関数を全てキャンセルして、Mcuとの接続をシャットダウンします。 |
160 | + * この関数は即座に完了します。 | |
160 | 161 | * @name mbedJS.Mcu#shutdown |
161 | 162 | * @function |
162 | 163 | */ |
@@ -220,6 +221,9 @@ CLASS.prototype= | ||
220 | 221 | * 指定idのオブジェクトをMCUのメモリから削除します。 |
221 | 222 | * @name mbedJS.Mcu#disposeObject |
222 | 223 | * @function |
224 | + * @param {int} i_oid | |
225 | + * オブジェクトID。 | |
226 | + * mbedJSオブジェクトが所有するリモートオブジェクトのIDを指定します。 | |
223 | 227 | * @return {boolean} |
224 | 228 | * 結果を返します。 |
225 | 229 | */ |
@@ -12,8 +12,8 @@ var MI=MiMicJS; | ||
12 | 12 | * @constructor |
13 | 13 | * @param {mbedJS.Mcu} i_mcu |
14 | 14 | * インスタンスをバインドするMCUオブジェクトです。 |
15 | - * @param {HashMap|Generator} i_event | |
16 | - * 非同期イベントハンドラの連想配列、又はGeneratorです。 | |
15 | + * @param {HashMap|Generator|function} i_handler | |
16 | + * 非同期イベントハンドラの連想配列、Generator、コールバック関数の何れかを指定します。 | |
17 | 17 | * <p> |
18 | 18 | * 非同期イベントハンドラの場合、関数はイベントハンドラで結果を通知します。 |
19 | 19 | * <ul> |
@@ -41,7 +41,10 @@ var MI=MiMicJS; | ||
41 | 41 | * </ul> |
42 | 42 | * <p> |
43 | 43 | * Generatorを指定した場合、コールバック関数の引数はyiledの戻り値として取得できます。 |
44 | + * </p> | |
44 | 45 | * <p> |
46 | + * コールバック関数を指定した場合、RPCが完了したときに呼び出されます。メンバ関数のイベントハンドラは個別に設定する必要があります。 | |
47 | + * </p> | |
45 | 48 | * @return {mbedJS.Memory} |
46 | 49 | * @example //Callback |
47 | 50 | * var s=0; |
@@ -166,15 +169,15 @@ var CLASS=function Memory(i_mcu,i_handler) | ||
166 | 169 | var _t=this; |
167 | 170 | _t._mcu=i_mcu; |
168 | 171 | _t._lc=CLASS; |
169 | - if(MI.isGenerator(i_handler)){_t._gen=i_handler;} | |
170 | - else if(i_handler){_t._event=i_handler} | |
171 | - function cb(j) | |
172 | - { | |
173 | - if(_t._event.onNew){_t._event.onNew();} | |
174 | - if(_t._gen){_t._gen.next(_t);} | |
175 | - _t._lc=null; | |
176 | - } | |
177 | - return _t._mcu.rpc(_t.RPC_NS+":init","",cb); | |
172 | + var cb=MI._initHandler.call(_t,i_handler); | |
173 | + _t._mcu.rpc(_t.RPC_NS+":init","", | |
174 | + function(j) | |
175 | + { | |
176 | + if(cb){cb();} | |
177 | + if(_t._gen){_t._gen.next(_t);} | |
178 | + _t._lc=null; | |
179 | + } | |
180 | + ); | |
178 | 181 | }catch(e){ |
179 | 182 | throw new MI.MiMicException(e); |
180 | 183 | } |
@@ -225,15 +228,16 @@ CLASS.prototype= | ||
225 | 228 | //read(i_addr,i_len) |
226 | 229 | try{ |
227 | 230 | var _t=this; |
228 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
231 | + var cb=MI._getCb(arguments,_t._event.onRead); | |
232 | + MI._assertYield.call(_t); | |
229 | 233 | _t._lc=CLASS.read; |
230 | - var a=[i_addr,MI.isUndefined(i_size,1)]; | |
234 | + var a=[i_addr,(MI._getBaseArgsLen(arguments)==1)?i_size:1]; | |
231 | 235 | MI.assertInt(a); |
232 | 236 | return _t._mcu.rpc(_t.RPC_NS+":read",a[0]+","+a[1], |
233 | 237 | function (j) |
234 | 238 | { |
235 | 239 | var v=MI.bstr2byteArray(j.result[0]); |
236 | - if(_t._event.onRead){_t._event.onRead(v);} | |
240 | + if(cb){cb(v);} | |
237 | 241 | if(_t._gen){_t._gen.next(v);} |
238 | 242 | _t._lc=null; |
239 | 243 | }); |
@@ -259,17 +263,18 @@ CLASS.prototype= | ||
259 | 263 | { |
260 | 264 | try{ |
261 | 265 | var _t=this; |
262 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
266 | + var cb=MI._getCb(arguments,_t._event.onWrite); | |
267 | + MI._assertYield.call(_t); | |
263 | 268 | _t._lc=CLASS.write; |
264 | 269 | MI.assertInt(i_addr); |
265 | 270 | MI.assertInt(i_v); |
266 | 271 | return _t._mcu.rpc(_t.RPC_NS+":write",i_addr+",\""+MI.byteArray2bstr(i_v)+"\"", |
267 | - function (j) | |
268 | - { | |
269 | - if(_t._event.onWrite){_t._event.onWrite();} | |
270 | - if(_t._gen){_t._gen.next();} | |
271 | - _t._lc=null; | |
272 | - } | |
272 | + function (j) | |
273 | + { | |
274 | + if(cb){cb();} | |
275 | + if(_t._gen){_t._gen.next();} | |
276 | + _t._lc=null; | |
277 | + } | |
273 | 278 | ); |
274 | 279 | }catch(e){ |
275 | 280 | throw new MI.MiMicException(e); |
@@ -296,21 +301,24 @@ CLASS.prototype= | ||
296 | 301 | //read(i_addr,i_len) |
297 | 302 | try{ |
298 | 303 | var _t=this; |
299 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
304 | + var cb=MI._getCb(arguments,_t._event.onRead32); | |
305 | + MI._assertYield.call(_t); | |
300 | 306 | _t._lc=CLASS.read32; |
301 | - var a=[i_addr,MI.isUndefined(i_size,4)]; | |
307 | + | |
308 | + var a=[i_addr,(MI._getBaseArgsLen(arguments)==1)?4:i_size]; | |
302 | 309 | if(a[1]%4!=0){ |
303 | 310 | throw new MI.MiMicException(MI.Error.NG_INVALID_ARG); |
304 | 311 | } |
305 | 312 | MI.assertInt(a); |
306 | 313 | return _t._mcu.rpc(_t.RPC_NS+":read",a[0]+","+a[1], |
307 | - function (j) | |
308 | - { | |
309 | - var v=MI.bstr2uintArray(j.result[0]); | |
310 | - if(_t._event.onRead32){_t._event.onRead32(v);} | |
311 | - if(_t._gen){_t._gen.next(v);} | |
312 | - _t._lc=null; | |
313 | - }); | |
314 | + function (j) | |
315 | + { | |
316 | + var v=MI.bstr2uintArray(j.result[0]); | |
317 | + if(cb){cb(v);} | |
318 | + if(_t._gen){_t._gen.next(v);} | |
319 | + _t._lc=null; | |
320 | + } | |
321 | + ); | |
314 | 322 | }catch(e){ |
315 | 323 | throw new MI.MiMicException(e); |
316 | 324 | } |
@@ -333,17 +341,18 @@ CLASS.prototype= | ||
333 | 341 | { |
334 | 342 | try{ |
335 | 343 | var _t=this; |
336 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
344 | + var cb=MI._getCb(arguments,_t._event.onWrite32); | |
345 | + MI._assertYield.call(_t); | |
337 | 346 | _t._lc=CLASS.write32; |
338 | 347 | MI.assertInt(i_addr); |
339 | 348 | MI.assertInt(i_v); |
340 | 349 | return _t._mcu.rpc(_t.RPC_NS+":write",i_addr+",\""+MI.uintArray2bstr(i_v)+"\"", |
341 | - function (j) | |
342 | - { | |
343 | - if(_t._event.onWrite){_t._event.onWrite32();} | |
344 | - if(_t._gen){_t._gen.next();} | |
345 | - _t._lc=null; | |
346 | - } | |
350 | + function (j) | |
351 | + { | |
352 | + if(cb){cb();} | |
353 | + if(_t._gen){_t._gen.next();} | |
354 | + _t._lc=null; | |
355 | + } | |
347 | 356 | ); |
348 | 357 | }catch(e){ |
349 | 358 | throw new MI.MiMicException(e); |
@@ -25,8 +25,8 @@ var MI=MiMicJS; | ||
25 | 25 | * <p>配列の場合は次の順番でパラメータを指定します。 |
26 | 26 | * <pre>{port,mask}</pre> |
27 | 27 | * </p> |
28 | - * @param {HashMap|Generator} i_event | |
29 | - * 非同期イベントハンドラの連想配列、又はGeneratorです。 | |
28 | + * @param {HashMap|Generator|function} i_handler | |
29 | + * 非同期イベントハンドラの連想配列、Generator、コールバック関数の何れかを指定します。 | |
30 | 30 | * <p> |
31 | 31 | * 非同期イベントハンドラの場合、関数はイベントハンドラで結果を通知します。 |
32 | 32 | * <ul> |
@@ -42,7 +42,10 @@ var MI=MiMicJS; | ||
42 | 42 | * </ul> |
43 | 43 | * <p> |
44 | 44 | * Generatorを指定した場合、コールバック関数の引数はyiledの戻り値として取得できます。 |
45 | + * </p> | |
45 | 46 | * <p> |
47 | + * コールバック関数を指定した場合、RPCが完了したときに呼び出されます。メンバ関数のイベントハンドラは個別に設定する必要があります。 | |
48 | + * </p> | |
46 | 49 | * @return {mbedJS.PortIn} |
47 | 50 | * @example //Callback |
48 | 51 | * var mcu=new mbedJS.Mcu("192.168.128.39", |
@@ -87,15 +90,7 @@ var CLASS=function PortIn(i_mcu,i_params,i_handler) | ||
87 | 90 | var _t=this; |
88 | 91 | _t._mcu=i_mcu; |
89 | 92 | _t._lc=CLASS; |
90 | - if(MI.isGenerator(i_handler)){_t._gen=i_handler;} | |
91 | - else if(i_handler){_t._event=i_handler} | |
92 | - function cb(j) | |
93 | - { | |
94 | - _t._oid=j.result[0]; | |
95 | - if(_t._event.onNew){_t._event.onNew();} | |
96 | - if(_t._gen){_t._gen.next(_t);} | |
97 | - _t._lc=null; | |
98 | - } | |
93 | + var cb=MI._initHandler.call(_t,i_handler); | |
99 | 94 | //引数の正規化 |
100 | 95 | var pr; |
101 | 96 | if(MI.isHashArray(i_params)){ |
@@ -104,7 +99,15 @@ var CLASS=function PortIn(i_mcu,i_params,i_handler) | ||
104 | 99 | pr=i_params; |
105 | 100 | } |
106 | 101 | MI.assertInt(pr); |
107 | - return _t._mcu.rpc(_t.RPC_NS+":_new1",pr[0]+","+pr[1],cb); | |
102 | + _t._mcu.rpc(_t.RPC_NS+":_new1",pr[0]+","+pr[1], | |
103 | + function(j) | |
104 | + { | |
105 | + _t._oid=j.result[0]; | |
106 | + if(cb){cb();} | |
107 | + if(_t._gen){_t._gen.next(_t);} | |
108 | + _t._lc=null; | |
109 | + } | |
110 | + ); | |
108 | 111 | }catch(e){ |
109 | 112 | throw new MI.MiMicException(e); |
110 | 113 | } |
@@ -151,16 +154,18 @@ CLASS.prototype= | ||
151 | 154 | { |
152 | 155 | try{ |
153 | 156 | var _t=this; |
154 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
157 | + var cb=MI._getCb(arguments,_t._event.onRead); | |
158 | + MI._assertYield.call(_t); | |
155 | 159 | _t._lc=CLASS.read; |
156 | 160 | return _t._mcu.rpc(_t.RPC_NS+":read",_t._oid, |
157 | - function (j) | |
158 | - { | |
159 | - var v=j.result[0]; | |
160 | - if(_t._event.onRead){_t._event.onRead(v);} | |
161 | - if(_t._gen){_t._gen.next(v);} | |
162 | - _t._lc=null; | |
163 | - }); | |
161 | + function (j) | |
162 | + { | |
163 | + var v=j.result[0]; | |
164 | + if(cb){cb(v);} | |
165 | + if(_t._gen){_t._gen.next(v);} | |
166 | + _t._lc=null; | |
167 | + } | |
168 | + ); | |
164 | 169 | }catch(e){ |
165 | 170 | throw new MI.MiMicException(e); |
166 | 171 | } |
@@ -25,8 +25,8 @@ var MI=MiMicJS; | ||
25 | 25 | * <p>配列の場合は次の順番でパラメータを指定します。 |
26 | 26 | * <pre>{port,mask}</pre> |
27 | 27 | * </p> |
28 | - * @param {HashMap|Generator} i_event | |
29 | - * 非同期イベントハンドラの連想配列、又はGeneratorです。 | |
28 | + * @param {HashMap|Generator|function} i_handler | |
29 | + * 非同期イベントハンドラの連想配列、Generator、コールバック関数の何れかを指定します。 | |
30 | 30 | * <p> |
31 | 31 | * 非同期イベントハンドラの場合、関数はイベントハンドラで結果を通知します。 |
32 | 32 | * <ul> |
@@ -45,7 +45,10 @@ var MI=MiMicJS; | ||
45 | 45 | * </ul> |
46 | 46 | * <p> |
47 | 47 | * Generatorを指定した場合、コールバック関数の引数はyiledの戻り値として取得できます。 |
48 | + * </p> | |
48 | 49 | * <p> |
50 | + * コールバック関数を指定した場合、RPCが完了したときに呼び出されます。メンバ関数のイベントハンドラは個別に設定する必要があります。 | |
51 | + * </p> | |
49 | 52 | * @return {mbedJS.PortOut} |
50 | 53 | * @example //Callback |
51 | 54 | * var mcu=new mbedJS.Mcu("192.168.128.39", |
@@ -91,15 +94,7 @@ var CLASS=function PortOut(i_mcu,i_params,i_handler) | ||
91 | 94 | var _t=this; |
92 | 95 | _t._mcu=i_mcu; |
93 | 96 | _t._lc=CLASS; |
94 | - if(MI.isGenerator(i_handler)){_t._gen=i_handler;} | |
95 | - else if(i_handler){_t._event=i_handler} | |
96 | - function cb(j) | |
97 | - { | |
98 | - _t._oid=j.result[0]; | |
99 | - if(_t._event.onNew){_t._event.onNew();} | |
100 | - if(_t._gen){_t._gen.next(_t);} | |
101 | - _t._lc=null; | |
102 | - } | |
97 | + var cb=MI._initHandler.call(_t,i_handler); | |
103 | 98 | //引数の正規化 |
104 | 99 | var pr; |
105 | 100 | if(MI.isHashArray(i_params)){ |
@@ -108,7 +103,15 @@ var CLASS=function PortOut(i_mcu,i_params,i_handler) | ||
108 | 103 | pr=i_params; |
109 | 104 | } |
110 | 105 | MI.assertInt(pr); |
111 | - return _t._mcu.rpc(_t.RPC_NS+":_new1",pr[0]+","+pr[1],cb); | |
106 | + _t._mcu.rpc(_t.RPC_NS+":_new1",pr[0]+","+pr[1], | |
107 | + function(j) | |
108 | + { | |
109 | + _t._oid=j.result[0]; | |
110 | + if(cb){cb();} | |
111 | + if(_t._gen){_t._gen.next(_t);} | |
112 | + _t._lc=null; | |
113 | + } | |
114 | + ); | |
112 | 115 | }catch(e){ |
113 | 116 | throw new MI.MiMicException(e); |
114 | 117 | } |
@@ -154,15 +157,17 @@ CLASS.prototype= | ||
154 | 157 | { |
155 | 158 | try{ |
156 | 159 | var _t=this; |
157 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
160 | + var cb=MI._getCb(arguments,_t._event.onWrite); | |
161 | + MI._assertYield.call(_t); | |
158 | 162 | _t._lc=CLASS.write; |
159 | 163 | MI.assertInt(i_value); |
160 | 164 | return _t._mcu.rpc(_t.RPC_NS+":write",_t._oid+","+i_value, |
161 | - function(j){ | |
162 | - if(_t._event.onWrite){_t._event.onWrite();} | |
163 | - if(_t._gen){_t._gen.next();} | |
164 | - _t._lc=null; | |
165 | - }); | |
165 | + function(j){ | |
166 | + if(cb){cb();} | |
167 | + if(_t._gen){_t._gen.next();} | |
168 | + _t._lc=null; | |
169 | + } | |
170 | + ); | |
166 | 171 | }catch(e){ |
167 | 172 | throw new MI.MiMicException(e); |
168 | 173 | } |
@@ -182,16 +187,18 @@ CLASS.prototype= | ||
182 | 187 | { |
183 | 188 | try{ |
184 | 189 | var _t=this; |
185 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
190 | + var cb=MI._getCb(arguments,_t._event.onRead); | |
191 | + MI._assertYield.call(_t); | |
186 | 192 | _t._lc=CLASS.read; |
187 | 193 | return _t._mcu.rpc(_t.RPC_NS+":read",_t._oid, |
188 | - function (j) | |
189 | - { | |
190 | - var v=j.result[0]; | |
191 | - if(_t._event.onRead){_t._event.onRead(v);} | |
192 | - if(_t._gen){_t._gen.next(v);} | |
193 | - _t._lc=null; | |
194 | - }); | |
194 | + function (j) | |
195 | + { | |
196 | + var v=j.result[0]; | |
197 | + if(cb){cb(v);} | |
198 | + if(_t._gen){_t._gen.next(v);} | |
199 | + _t._lc=null; | |
200 | + } | |
201 | + ); | |
195 | 202 | }catch(e){ |
196 | 203 | throw new MI.MiMicException(e); |
197 | 204 | } |
@@ -14,8 +14,8 @@ var MI=MiMicJS; | ||
14 | 14 | * インスタンスをバインドするMCUオブジェクトです。 |
15 | 15 | * @param {PinName} i_params |
16 | 16 | * ピンIDを指定します。 |
17 | - * @param {HashMap|Generator} i_event | |
18 | - * 非同期イベントハンドラの連想配列、又はGeneratorです。 | |
17 | + * @param {HashMap|Generator|function} i_handler | |
18 | + * 非同期イベントハンドラの連想配列、Generator、コールバック関数の何れかを指定します。 | |
19 | 19 | * <p> |
20 | 20 | * 非同期イベントハンドラの場合、関数はイベントハンドラで結果を通知します。 |
21 | 21 | * <ul> |
@@ -52,7 +52,10 @@ var MI=MiMicJS; | ||
52 | 52 | * </ul> |
53 | 53 | * <p> |
54 | 54 | * Generatorを指定した場合、コールバック関数の引数はyiledの戻り値として取得できます。 |
55 | + * </p> | |
55 | 56 | * <p> |
57 | + * コールバック関数を指定した場合、RPCが完了したときに呼び出されます。メンバ関数のイベントハンドラは個別に設定する必要があります。 | |
58 | + * </p> | |
56 | 59 | * @return {mbedJS.PwmOut} |
57 | 60 | * @example //Callback |
58 | 61 | * var mcu=new mbedJS.Mcu("192.168.128.39", |
@@ -122,17 +125,17 @@ var CLASS=function PwmOut(i_mcu,i_params,i_handler) | ||
122 | 125 | var _t=this; |
123 | 126 | _t._mcu=i_mcu; |
124 | 127 | _t._lc=CLASS; |
125 | - if(MI.isGenerator(i_handler)){_t._gen=i_handler;} | |
126 | - else if(i_handler){_t._event=i_handler} | |
127 | - function cb(j) | |
128 | - { | |
129 | - _t._oid=j.result[0]; | |
130 | - if(_t._event.onNew){_t._event.onNew();} | |
131 | - if(_t._gen){_t._gen.next(_t);} | |
132 | - _t._lc=null; | |
133 | - } | |
128 | + var cb=MI._initHandler.call(_t,i_handler); | |
134 | 129 | MI.assertInt(i_params); |
135 | - return _t._mcu.rpc(_t.RPC_NS+":_new1",i_params,cb); | |
130 | + _t._mcu.rpc(_t.RPC_NS+":_new1",i_params, | |
131 | + function(j) | |
132 | + { | |
133 | + _t._oid=j.result[0]; | |
134 | + if(cb){cb();} | |
135 | + if(_t._gen){_t._gen.next(_t);} | |
136 | + _t._lc=null; | |
137 | + } | |
138 | + ); | |
136 | 139 | }catch(e){ |
137 | 140 | throw new MI.MiMicException(e); |
138 | 141 | } |
@@ -180,12 +183,13 @@ CLASS.prototype= | ||
180 | 183 | { |
181 | 184 | try{ |
182 | 185 | var _t=this; |
183 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
186 | + var cb=MI._getCb(arguments,_t._event.onWrite); | |
187 | + MI._assertYield.call(_t); | |
184 | 188 | _t._lc=CLASS.write; |
185 | 189 | MI.assertNumber(i_value); |
186 | 190 | return _t._mcu.rpc(_t.RPC_NS+":write_fx",_t._oid+","+Math.round(i_value*10000), |
187 | 191 | function(j){ |
188 | - if(_t._event.onWrite){_t._event.onWrite();} | |
192 | + if(cb){cb();} | |
189 | 193 | if(_t._gen){_t._gen.next();} |
190 | 194 | _t._lc=null; |
191 | 195 | }); |
@@ -207,13 +211,14 @@ CLASS.prototype= | ||
207 | 211 | { |
208 | 212 | try{ |
209 | 213 | var _t=this; |
210 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
214 | + var cb=MI._getCb(arguments,_t._event.onRead); | |
215 | + MI._assertYield.call(_t); | |
211 | 216 | _t._lc=CLASS.read; |
212 | 217 | return _t._mcu.rpc(_t.RPC_NS+":read_fx",_t._oid, |
213 | 218 | function (j) |
214 | 219 | { |
215 | 220 | var v=j.result[0]/10000; |
216 | - if(_t._event.onRead){_t._event.onRead(v);} | |
221 | + if(cb){cb(v);} | |
217 | 222 | if(_t._gen){_t._gen.next(v);} |
218 | 223 | _t._lc=null; |
219 | 224 | }); |
@@ -237,12 +242,13 @@ CLASS.prototype= | ||
237 | 242 | { |
238 | 243 | try{ |
239 | 244 | var _t=this; |
240 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
245 | + var cb=MI._getCb(arguments,_t._event.onPeriod); | |
246 | + MI._assertYield.call(_t); | |
241 | 247 | _t._lc=CLASS.period; |
242 | 248 | MI.assertInt(i_value); |
243 | 249 | return _t._mcu.rpc(_t.RPC_NS+":period_fx",_t._oid+","+Math.round(i_value*10000), |
244 | 250 | function(j){ |
245 | - if(_t._event.onPeriod){_t._event.onPeriod();} | |
251 | + if(cb){cb();} | |
246 | 252 | if(_t._gen){_t._gen.next();} |
247 | 253 | _t._lc=null; |
248 | 254 | }); |
@@ -266,12 +272,13 @@ CLASS.prototype= | ||
266 | 272 | { |
267 | 273 | try{ |
268 | 274 | var _t=this; |
269 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
275 | + var cb=MI._getCb(arguments,_t._event.onPeriod_ms); | |
276 | + MI._assertYield.call(_t); | |
270 | 277 | _t._lc=CLASS.period_ms; |
271 | 278 | MI.assertInt(i_value); |
272 | 279 | return _t._mcu.rpc(_t.RPC_NS+":period_ms",_t._oid+","+Math.round(i_value), |
273 | 280 | function(j){ |
274 | - if(_t._event.onPeriod_ms){_t._event.onPeriod_ms();} | |
281 | + if(cb){cb();} | |
275 | 282 | if(_t._gen){_t._gen.next();} |
276 | 283 | _t._lc=null; |
277 | 284 | }); |
@@ -295,12 +302,13 @@ CLASS.prototype= | ||
295 | 302 | { |
296 | 303 | try{ |
297 | 304 | var _t=this; |
298 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
305 | + var cb=MI._getCb(arguments,_t._event.onPeriod_us); | |
306 | + MI._assertYield.call(_t); | |
299 | 307 | _t._lc=CLASS.period_us; |
300 | 308 | MI.assertInt(i_value); |
301 | 309 | return _t._mcu.rpc(_t.RPC_NS+":period_us",_t._oid+","+Math.round(i_value), |
302 | 310 | function(j){ |
303 | - if(_t._event.onPeriod_us){_t._event.onPeriod_us();} | |
311 | + if(cb){cb();} | |
304 | 312 | if(_t._gen){_t._gen.next();} |
305 | 313 | _t._lc=null; |
306 | 314 | }); |
@@ -324,12 +332,13 @@ CLASS.prototype= | ||
324 | 332 | { |
325 | 333 | try{ |
326 | 334 | var _t=this; |
327 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
335 | + var cb=MI._getCb(arguments,_t._event.onPulsewidth); | |
336 | + MI._assertYield.call(_t); | |
328 | 337 | _t._lc=CLASS.pulsewidth; |
329 | 338 | MI.assertInt(i_value); |
330 | 339 | return _t._mcu.rpc(_t.RPC_NS+":pulsewidth_fx",_t._oid+","+Math.round(i_value*10000), |
331 | 340 | function(j){ |
332 | - if(_t._event.onPulsewidth){_t._event.onPulsewidth();} | |
341 | + if(cb){cb();} | |
333 | 342 | if(_t._gen){_t._gen.next();} |
334 | 343 | _t._lc=null; |
335 | 344 | }); |
@@ -352,15 +361,17 @@ CLASS.prototype= | ||
352 | 361 | { |
353 | 362 | try{ |
354 | 363 | var _t=this; |
355 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
364 | + var cb=MI._getCb(arguments,_t._event.onPulsewidth_ms); | |
365 | + MI._assertYield.call(_t); | |
356 | 366 | _t._lc=CLASS.pulsewidth_ms; |
357 | 367 | MI.assertInt(i_value); |
358 | 368 | return _t._mcu.rpc(_t.RPC_NS+":pulsewidth_ms",_t._oid+","+Math.round(i_value), |
359 | - function(j){ | |
360 | - if(_t._event.onPulsewidth_ms){_t._event.onPulsewidth_ms();} | |
361 | - if(_t._gen){_t._gen.next();} | |
362 | - _t._lc=null; | |
363 | - }); | |
369 | + function(j){ | |
370 | + if(cb){cb();} | |
371 | + if(_t._gen){_t._gen.next();} | |
372 | + _t._lc=null; | |
373 | + } | |
374 | + ); | |
364 | 375 | }catch(e){ |
365 | 376 | throw new MI.MiMicException(e); |
366 | 377 | } |
@@ -380,15 +391,17 @@ CLASS.prototype= | ||
380 | 391 | { |
381 | 392 | try{ |
382 | 393 | var _t=this; |
383 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
394 | + var cb=MI._getCb(arguments,_t._event.onPulsewidth_us); | |
395 | + MI._assertYield.call(_t); | |
384 | 396 | _t._lc=CLASS.pulsewidth_us; |
385 | 397 | MI.assertInt(i_value); |
386 | 398 | return _t._mcu.rpc(_t.RPC_NS+":pulsewidth_us",_t._oid+","+Math.round(i_value), |
387 | - function(j){ | |
388 | - if(_t._event.onPulsewidth_us){_t._event.onPulsewidth_us();} | |
389 | - if(_t._gen){_t._gen.next();} | |
390 | - _t._lc=null; | |
391 | - }); | |
399 | + function(j){ | |
400 | + if(cb){cb();} | |
401 | + if(_t._gen){_t._gen.next();} | |
402 | + _t._lc=null; | |
403 | + } | |
404 | + ); | |
392 | 405 | }catch(e){ |
393 | 406 | throw new MI.MiMicException(e); |
394 | 407 | } |
@@ -14,8 +14,8 @@ var MI=MiMicJS; | ||
14 | 14 | * インスタンスをバインドするMCUオブジェクトです。 |
15 | 15 | * @param {[PinName,PinName,PinName]} i_params |
16 | 16 | * SPIを構成する3つのPinNameを格納する配列です。mosi,miso,sclkの順番です。 |
17 | - * @param {HashMap|Generator} i_event | |
18 | - * 非同期イベントハンドラの連想配列、又はGeneratorです。 | |
17 | + * @param {HashMap|Generator|function} i_handler | |
18 | + * 非同期イベントハンドラの連想配列、Generator、コールバック関数の何れかを指定します。 | |
19 | 19 | * <p> |
20 | 20 | * 非同期イベントハンドラの場合、関数はイベントハンドラで結果を通知します。 |
21 | 21 | * <ul> |
@@ -37,7 +37,10 @@ var MI=MiMicJS; | ||
37 | 37 | * </ul> |
38 | 38 | * <p> |
39 | 39 | * Generatorを指定した場合、コールバック関数の引数はyiledの戻り値として取得できます。 |
40 | + * </p> | |
40 | 41 | * <p> |
42 | + * コールバック関数を指定した場合、RPCが完了したときに呼び出されます。メンバ関数のイベントハンドラは個別に設定する必要があります。 | |
43 | + * </p> | |
41 | 44 | * @return {mbedJS.SPI} |
42 | 45 | * @example //Callback |
43 | 46 | * var mcu=new mbedJS.Mcu("192.168.128.39", |
@@ -87,17 +90,17 @@ var CLASS=function SPI(i_mcu,i_params,i_handler) | ||
87 | 90 | var _t=this; |
88 | 91 | _t._mcu=i_mcu; |
89 | 92 | _t._lc=CLASS; |
90 | - if(MI.isGenerator(i_handler)){_t._gen=i_handler;} | |
91 | - else if(i_handler){_t._event=i_handler} | |
92 | - function cb(j) | |
93 | - { | |
94 | - _t._oid=j.result[0]; | |
95 | - if(_t._event.onNew){_t._event.onNew();} | |
96 | - if(_t._gen){_t._gen.next(_t);} | |
97 | - _t._lc=null; | |
98 | - } | |
93 | + var cb=MI._initHandler.call(_t,i_handler); | |
99 | 94 | MI.assertInt(i_params); |
100 | - return _t._mcu.rpc(_t.RPC_NS+":_new1",i_params[0]+","+i_params[1]+","+i_params[2]+","+NS.PinName.NC,cb); | |
95 | + _t._mcu.rpc(_t.RPC_NS+":_new1",i_params[0]+","+i_params[1]+","+i_params[2]+","+NS.PinName.NC, | |
96 | + function(j) | |
97 | + { | |
98 | + _t._oid=j.result[0]; | |
99 | + if(cb){cb();} | |
100 | + if(_t._gen){_t._gen.next(_t);} | |
101 | + _t._lc=null; | |
102 | + } | |
103 | + ); | |
101 | 104 | }catch(e){ |
102 | 105 | throw new MI.MiMicException(e); |
103 | 106 | } |
@@ -144,16 +147,18 @@ CLASS.prototype= | ||
144 | 147 | { |
145 | 148 | try{ |
146 | 149 | var _t=this; |
147 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
150 | + MI._assertYield.call(_t); | |
151 | + var cb=MI._getCb(arguments,_t._event.onWrite); | |
148 | 152 | _t._lc=CLASS.write; |
149 | 153 | MI.assertInt(i_value); |
150 | 154 | return _t._mcu.rpc(_t.RPC_NS+":write",_t._oid+","+i_value, |
151 | - function(j){ | |
152 | - var v=j.result[0]; | |
153 | - if(_t._event.onWrite){_t._event.onWrite(v);} | |
154 | - if(_t._gen){_t._gen.next(v);} | |
155 | - _t._lc=null; | |
156 | - }); | |
155 | + function(j){ | |
156 | + var v=j.result[0]; | |
157 | + if(cb){cb(v);} | |
158 | + if(_t._gen){_t._gen.next(v);} | |
159 | + _t._lc=null; | |
160 | + } | |
161 | + ); | |
157 | 162 | }catch(e){ |
158 | 163 | throw new MI.MiMicException(e); |
159 | 164 | } |
@@ -173,15 +178,17 @@ CLASS.prototype= | ||
173 | 178 | { |
174 | 179 | try{ |
175 | 180 | var _t=this; |
176 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
181 | + MI._assertYield.call(_t); | |
182 | + var cb=MI._getCb(arguments,_t._event.onFrequency); | |
177 | 183 | _t._lc=CLASS.frequency; |
178 | 184 | MI.assertInt(i_value); |
179 | 185 | return _t._mcu.rpc(_t.RPC_NS+":frequency",_t._oid+","+i_value, |
180 | - function(j){ | |
181 | - if(_t._event.onFrequency){_t._event.onFrequency();} | |
182 | - if(_t._gen){_t._gen.next();} | |
183 | - _t._lc=null; | |
184 | - }); | |
186 | + function(j){ | |
187 | + if(cb){cb();} | |
188 | + if(_t._gen){_t._gen.next();} | |
189 | + _t._lc=null; | |
190 | + } | |
191 | + ); | |
185 | 192 | }catch(e){ |
186 | 193 | throw new MI.MiMicException(e); |
187 | 194 | } |
@@ -202,16 +209,18 @@ CLASS.prototype= | ||
202 | 209 | { |
203 | 210 | try{ |
204 | 211 | var _t=this; |
205 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
212 | + MI._assertYield.call(_t); | |
213 | + var cb=MI._getCb(arguments,_t._event.onFormat); | |
206 | 214 | _t._lc=CLASS.format; |
207 | 215 | var mode=i_mode?i_mode:0; |
208 | 216 | MI.assertInt([i_bits,mode]); |
209 | 217 | return _t._mcu.rpc(_t.RPC_NS+":format",_t._oid+","+i_bits+","+mode, |
210 | - function(j){ | |
211 | - if(_t._event.onFormat){_t._event.onFormat();} | |
212 | - if(_t._gen){_t._gen.next();} | |
213 | - _t._lc=null; | |
214 | - }); | |
218 | + function(j){ | |
219 | + if(cb){cb();} | |
220 | + if(_t._gen){_t._gen.next();} | |
221 | + _t._lc=null; | |
222 | + } | |
223 | + ); | |
215 | 224 | }catch(e){ |
216 | 225 | throw new MI.MiMicException(e); |
217 | 226 | } |
@@ -15,8 +15,8 @@ var MI=MiMicJS; | ||
15 | 15 | * @param {[PinName,PinName,PinName]} i_params |
16 | 16 | * SPIを構成する4つのPinNameを格納する配列です。 |
17 | 17 | * mosi, miso, sclkの順番で設定します。 |
18 | - * @param {HashMap|Generator} i_event | |
19 | - * 非同期イベントハンドラの連想配列、又はGeneratorです。 | |
18 | + * @param {HashMap|Generator|function} i_handler | |
19 | + * 非同期イベントハンドラの連想配列、Generator、コールバック関数の何れかを指定します。 | |
20 | 20 | * <p> |
21 | 21 | * 非同期イベントハンドラの場合、関数はイベントハンドラで結果を通知します。 |
22 | 22 | * <ul> |
@@ -44,7 +44,10 @@ var MI=MiMicJS; | ||
44 | 44 | * </ul> |
45 | 45 | * <p> |
46 | 46 | * Generatorを指定した場合、コールバック関数の引数はyiledの戻り値として取得できます。 |
47 | + * </p> | |
47 | 48 | * <p> |
49 | + * コールバック関数を指定した場合、RPCが完了したときに呼び出されます。メンバ関数のイベントハンドラは個別に設定する必要があります。 | |
50 | + * </p> | |
48 | 51 | * @return {mbedJS.SPI} |
49 | 52 | * @example //Callback |
50 | 53 | * var mcu=new mbedJS.Mcu("192.168.128.39", |
@@ -104,17 +107,17 @@ var CLASS=function SPISlave(i_mcu,i_params,i_handler) | ||
104 | 107 | var _t=this; |
105 | 108 | _t._mcu=i_mcu; |
106 | 109 | _t._lc=CLASS; |
107 | - if(MI.isGenerator(i_handler)){_t._gen=i_handler;} | |
108 | - else if(i_handler){_t._event=i_handler} | |
109 | - function cb(j) | |
110 | - { | |
111 | - _t._oid=j.result[0]; | |
112 | - if(_t._event.onNew){_t._event.onNew();} | |
113 | - if(_t._gen){_t._gen.next(_t);} | |
114 | - _t._lc=null; | |
115 | - } | |
110 | + var cb=MI._initHandler.call(_t,i_handler); | |
116 | 111 | MI.assertInt(i_params); |
117 | - return _t._mcu.rpc(_t.RPC_NS+":_new1",i_params[0]+","+i_params[1]+","+i_params[2]+","+i_params[3],cb); | |
112 | + _t._mcu.rpc(_t.RPC_NS+":_new1",i_params[0]+","+i_params[1]+","+i_params[2]+","+i_params[3], | |
113 | + function(j) | |
114 | + { | |
115 | + _t._oid=j.result[0]; | |
116 | + if(cb){cb();} | |
117 | + if(_t._gen){_t._gen.next(_t);} | |
118 | + _t._lc=null; | |
119 | + } | |
120 | + ); | |
118 | 121 | }catch(e){ |
119 | 122 | throw new MI.MiMicException(e); |
120 | 123 | } |
@@ -162,12 +165,13 @@ CLASS.prototype= | ||
162 | 165 | { |
163 | 166 | try{ |
164 | 167 | var _t=this; |
165 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
168 | + MI._assertYield.call(_t); | |
169 | + var cb=MI._getCb(arguments,_t._event.onFrequency); | |
166 | 170 | _t._lc=CLASS.frequency; |
167 | 171 | MI.assertInt(i_value); |
168 | 172 | return _t._mcu.rpc(_t.RPC_NS+":frequency",_t._oid+","+i_value, |
169 | 173 | function(j){ |
170 | - if(_t._event.onFrequency){_t._event.onFrequency();} | |
174 | + if(cb){cb();} | |
171 | 175 | if(_t._gen){_t._gen.next();} |
172 | 176 | _t._lc=null; |
173 | 177 | }); |
@@ -191,13 +195,14 @@ CLASS.prototype= | ||
191 | 195 | { |
192 | 196 | try{ |
193 | 197 | var _t=this; |
194 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
198 | + MI._assertYield.call(_t); | |
199 | + var cb=MI._getCb(arguments,_t._event.onFormat); | |
195 | 200 | _t._lc=CLASS.format; |
196 | 201 | var mode=i_mode?i_mode:0; |
197 | 202 | MI.assertInt([i_bits,mode]); |
198 | 203 | return _t._mcu.rpc(_t.RPC_NS+":format",_t._oid+","+i_bits+","+mode, |
199 | 204 | function(j){ |
200 | - if(_t._event.onFormat){_t._event.onFormat();} | |
205 | + if(cb){cb();} | |
201 | 206 | if(_t._gen){_t._gen.next();} |
202 | 207 | _t._lc=null; |
203 | 208 | }); |
@@ -220,13 +225,14 @@ CLASS.prototype= | ||
220 | 225 | { |
221 | 226 | try{ |
222 | 227 | var _t=this; |
223 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
228 | + MI._assertYield.call(_t); | |
229 | + var cb=MI._getCb(arguments,_t._event.onRead); | |
224 | 230 | _t._lc=CLASS.read; |
225 | 231 | return _t._mcu.rpc(_t.RPC_NS+":read",_t._oid, |
226 | 232 | function (j) |
227 | 233 | { |
228 | 234 | var v=j.result[0]; |
229 | - if(_t._event.onRead){_t._event.onRead(v);} | |
235 | + if(cb){cb(v);} | |
230 | 236 | if(_t._gen){_t._gen.next(v);} |
231 | 237 | _t._lc=null; |
232 | 238 | }); |
@@ -249,13 +255,14 @@ CLASS.prototype= | ||
249 | 255 | { |
250 | 256 | try{ |
251 | 257 | var _t=this; |
252 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
258 | + MI._assertYield.call(_t); | |
259 | + var cb=MI._getCb(arguments,_t._event.onReceive); | |
253 | 260 | _t._lc=CLASS.receive; |
254 | 261 | return _t._mcu.rpc(_t.RPC_NS+":receive",_t._oid, |
255 | 262 | function (j) |
256 | 263 | { |
257 | 264 | var v=j.result[0]; |
258 | - if(_t._event.onReceive){_t._event.onReceive(v);} | |
265 | + if(cb){cb(v);} | |
259 | 266 | if(_t._gen){_t._gen.next(v);} |
260 | 267 | _t._lc=null; |
261 | 268 | }); |
@@ -278,13 +285,14 @@ CLASS.prototype= | ||
278 | 285 | { |
279 | 286 | try{ |
280 | 287 | var _t=this; |
281 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
288 | + MI._assertYield.call(_t); | |
289 | + var cb=MI._getCb(arguments,_t._event.onReply); | |
282 | 290 | _t._lc=CLASS.reply; |
283 | 291 | MI.assertInt(i_value); |
284 | 292 | return _t._mcu.rpc(_t.RPC_NS+":reply",_t._oid+","+i_value, |
285 | 293 | function (j) |
286 | 294 | { |
287 | - if(_t._event.onReply){_t._event.onReply();} | |
295 | + if(cb){cb();} | |
288 | 296 | if(_t._gen){_t._gen.next();} |
289 | 297 | _t._lc=null; |
290 | 298 | }); |
@@ -14,8 +14,8 @@ var MI=MiMicJS; | ||
14 | 14 | * インスタンスをバインドするMCUオブジェクトです。 |
15 | 15 | * @param {[PinName,PinName]} i_params |
16 | 16 | * UARTを構成する2本のピンを指定します。tx,rxの順で設定します。 |
17 | - * @param {HashMap|Generator} i_event | |
18 | - * 非同期イベントハンドラの連想配列、又はGeneratorです。 | |
17 | + * @param {HashMap|Generator|function} i_handler | |
18 | + * 非同期イベントハンドラの連想配列、Generator、コールバック関数の何れかを指定します。 | |
19 | 19 | * <p> |
20 | 20 | * 非同期イベントハンドラの場合、関数はイベントハンドラで結果を通知します。 |
21 | 21 | * <ul> |
@@ -70,7 +70,10 @@ var MI=MiMicJS; | ||
70 | 70 | * </ul> |
71 | 71 | * <p> |
72 | 72 | * Generatorを指定した場合、コールバック関数の引数はyiledの戻り値として取得できます。 |
73 | + * </p> | |
73 | 74 | * <p> |
75 | + * コールバック関数を指定した場合、RPCが完了したときに呼び出されます。メンバ関数のイベントハンドラは個別に設定する必要があります。 | |
76 | + * </p> | |
74 | 77 | * @return {mbedJS.Serial} |
75 | 78 | * @example //Callback |
76 | 79 | * var mcu=new mbedJS.Mcu("192.168.128.39", |
@@ -146,19 +149,21 @@ var CLASS=function Serial(i_mcu,i_params,i_handler) | ||
146 | 149 | { |
147 | 150 | try{ |
148 | 151 | var _t=this; |
152 | + var cb; | |
149 | 153 | _t._mcu=i_mcu; |
150 | 154 | _t._lc=CLASS; |
151 | - if(MI.isGenerator(i_handler)){_t._gen=i_handler;} | |
152 | - else if(i_handler){_t._event=i_handler} | |
153 | - function cb(j) | |
154 | - { | |
155 | - _t._oid=j.result[0]; | |
156 | - if(_t._event.onNew){_t._event.onNew();} | |
157 | - if(_t._gen){_t._gen.next(_t);} | |
158 | - _t._lc=null; | |
159 | - } | |
155 | + //ハンドラの初期化 | |
156 | + var cb=MI._initHandler.call(_t,i_handler); | |
160 | 157 | MI.assertInt(i_params); |
161 | - _t._mcu.rpc(_t.RPC_NS+":_new1",i_params[0]+","+i_params[1],cb); | |
158 | + _t._mcu.rpc(_t.RPC_NS+":_new1",i_params[0]+","+i_params[1], | |
159 | + function(j) | |
160 | + { | |
161 | + _t._oid=j.result[0]; | |
162 | + if(cb){cb();} | |
163 | + if(_t._gen){_t._gen.next(_t);} | |
164 | + _t._lc=null; | |
165 | + } | |
166 | + ); | |
162 | 167 | }catch(e){ |
163 | 168 | throw new MI.MiMicException(e); |
164 | 169 | } |
@@ -218,17 +223,18 @@ CLASS.prototype= | ||
218 | 223 | { |
219 | 224 | try{ |
220 | 225 | var _t=this; |
221 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
226 | + MI._assertYield.call(_t); | |
227 | + var cb=MI._getCb(arguments,_t._event.onFormat); | |
222 | 228 | _t._lc=CLASS.format; |
223 | 229 | var p=[MI.isUndefined(i_bits,8),MI.isUndefined(i_parity,_t.Parity.None),MI.isUndefined(i_stop_bits,1)]; |
224 | 230 | MI.assertInt(p); |
225 | 231 | return _t._mcu.rpc(_t.RPC_NS+":format",_t._oid+","+p[0]+","+p[1]+","+p[2], |
226 | - function (j) | |
227 | - { | |
228 | - if(_t._event.onFormat){_t._event.onFormat();} | |
229 | - if(_t._gen){_t._gen.next();} | |
230 | - _t._lc=null; | |
231 | - } | |
232 | + function (j) | |
233 | + { | |
234 | + if(cb){cb();} | |
235 | + if(_t._gen){_t._gen.next();} | |
236 | + _t._lc=null; | |
237 | + } | |
232 | 238 | ); |
233 | 239 | }catch(e){ |
234 | 240 | throw new MI.MiMicException(e); |
@@ -249,16 +255,17 @@ CLASS.prototype= | ||
249 | 255 | { |
250 | 256 | try{ |
251 | 257 | var _t=this; |
252 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
258 | + MI._assertYield.call(_t); | |
259 | + var cb=MI._getCb(arguments,_t._event.onReadable); | |
253 | 260 | _t._lc=CLASS.readable; |
254 | 261 | return _t._mcu.rpc(_t.RPC_NS+":readable",_t._oid, |
255 | - function (j) | |
256 | - { | |
257 | - var v=j.result[0]; | |
258 | - if(_t._event.onReadable){_t._event.onReadable(v);} | |
259 | - if(_t._gen){_t._gen.next(v);} | |
260 | - _t._lc=null; | |
261 | - } | |
262 | + function (j) | |
263 | + { | |
264 | + var v=j.result[0]; | |
265 | + if(cb){cb(v);} | |
266 | + if(_t._gen){_t._gen.next(v);} | |
267 | + _t._lc=null; | |
268 | + } | |
262 | 269 | ); |
263 | 270 | }catch(e){ |
264 | 271 | throw new MI.MiMicException(e); |
@@ -279,16 +286,17 @@ CLASS.prototype= | ||
279 | 286 | { |
280 | 287 | try{ |
281 | 288 | var _t=this; |
282 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
289 | + MI._assertYield.call(_t); | |
290 | + var cb=MI._getCb(arguments,_t._event.onWriteable); | |
283 | 291 | _t._lc=CLASS.writeable; |
284 | 292 | return _t._mcu.rpc(_t.RPC_NS+":writeable",_t._oid, |
285 | - function (j) | |
286 | - { | |
287 | - var v=j.result[0]?true:false; | |
288 | - if(_t._event.onWriteable){_t._event.onWriteable(v);} | |
289 | - if(_t._gen){_t._gen.next(v);} | |
290 | - _t._lc=null; | |
291 | - } | |
293 | + function (j) | |
294 | + { | |
295 | + var v=j.result[0]?true:false; | |
296 | + if(cb){cb(v);} | |
297 | + if(_t._gen){_t._gen.next(v);} | |
298 | + _t._lc=null; | |
299 | + } | |
292 | 300 | ); |
293 | 301 | }catch(e){ |
294 | 302 | throw new MI.MiMicException(e); |
@@ -307,15 +315,16 @@ CLASS.prototype= | ||
307 | 315 | { |
308 | 316 | try{ |
309 | 317 | var _t=this; |
310 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
318 | + MI._assertYield.call(_t); | |
319 | + var cb=MI._getCb(arguments,_t._event.onSend_break); | |
311 | 320 | _t._lc=CLASS.send_break; |
312 | 321 | return _t._mcu.rpc(_t.RPC_NS+":send_break",_t._oid, |
313 | - function (j) | |
314 | - { | |
315 | - if(_t._event.onSend_break){_t._event.onSend_break();} | |
316 | - if(_t._gen){_t._gen.next();} | |
317 | - _t._lc=null; | |
318 | - } | |
322 | + function (j) | |
323 | + { | |
324 | + if(cb){cb();} | |
325 | + if(_t._gen){_t._gen.next();} | |
326 | + _t._lc=null; | |
327 | + } | |
319 | 328 | ); |
320 | 329 | }catch(e){ |
321 | 330 | throw new MI.MiMicException(e); |
@@ -336,17 +345,18 @@ CLASS.prototype= | ||
336 | 345 | { |
337 | 346 | try{ |
338 | 347 | var _t=this; |
339 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
348 | + MI._assertYield.call(_t); | |
349 | + var cb=MI._getCb(arguments,_t._event.onPutc); | |
340 | 350 | _t._lc=CLASS.putc; |
341 | 351 | MI.assertInt(i_c); |
342 | 352 | return _t._mcu.rpc(_t.RPC_NS+":putc",_t._oid+","+i_c, |
343 | - function (j) | |
344 | - { | |
345 | - var v=j.result[0]; | |
346 | - if(_t._event.onPutc){_t._event.onPutc(v);} | |
347 | - if(_t._gen){_t._gen.next(v);} | |
348 | - _t._lc=null; | |
349 | - } | |
353 | + function (j) | |
354 | + { | |
355 | + var v=j.result[0]; | |
356 | + if(cb){cb(v);} | |
357 | + if(_t._gen){_t._gen.next(v);} | |
358 | + _t._lc=null; | |
359 | + } | |
350 | 360 | ); |
351 | 361 | }catch(e){ |
352 | 362 | throw new MI.MiMicException(e); |
@@ -367,16 +377,17 @@ CLASS.prototype= | ||
367 | 377 | { |
368 | 378 | try{ |
369 | 379 | var _t=this; |
370 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
380 | + MI._assertYield.call(_t); | |
381 | + var cb=MI._getCb(arguments,_t._event.onPuts); | |
371 | 382 | _t._lc=CLASS.puts; |
372 | 383 | return _t._mcu.rpc(_t.RPC_NS+":puts",_t._oid+",\""+i_s+"\"", |
373 | - function (j) | |
374 | - { | |
375 | - var v=j.result[0]; | |
376 | - if(_t._event.onPuts){_t._event.onPuts(v);} | |
377 | - if(_t._gen){_t._gen.next(v);} | |
378 | - _t._lc=null; | |
379 | - } | |
384 | + function (j) | |
385 | + { | |
386 | + var v=j.result[0]; | |
387 | + if(cb){cb(v);} | |
388 | + if(_t._gen){_t._gen.next(v);} | |
389 | + _t._lc=null; | |
390 | + } | |
380 | 391 | ); |
381 | 392 | }catch(e){ |
382 | 393 | throw new MI.MiMicException(e); |
@@ -397,16 +408,17 @@ CLASS.prototype= | ||
397 | 408 | { |
398 | 409 | try{ |
399 | 410 | var _t=this; |
400 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
411 | + MI._assertYield.call(_t); | |
412 | + var cb=MI._getCb(arguments,_t._event.onGetc); | |
401 | 413 | _t._lc=CLASS.getc; |
402 | 414 | return _t._mcu.rpc(_t.RPC_NS+":getc",_t._oid, |
403 | - function (j) | |
404 | - { | |
405 | - var v=j.result[0]; | |
406 | - if(_t._event.onGetc){_t._event.onGetc(v);} | |
407 | - if(_t._gen){_t._gen.next(v);} | |
408 | - _t._lc=null; | |
409 | - } | |
415 | + function (j) | |
416 | + { | |
417 | + var v=j.result[0]; | |
418 | + if(cb){cb(v);} | |
419 | + if(_t._gen){_t._gen.next(v);} | |
420 | + _t._lc=null; | |
421 | + } | |
410 | 422 | ); |
411 | 423 | }catch(e){ |
412 | 424 | throw new MI.MiMicException(e); |
@@ -429,17 +441,18 @@ CLASS.prototype= | ||
429 | 441 | { |
430 | 442 | try{ |
431 | 443 | var _t=this; |
432 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
444 | + MI._assertYield.call(_t); | |
445 | + var cb=MI._getCb(arguments,_t._event.onGets); | |
433 | 446 | _t._lc=CLASS.gets; |
434 | 447 | MI.assertInt(i_len); |
435 | 448 | return _t._mcu.rpc(_t.RPC_NS+":gets",_t._oid+","+i_len, |
436 | - function (j) | |
437 | - { | |
438 | - var v=j.result[0]; | |
439 | - if(_t._event.onGets){_t._event.onGets(v);} | |
440 | - if(_t._gen){_t._gen.next(v);} | |
441 | - _t._lc=null; | |
442 | - } | |
449 | + function (j) | |
450 | + { | |
451 | + var v=j.result[0]; | |
452 | + if(cb){cb(v);} | |
453 | + if(_t._gen){_t._gen.next(v);} | |
454 | + _t._lc=null; | |
455 | + } | |
443 | 456 | ); |
444 | 457 | }catch(e){ |
445 | 458 | throw new MI.MiMicException(e); |
@@ -460,16 +473,17 @@ CLASS.prototype= | ||
460 | 473 | { |
461 | 474 | try{ |
462 | 475 | var _t=this; |
463 | - if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
476 | + MI._assertYield.call(_t); | |
477 | + var cb=MI._getCb(arguments,_t._event.onBaud); | |
464 | 478 | _t._lc=CLASS.baud; |
465 | 479 | MI.assertInt(i_baudrate); |
466 | 480 | return _t._mcu.rpc(_t.RPC_NS+":baud",_t._oid+","+i_baudrate, |
467 | - function (j) | |
468 | - { | |
469 | - if(_t._event.onBaud){_t._event.onBaud();} | |
470 | - if(_t._gen){_t._gen.next();} | |
471 | - _t._lc=null; | |
472 | - } | |
481 | + function (j) | |
482 | + { | |
483 | + if(cb){cb();} | |
484 | + if(_t._gen){_t._gen.next();} | |
485 | + _t._lc=null; | |
486 | + } | |
473 | 487 | ); |
474 | 488 | }catch(e){ |
475 | 489 | throw new MI.MiMicException(e); |
@@ -62,6 +62,35 @@ function async() | ||
62 | 62 | }); |
63 | 63 | } |
64 | 64 | |
65 | +function async2() | |
66 | +{ | |
67 | + log(); | |
68 | + log("ASYNC2"); | |
69 | + var mcu=new mbedJS.Mcu("192.168.128.39", | |
70 | + { | |
71 | + onNew:function(){ | |
72 | + var pin=new mbedJS.AnalogIn(mcu,mbedJS.PinName.A0, | |
73 | + function(){ | |
74 | + log("[PASS]onNew"); | |
75 | + pin.read(function(v) | |
76 | + { | |
77 | + log("[PASS]onread:"+v); | |
78 | + pin.read_u16(function(v){ | |
79 | + log("[PASS]onRead_u16:"+v); | |
80 | + mcu.close(); | |
81 | + }); | |
82 | + }); | |
83 | + }); | |
84 | + }, | |
85 | + onClose:function(){ | |
86 | + log("[PASS]onClose"); | |
87 | + }, | |
88 | + onError:function(){ | |
89 | + alert("Error"); | |
90 | + } | |
91 | + }); | |
92 | +} | |
93 | + | |
65 | 94 | /** |
66 | 95 | * 誤った使用方法でExceptionが出た場合にシャットダウンできるかのテスト |
67 | 96 | */ |
@@ -101,6 +130,7 @@ function sync() | ||
101 | 130 | <h1>AnalogIn test</h1> |
102 | 131 | <hr/> |
103 | 132 | <button onclick="async();">ASYNC</button> |
133 | +<button onclick="async2();">ASYNC2</button> | |
104 | 134 | <button onclick="sync();">SYNC</button> |
105 | 135 | <textarea id="console" rows="15" cols="80"></textarea> |
106 | 136 | </body> |
\ No newline at end of file |
@@ -69,7 +69,38 @@ function async() | ||
69 | 69 | } |
70 | 70 | }); |
71 | 71 | } |
72 | - | |
72 | +function async2() | |
73 | +{ | |
74 | + log(); | |
75 | + log("ASYNC"); | |
76 | + var mcu=new mbedJS.Mcu("192.168.128.39", | |
77 | + { | |
78 | + onNew:function(){ | |
79 | + var pin=new mbedJS.AnalogOut(mcu,mbedJS.PinName.p18,function(){ | |
80 | + log("[PASS]onNew"); | |
81 | + pin.write(0.5,function() | |
82 | + { | |
83 | + log("[PASS]onWrite"); | |
84 | + pin.read(function(v) | |
85 | + { | |
86 | + log("[PASS]onread:"+v); | |
87 | + pin.write_u16(0,function() | |
88 | + { | |
89 | + log("[PASS]onWrite_u16:"); | |
90 | + mcu.close(); | |
91 | + }); | |
92 | + }); | |
93 | + }); | |
94 | + }); | |
95 | + }, | |
96 | + onClose:function(){ | |
97 | + log("[PASS]onClose"); | |
98 | + }, | |
99 | + onError:function(){ | |
100 | + alert("Error"); | |
101 | + } | |
102 | + }); | |
103 | +} | |
73 | 104 | /** |
74 | 105 | * 誤った使用方法でExceptionが出た場合にシャットダウンできるかのテスト |
75 | 106 | */ |
@@ -113,6 +144,7 @@ function sync() | ||
113 | 144 | <h1>Analogout test</h1> |
114 | 145 | <hr/> |
115 | 146 | <button onclick="async();">ASYNC</button> |
147 | +<button onclick="async2();">ASYNC2</button> | |
116 | 148 | <button onclick="sync();">SYNC</button> |
117 | 149 | <textarea id="console" rows="15" cols="80"></textarea> |
118 | 150 | </body> |
\ No newline at end of file |
@@ -61,6 +61,33 @@ function async() | ||
61 | 61 | } |
62 | 62 | }); |
63 | 63 | } |
64 | +function async2() | |
65 | +{ | |
66 | + log(); | |
67 | + log("ASYNC2"); | |
68 | + var mcu=new mbedJS.Mcu("192.168.128.39", | |
69 | + { | |
70 | + onNew:function(){ | |
71 | + var pin=new mbedJS.BusIn(mcu,[mbedJS.PinName.P0_21,mbedJS.PinName.P0_22],function(){ | |
72 | + log("[PASS]onNew"); | |
73 | + pin.read(function(v) | |
74 | + { | |
75 | + log("[PASS]onread:"+v); | |
76 | + pin.mode(mbedJS.PinMode.PullDown,function(v){ | |
77 | + log("[PASS]onMode:"); | |
78 | + mcu.close(); | |
79 | + }); | |
80 | + }); | |
81 | + }); | |
82 | + }, | |
83 | + onClose:function(){ | |
84 | + log("[PASS]onClose"); | |
85 | + }, | |
86 | + onError:function(){ | |
87 | + alert("Error"); | |
88 | + } | |
89 | + }); | |
90 | +} | |
64 | 91 | |
65 | 92 | /** |
66 | 93 | * 誤った使用方法でExceptionが出た場合にシャットダウンできるかのテスト |
@@ -101,6 +128,7 @@ function sync() | ||
101 | 128 | <h1>BusIn test</h1> |
102 | 129 | <hr/> |
103 | 130 | <button onclick="async();">ASYNC</button> |
131 | +<button onclick="async2();">ASYNC2</button> | |
104 | 132 | <button onclick="sync();">SYNC</button> |
105 | 133 | <textarea id="console" rows="15" cols="80"></textarea> |
106 | 134 | </body> |
\ No newline at end of file |
@@ -77,6 +77,48 @@ function async() | ||
77 | 77 | }); |
78 | 78 | } |
79 | 79 | |
80 | +function async2() | |
81 | +{ | |
82 | + log(); | |
83 | + log("ASYNC2"); | |
84 | + var mcu=new mbedJS.Mcu("192.168.128.39", | |
85 | + { | |
86 | + onNew:function(){ | |
87 | + var bus=new mbedJS.BusInOut(mcu,[mbedJS.PinName.P0_21,mbedJS.PinName.P0_22],function(){ | |
88 | + log("[PASS]onNew"); | |
89 | + bus.mode(mbedJS.PinMode.PullDown,function() | |
90 | + { | |
91 | + log("[PASS]onMode"); | |
92 | + bus.output(function() | |
93 | + { | |
94 | + log("[PASS]onOutput:"); | |
95 | + bus.write(1,function() | |
96 | + { | |
97 | + log("[PASS]onWrite:"); | |
98 | + bus.input(function(){ | |
99 | + log("[PASS]onInput:"); | |
100 | + bus.read(function(v) | |
101 | + { | |
102 | + log("[PASS]onRead:"+v); | |
103 | + mcu.close(); | |
104 | + }); | |
105 | + }); | |
106 | + }); | |
107 | + }); | |
108 | + }); | |
109 | + }); | |
110 | + }, | |
111 | + onClose:function(){ | |
112 | + log("[PASS]onClose"); | |
113 | + }, | |
114 | + onError:function(){ | |
115 | + alert("Error"); | |
116 | + } | |
117 | + }); | |
118 | +} | |
119 | + | |
120 | + | |
121 | + | |
80 | 122 | /** |
81 | 123 | * 誤った使用方法でExceptionが出た場合にシャットダウンできるかのテスト |
82 | 124 | */ |
@@ -120,6 +162,7 @@ function sync() | ||
120 | 162 | <h1>BusInOut test</h1> |
121 | 163 | <hr/> |
122 | 164 | <button onclick="async();">ASYNC</button> |
165 | +<button onclick="async2();">ASYNC2</button> | |
123 | 166 | <button onclick="sync();">SYNC</button> |
124 | 167 | <textarea id="console" rows="15" cols="80"></textarea> |
125 | 168 | </body> |
\ No newline at end of file |
@@ -63,6 +63,34 @@ function async() | ||
63 | 63 | }); |
64 | 64 | } |
65 | 65 | |
66 | +function async2() | |
67 | +{ | |
68 | + log(); | |
69 | + log("ASYNC2"); | |
70 | + var mcu=new mbedJS.Mcu("192.168.128.39", | |
71 | + { | |
72 | + onNew:function(){ | |
73 | + var bus=new mbedJS.BusOut(mcu,[mbedJS.PinName.P0_21,mbedJS.PinName.P0_22],function(){ | |
74 | + log("[PASS]onNew"); | |
75 | + bus.write(2,function() | |
76 | + { | |
77 | + log("[PASS]onWrite:"); | |
78 | + bus.read(function(v){ | |
79 | + log("[PASS]onRead:"+v); | |
80 | + mcu.close(); | |
81 | + }); | |
82 | + }); | |
83 | + }); | |
84 | + }, | |
85 | + onClose:function(){ | |
86 | + log("[PASS]onClose"); | |
87 | + }, | |
88 | + onError:function(){ | |
89 | + alert("Error"); | |
90 | + } | |
91 | + }); | |
92 | +} | |
93 | + | |
66 | 94 | /** |
67 | 95 | * 誤った使用方法でExceptionが出た場合にシャットダウンできるかのテスト |
68 | 96 | */ |
@@ -100,6 +128,7 @@ function sync() | ||
100 | 128 | <h1>BusOut test</h1> |
101 | 129 | <hr/> |
102 | 130 | <button onclick="async();">ASYNC</button> |
131 | +<button onclick="async2();">ASYNC2</button> | |
103 | 132 | <button onclick="sync();">SYNC</button> |
104 | 133 | <textarea id="console" rows="15" cols="80"></textarea> |
105 | 134 | </body> |
\ No newline at end of file |
@@ -62,6 +62,33 @@ function async() | ||
62 | 62 | }); |
63 | 63 | } |
64 | 64 | |
65 | +function async2() | |
66 | +{ | |
67 | + log(); | |
68 | + log("ASYNC2"); | |
69 | + var mcu=new mbedJS.Mcu("192.168.128.39", | |
70 | + { | |
71 | + onNew:function(){ | |
72 | + var pin=new mbedJS.DigitalIn(mcu,mbedJS.PinName.P0_22,function(){ | |
73 | + log("[PASS]onNew"); | |
74 | + pin.mode(mbedJS.PinMode.PullUp,function() | |
75 | + { | |
76 | + log("[PASS]onMode:"); | |
77 | + pin.read(function(v){ | |
78 | + log("[PASS]onRead:"+v); | |
79 | + mcu.close(); | |
80 | + }); | |
81 | + }); | |
82 | + }); | |
83 | + }, | |
84 | + onClose:function(){ | |
85 | + log("[PASS]onClose"); | |
86 | + }, | |
87 | + onError:function(){ | |
88 | + alert("Error"); | |
89 | + } | |
90 | + }); | |
91 | +} | |
65 | 92 | /** |
66 | 93 | * 誤った使用方法でExceptionが出た場合にシャットダウンできるかのテスト |
67 | 94 | */ |
@@ -101,6 +128,7 @@ function sync() | ||
101 | 128 | <h1>DigitalIn test</h1> |
102 | 129 | <hr/> |
103 | 130 | <button onclick="async();">ASYNC</button> |
131 | +<button onclick="async2();">ASYNC2</button> | |
104 | 132 | <button onclick="sync();">SYNC</button> |
105 | 133 | <textarea id="console" rows="15" cols="80"></textarea> |
106 | 134 | </body> |
\ No newline at end of file |
@@ -49,6 +49,32 @@ function async() | ||
49 | 49 | } |
50 | 50 | }); |
51 | 51 | } |
52 | +function async2() | |
53 | +{ | |
54 | + log(); | |
55 | + log("ASYNC2"); | |
56 | + var mcu=new mbedJS.Mcu("192.168.128.39", | |
57 | + { | |
58 | + onNew:function(){ | |
59 | + var pin=new mbedJS.DigitalOut(mcu,mbedJS.PinName.P0_22,function(){ | |
60 | + log("[PASS]onNew"); | |
61 | + pin.read(function(v){ | |
62 | + log("[PASS]onRead "+v); | |
63 | + pin.write((v+1)%2,function(){ | |
64 | + log("[PASS]onWrite"); | |
65 | + mcu.close(); | |
66 | + }); | |
67 | + }); | |
68 | + }); | |
69 | + }, | |
70 | + onClose:function(){ | |
71 | + log("[PASS]onClose"); | |
72 | + }, | |
73 | + onError:function(){ | |
74 | + alert("Error"); | |
75 | + } | |
76 | + }); | |
77 | +} | |
52 | 78 | |
53 | 79 | /** |
54 | 80 | * 誤った使用方法でExceptionが出た場合にシャットダウンできるかのテスト |
@@ -93,6 +119,7 @@ function sync() | ||
93 | 119 | <h1>Digitalout test</h1> |
94 | 120 | <hr/> |
95 | 121 | <button onclick="async();">ASYNC</button> |
122 | +<button onclick="async2();">ASYNC2</button> | |
96 | 123 | <button onclick="sync();">SYNC</button> |
97 | 124 | <button onclick="sync2();">SYNC2</button> |
98 | 125 | <textarea id="console" rows="15" cols="80"></textarea> |
@@ -91,7 +91,49 @@ function async() | ||
91 | 91 | } |
92 | 92 | }); |
93 | 93 | } |
94 | - | |
94 | +function async2() | |
95 | +{ | |
96 | + log(); | |
97 | + log("ASYNC2"); | |
98 | + var st=0; | |
99 | + var mcu=new mbedJS.Mcu("192.168.128.39", | |
100 | + { | |
101 | + onNew:function(){ | |
102 | + var i2c=new mbedJS.I2C(mcu,[mbedJS.PinName.p28,mbedJS.PinName.p27],function(){ | |
103 | + log("[PASS]onNew"); | |
104 | + i2c.frequency(100000,function() | |
105 | + { | |
106 | + log("[PASS]onFrequency:"); | |
107 | + i2c.start(function(){ | |
108 | + log("[PASS]onStart:"); | |
109 | + i2c.write(1,function(v){ | |
110 | + log("[PASS]onWrite:"+v); | |
111 | + i2c.write(0,[1,2,3],false,function(v){ | |
112 | + log("[PASS]onWrite:"+v); | |
113 | + i2c.read(1,function(v){ | |
114 | + log("[PASS]onRead:"+v); | |
115 | + i2c.read(1,2,false,function(v){ | |
116 | + log("[PASS]onRead:"+v.ret+":"+v.data); | |
117 | + i2c.stop(function(){ | |
118 | + log("[PASS]onStop:"); | |
119 | + mcu.close(); | |
120 | + }); | |
121 | + }); | |
122 | + }); | |
123 | + }); | |
124 | + }); | |
125 | + }); | |
126 | + }); | |
127 | + }); | |
128 | + }, | |
129 | + onClose:function(){ | |
130 | + log("[PASS]onClose"); | |
131 | + }, | |
132 | + onError:function(){ | |
133 | + alert("Error"); | |
134 | + } | |
135 | + }); | |
136 | +} | |
95 | 137 | /** |
96 | 138 | * |
97 | 139 | */ |
@@ -110,11 +152,11 @@ function sync() | ||
110 | 152 | log("[PASS]onFrequency:"); |
111 | 153 | yield i2c.start(); |
112 | 154 | log("[PASS]onStart:"); |
113 | - yield i2c.write(1); | |
114 | - v=log("[PASS]onWrite:"+v); | |
115 | - yield i2c.write(0,[1,2,3],false); | |
116 | - v=log("[PASS]onWrite2:"+v); | |
117 | - yield i2c.read(1); | |
155 | + v=yield i2c.write(1); | |
156 | + log("[PASS]onWrite:"+v); | |
157 | + v=yield i2c.write(0,[1,2,3],false); | |
158 | + log("[PASS]onWrite2:"+v); | |
159 | + v=yield i2c.read(1); | |
118 | 160 | log("[PASS]onRead:"+v); |
119 | 161 | v=yield i2c.read(1,2,false); |
120 | 162 | log("[PASS]onRead:"+v.ret+":"+v.data); |
@@ -140,6 +182,7 @@ function sync() | ||
140 | 182 | <h1>I2C test</h1> |
141 | 183 | <hr/> |
142 | 184 | <button onclick="async();">ASYNC</button> |
185 | +<button onclick="async2();">ASYNC2</button> | |
143 | 186 | <button onclick="sync();">SYNC</button> |
144 | 187 | <textarea id="console" rows="15" cols="80"></textarea> |
145 | 188 | </body> |
\ No newline at end of file |
@@ -97,6 +97,53 @@ function async() | ||
97 | 97 | } |
98 | 98 | }); |
99 | 99 | } |
100 | +function async() | |
101 | +{ | |
102 | + log(); | |
103 | + log("ASYNC"); | |
104 | + var st=0; | |
105 | + var mcu=new mbedJS.Mcu("192.168.128.39", | |
106 | + { | |
107 | + onNew:function(){ | |
108 | + var i2c=new mbedJS.I2CSlave(mcu,[mbedJS.PinName.p28,mbedJS.PinName.p27],function(){ | |
109 | + log("[PASS]onNew"); | |
110 | + i2c.frequency(100000,function() | |
111 | + { | |
112 | + log("[PASS]onFrequency:"); | |
113 | + i2c.address(1,function() | |
114 | + { | |
115 | + log("[PASS]onAddress:"); | |
116 | + i2c.receive(function(){ | |
117 | + log("[PASS]onReceive:"); | |
118 | + i2c.write(1,function(v){ | |
119 | + log("[PASS]onWrite:"+v); | |
120 | + i2c.write([1,2,3],function(v){ | |
121 | + log("[PASS]onWrite:"+v); | |
122 | + i2c.read(function(v){ | |
123 | + log("[PASS]onRead:"+v); | |
124 | + i2c.read(2,false,function(v){ | |
125 | + log("[PASS]onRead:"+v.ret+":"+v.data); | |
126 | + i2c.stop(function(){ | |
127 | + log("[PASS]onStop:"); | |
128 | + mcu.close(); | |
129 | + }); | |
130 | + }); | |
131 | + }); | |
132 | + }); | |
133 | + }); | |
134 | + }); | |
135 | + }); | |
136 | + }); | |
137 | + }); | |
138 | + }, | |
139 | + onClose:function(){ | |
140 | + log("[PASS]onClose"); | |
141 | + }, | |
142 | + onError:function(){ | |
143 | + alert("Error"); | |
144 | + } | |
145 | + }); | |
146 | +} | |
100 | 147 | |
101 | 148 | /** |
102 | 149 | * |
@@ -127,6 +174,7 @@ function sync() | ||
127 | 174 | log("[PASS]onRead:"+v.ret+":"+v.data); |
128 | 175 | yield i2c.stop(); |
129 | 176 | yield mcu.close(); |
177 | + log("[PASS]onstop"); | |
130 | 178 | }catch(e){ |
131 | 179 | mcu.shutdown(); |
132 | 180 | alert(e); |
@@ -145,6 +193,7 @@ function sync() | ||
145 | 193 | <body> |
146 | 194 | <h1>I2CSlave test</h1> |
147 | 195 | <hr/> |
196 | +<button onclick="async();">ASYNC2</button> | |
148 | 197 | <button onclick="async();">ASYNC</button> |
149 | 198 | <button onclick="sync();">SYNC</button> |
150 | 199 | <textarea id="console" rows="15" cols="80"></textarea> |
@@ -104,6 +104,62 @@ function async() | ||
104 | 104 | } |
105 | 105 | }); |
106 | 106 | } |
107 | + | |
108 | +function async2() | |
109 | +{ | |
110 | + var s=0; | |
111 | + log(); | |
112 | + log("ASYNC"); | |
113 | + var mcu=new mbedJS.Mcu("192.168.128.39", | |
114 | + { | |
115 | + onNew:function(){ | |
116 | + var mem=new mbedJS.Memory(mcu,function(){ | |
117 | + mem.write(0x20080000,1,function(){ | |
118 | + log("[PASS]onWrite:"); | |
119 | + mem.read(0x20080000,1,function(v){ | |
120 | + log("[PASS]onRead:"+v); | |
121 | + mem.read(0x20080001,1,function(v){ | |
122 | + log("[PASS]onRead:"+v); | |
123 | + mem.read(0x20080000,8,function(v){ | |
124 | + log("[PASS]onRead:"+v); | |
125 | + mem.write(0x20080001,[2],function(){ | |
126 | + log("[PASS]onWrite:"); | |
127 | + mem.write(0x20080004,[10,20,30],function(){ | |
128 | + log("[PASS]onWrite:"); | |
129 | + mem.write32(0x20080000,0xff,function(){ | |
130 | + log("[PASS]onWrite32:"); | |
131 | + mem.read32(0x20080000,function(v){ | |
132 | + log("[PASS]onRead32:"+v); | |
133 | + mem.read32(0x20080004,4,function(v){ | |
134 | + log("[PASS]onRead32:"+v); | |
135 | + mem.read32(0x20080000,16,function(v){ | |
136 | + log("[PASS]onRead32:"+v); | |
137 | + mem.write32(0x20080004,[2],function(){ | |
138 | + log("[PASS]onWrite32:"+s); | |
139 | + mem.write32(0x20080004,[10,20,30],function(){ | |
140 | + mcu.close(); | |
141 | + }); | |
142 | + }); | |
143 | + }); | |
144 | + }); | |
145 | + }); | |
146 | + }); | |
147 | + }); | |
148 | + }); | |
149 | + }); | |
150 | + }); | |
151 | + }); | |
152 | + }); | |
153 | + }); | |
154 | + }, | |
155 | + onClose:function(){ | |
156 | + log("[PASS]onClose"); | |
157 | + }, | |
158 | + onError:function(){ | |
159 | + alert("Error"); | |
160 | + } | |
161 | + }); | |
162 | +} | |
107 | 163 | function sync() |
108 | 164 | { |
109 | 165 | log(); |
@@ -157,6 +213,7 @@ function sync() | ||
157 | 213 | <h1>Memory test</h1> |
158 | 214 | <hr/> |
159 | 215 | <button onclick="async();">ASYNC</button> |
216 | +<button onclick="async2();">ASYNC2</button> | |
160 | 217 | <button onclick="sync();">SYNC</button> |
161 | 218 | <button onclick="sync2();">SYNC2</button> |
162 | 219 | <textarea id="console" rows="15" cols="80"></textarea> |
@@ -57,7 +57,29 @@ function async() | ||
57 | 57 | } |
58 | 58 | }); |
59 | 59 | } |
60 | - | |
60 | +function async2() | |
61 | +{ | |
62 | + log(); | |
63 | + log("ASYNC2"); | |
64 | + var mcu=new mbedJS.Mcu("192.168.128.39", | |
65 | + { | |
66 | + onNew:function(){ | |
67 | + var pin=new mbedJS.PortIn(mcu,[mbedJS.PortName.Port0,0xffffffff],function(){ | |
68 | + log("[PASS]onNew"); | |
69 | + pin.read(function(v){ | |
70 | + log("[PASS]read:"+v); | |
71 | + mcu.close(); | |
72 | + }); | |
73 | + }); | |
74 | + }, | |
75 | + onClose:function(){ | |
76 | + log("[PASS]onClose"); | |
77 | + }, | |
78 | + onError:function(){ | |
79 | + alert("Error"); | |
80 | + } | |
81 | + }); | |
82 | +} | |
61 | 83 | /** |
62 | 84 | * Sync |
63 | 85 | */ |
@@ -96,6 +118,7 @@ function sync() | ||
96 | 118 | <h1>PortIn test</h1> |
97 | 119 | <hr/> |
98 | 120 | <button onclick="async();">ASYNC</button> |
121 | +<button onclick="async2();">ASYNC2</button> | |
99 | 122 | <button onclick="sync();">SYNC</button> |
100 | 123 | <textarea id="console" rows="15" cols="80"></textarea> |
101 | 124 | </body> |
\ No newline at end of file |
@@ -62,7 +62,34 @@ function async() | ||
62 | 62 | } |
63 | 63 | }); |
64 | 64 | } |
65 | - | |
65 | +function async2() | |
66 | +{ | |
67 | + log(); | |
68 | + log("ASYNC2"); | |
69 | + var mcu=new mbedJS.Mcu("192.168.128.39", | |
70 | + { | |
71 | + onNew:function(){ | |
72 | + var pin=new mbedJS.PortOut(mcu,[mbedJS.PortName.Port0,0xffffffff],function(){ | |
73 | + log("[PASS]onNew"); | |
74 | + pin.write(1234,function() | |
75 | + { | |
76 | + log("[PASS]write:"); | |
77 | + pin.read(function(v) | |
78 | + { | |
79 | + log("[PASS]read:"+v); | |
80 | + mcu.close(); | |
81 | + }); | |
82 | + }); | |
83 | + }); | |
84 | + }, | |
85 | + onClose:function(){ | |
86 | + log("[PASS]onClose"); | |
87 | + }, | |
88 | + onError:function(){ | |
89 | + alert("Error"); | |
90 | + } | |
91 | + }); | |
92 | +} | |
66 | 93 | /** |
67 | 94 | * Sync |
68 | 95 | */ |
@@ -103,6 +130,7 @@ function sync() | ||
103 | 130 | <h1>PortOut test</h1> |
104 | 131 | <hr/> |
105 | 132 | <button onclick="async();">ASYNC</button> |
133 | +<button onclick="async2();">ASYNC2</button> | |
106 | 134 | <button onclick="sync();">SYNC</button> |
107 | 135 | <textarea id="console" rows="15" cols="80"></textarea> |
108 | 136 | </body> |
\ No newline at end of file |
@@ -87,7 +87,51 @@ function async() | ||
87 | 87 | } |
88 | 88 | }); |
89 | 89 | } |
90 | - | |
90 | +function async2() | |
91 | +{ | |
92 | + log(); | |
93 | + log("ASYNC2"); | |
94 | + var mcu=new mbedJS.Mcu("192.168.128.39", | |
95 | + { | |
96 | + onNew:function(){ | |
97 | + var pin=new mbedJS.PwmOut(mcu,mbedJS.PinName.p21,function(){ | |
98 | + log("[PASS]onNew"); | |
99 | + pin.write(0.33,function(){ | |
100 | + log("[PASS]onwrite:"); | |
101 | + pin.read(function(v) | |
102 | + { | |
103 | + log("[PASS]onread:"+v); | |
104 | + pin.period(1.0,function(){ | |
105 | + log("[PASS]onPeriod:"); | |
106 | + pin.period_ms(1,function(){ | |
107 | + log("[PASS]onPeriod_ms:"); | |
108 | + pin.period_us(10,function(){ | |
109 | + log("[PASS]onPeriod_us:"); | |
110 | + pin.pulsewidth(3,function(){ | |
111 | + log("[PASS]onPulseWidth:"); | |
112 | + pin.pulsewidth_ms(30,function(){ | |
113 | + log("[PASS]onPulseWidth_ms:"); | |
114 | + pin.pulsewidth_us(40,function(){ | |
115 | + log("[PASS]onPulseWidth_us:"); | |
116 | + mcu.close(); | |
117 | + }); | |
118 | + }); | |
119 | + }); | |
120 | + }); | |
121 | + }); | |
122 | + }); | |
123 | + }); | |
124 | + }); | |
125 | + }); | |
126 | + }, | |
127 | + onClose:function(){ | |
128 | + log("[PASS]onClose"); | |
129 | + }, | |
130 | + onError:function(){ | |
131 | + alert("Error"); | |
132 | + } | |
133 | + }); | |
134 | +} | |
91 | 135 | /** |
92 | 136 | * Sync |
93 | 137 | */ |
@@ -138,6 +182,7 @@ function sync() | ||
138 | 182 | <h1>Pwm test</h1> |
139 | 183 | <hr/> |
140 | 184 | <button onclick="async();">ASYNC</button> |
185 | +<button onclick="async2();">ASYNC</button> | |
141 | 186 | <button onclick="sync();">SYNC</button> |
142 | 187 | <textarea id="console" rows="15" cols="80"></textarea> |
143 | 188 | </body> |
\ No newline at end of file |
@@ -67,6 +67,38 @@ function async() | ||
67 | 67 | }); |
68 | 68 | } |
69 | 69 | |
70 | + | |
71 | +function async2() | |
72 | +{ | |
73 | + log(); | |
74 | + log("ASYNC2"); | |
75 | + var mcu=new mbedJS.Mcu("192.168.128.39", | |
76 | + { | |
77 | + onNew:function(){ | |
78 | + var pin=new mbedJS.SPI(mcu,[mbedJS.PinName.p5,mbedJS.PinName.p6,mbedJS.PinName.p7],function(){ | |
79 | + log("[PASS]onNew"); | |
80 | + pin.frequency(1000000,function() | |
81 | + { | |
82 | + log("[PASS]onFrequency:"); | |
83 | + pin.format(8,3,function() | |
84 | + { | |
85 | + log("[PASS]onFormat:"); | |
86 | + pin.write(39,function(v){ | |
87 | + log("[PASS]onWrite:"+v); | |
88 | + mcu.close(); | |
89 | + }); | |
90 | + }); | |
91 | + }); | |
92 | + }); | |
93 | + }, | |
94 | + onClose:function(){ | |
95 | + log("[PASS]onClose"); | |
96 | + }, | |
97 | + onError:function(){ | |
98 | + alert("Error"); | |
99 | + } | |
100 | + }); | |
101 | +} | |
70 | 102 | /** |
71 | 103 | * 誤った使用方法でExceptionが出た場合にシャットダウンできるかのテスト |
72 | 104 | */ |
@@ -107,6 +139,7 @@ function sync() | ||
107 | 139 | <h1>SPI test</h1> |
108 | 140 | <hr/> |
109 | 141 | <button onclick="async();">ASYNC</button> |
142 | +<button onclick="async2();">ASYNC2</button> | |
110 | 143 | <button onclick="sync();">SYNC</button> |
111 | 144 | <textarea id="console" rows="15" cols="80"></textarea> |
112 | 145 | </body> |
\ No newline at end of file |
@@ -78,6 +78,46 @@ function async() | ||
78 | 78 | }); |
79 | 79 | } |
80 | 80 | |
81 | +function async2() | |
82 | +{ | |
83 | + log(); | |
84 | + log("ASYNC2"); | |
85 | + var mcu=new mbedJS.Mcu("192.168.128.39", | |
86 | + { | |
87 | + onNew:function(){ | |
88 | + var pin=new mbedJS.SPISlave(mcu,[mbedJS.PinName.p5,mbedJS.PinName.p6,mbedJS.PinName.p7,mbedJS.PinName.p8],function(){ | |
89 | + log("[PASS]onNew"); | |
90 | + pin.frequency(1000000,function() | |
91 | + { | |
92 | + log("[PASS]onFrequency:"); | |
93 | + pin.format(8,3,function() | |
94 | + { | |
95 | + log("[PASS]onFormat:"); | |
96 | + pin.read(function(v){ | |
97 | + log("[PASS]onread:"+v); | |
98 | + pin.receive(function(v) | |
99 | + { | |
100 | + log("[PASS]onReceive:"+v); | |
101 | + pin.reply(1,function(){ | |
102 | + log("[PASS]onReply:"); | |
103 | + mcu.close(); | |
104 | + }); | |
105 | + }); | |
106 | + }); | |
107 | + }); | |
108 | + }); | |
109 | + }); | |
110 | + }, | |
111 | + onClose:function(){ | |
112 | + log("[PASS]onClose"); | |
113 | + }, | |
114 | + onError:function(){ | |
115 | + alert("Error"); | |
116 | + } | |
117 | + }); | |
118 | +} | |
119 | + | |
120 | + | |
81 | 121 | /** |
82 | 122 | * |
83 | 123 | */ |
@@ -121,6 +161,7 @@ function sync() | ||
121 | 161 | <body> |
122 | 162 | <h1>SPISlave test</h1> |
123 | 163 | <hr/> |
164 | +<button onclick="async2();">ASYNC2</button> | |
124 | 165 | <button onclick="async();">ASYNC</button> |
125 | 166 | <button onclick="sync();">SYNC</button> |
126 | 167 | <textarea id="console" rows="15" cols="80"></textarea> |
@@ -92,7 +92,55 @@ function async() | ||
92 | 92 | } |
93 | 93 | }); |
94 | 94 | } |
95 | - | |
95 | +function async2() | |
96 | +{ | |
97 | + log(); | |
98 | + log("ASYNC2"); | |
99 | + var mcu=new mbedJS.Mcu("192.168.128.39", | |
100 | + { | |
101 | + onNew:function(){ | |
102 | + var uart=new mbedJS.Serial(mcu,[mbedJS.PinName.p9,mbedJS.PinName.p10], | |
103 | + function(){ | |
104 | + log("[PASS]onNew"); | |
105 | + uart.baud(115200,function() | |
106 | + { | |
107 | + log("[PASS]onBaud:"); | |
108 | + uart.send_break(function(){ | |
109 | + log("[PASS]onSend_break:"); | |
110 | + uart.format(8,uart.Parity.None,1,function(){ | |
111 | + log("[PASS]onForma:"); | |
112 | + uart.readable(function(v){ | |
113 | + log("[PASS]onReadable:"+v); | |
114 | + uart.writeable(function(v){ | |
115 | + log("[PASS]onWritable:"+v); | |
116 | + uart.putc(32,function(v){ | |
117 | + log("[PASS]onPutc:"+v); | |
118 | + uart.getc(function(v){ | |
119 | + log("[PASS]onGetc:"+v); | |
120 | + uart.puts("1234",function(v){ | |
121 | + log("[PASS]onPuts:"+v); | |
122 | + uart.gets(5,function(v){ | |
123 | + log("[PASS]onGets:"+v); | |
124 | + mcu.close(); | |
125 | + }); | |
126 | + }); | |
127 | + }); | |
128 | + }); | |
129 | + }); | |
130 | + }); | |
131 | + }); | |
132 | + }); | |
133 | + }); | |
134 | + }); | |
135 | + }, | |
136 | + onClose:function(){ | |
137 | + log("[PASS]onClose"); | |
138 | + }, | |
139 | + onError:function(){ | |
140 | + alert("Error"); | |
141 | + } | |
142 | + }); | |
143 | +} | |
96 | 144 | /** |
97 | 145 | * |
98 | 146 | */ |
@@ -146,6 +194,7 @@ function sync() | ||
146 | 194 | <body> |
147 | 195 | <h1>Serial test</h1> |
148 | 196 | <hr/> |
197 | +<button onclick="async2();">ASYNC2</button> | |
149 | 198 | <button onclick="async();">ASYNC</button> |
150 | 199 | <button onclick="sync();">SYNC</button> |
151 | 200 | <textarea id="console" rows="15" cols="80"></textarea> |