source: EcnlProtoTool/trunk/webapp/webmrbc/Arduino/SerialBlock.cs@ 287

Last change on this file since 287 was 287, checked in by coas-nagasima, 7 years ago

ファイルヘッダーコメントを追加

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-csharp
File size: 11.3 KB
Line 
1/*
2 * TOPPERS/ECNL Prototyping tool
3 *
4 * Copyright (C) 2017 Cores Co., Ltd. Japan
5 *
6 * 上記著作権者は,以下の(1)~(4)の条件を満たす場合に限り,本ソフトウェ
7 * ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
8 * 変・再配布(以下,利用と呼ぶ)することを無償で許諾する.
9 * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
10 * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
11 * スコード中に含まれていること.
12 * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
13 * 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
14 * 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
15 * の無保証規定を掲載すること.
16 * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
17 * 用できない形で再配布する場合には,次のいずれかの条件を満たすこ
18 * と.
19 * (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
20 * 作権表示,この利用条件および下記の無保証規定を掲載すること.
21 * (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
22 * 報告すること.
23 * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
24 * 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
25 * また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
26 * 由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを
27 * 免責すること.
28 *
29 * 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
30 * よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
31 * に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
32 * アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
33 * の責任を負わない.
34 *
35 * @(#) $Id: SerialBlock.cs 287 2017-05-05 14:22:23Z coas-nagasima $
36 */
37using System;
38using System.Collections.Generic;
39using System.Linq;
40
41namespace WebMrbc
42{
43 public class BpsValueBlock : Block
44 {
45 public const string type_name = "bps_value";
46
47 public BpsValueBlock()
48 : base(type_name)
49 {
50 }
51
52 public void init()
53 {
54 this.appendDummyInput()
55 .appendField(new FieldDropdown(new[] {
56 new[] { "115.2kbps", "115200" },
57 new[] { "57.6kbps", "57600" },
58 new[] { "38.4kbps", "38400" },
59 new[] { "31.25kbps", "31250" },
60 new[] { "28.8kbps", "28800" },
61 new[] { "19.2kbps", "19200" },
62 new[] { "14.4kbps", "14400" },
63 new[] { "9.6kbps", "9600" },
64 new[] { "4.8kbps", "4800" },
65 new[] { "2.4kbps", "2400" },
66 new[] { "1.2kbps", "1200" },
67 new[] { "600bps", "600" },
68 new[] { "300bps", "300" }
69 }), "VALUE");
70 this.setInputsInline(true);
71 this.setOutput(true, "Number");
72 this.setColour(160);
73 this.setTooltip("");
74 this.setHelpUrl("http://www.example.com/");
75 }
76 }
77
78 public class SerialNewBlock : Block
79 {
80 public const string type_name = "serial_new";
81
82 public SerialNewBlock()
83 : base(type_name)
84 {
85 }
86
87 public void init()
88 {
89 this.appendDummyInput()
90 .appendField("シリアル通信を初期化します")
91 .appendField(App.TargetBoard.SerialPorts(), "SERIAL_PORT_NO");
92 this.appendValueInput("BPS")
93 .setCheck("Number")
94 .appendField("ボーレート");
95 this.setInputsInline(true);
96 this.setOutput(true, "Number");
97 this.setColour(160);
98 this.setTooltip("");
99 this.setHelpUrl("http://www.example.com/");
100 }
101 }
102
103 public class SerialBpsBlock : Block
104 {
105 public const string type_name = "serial_bps";
106
107 public SerialBpsBlock()
108 : base(type_name)
109 {
110 }
111
112 public void init()
113 {
114 this.appendDummyInput()
115 .appendField("ボーレートを設定します")
116 .appendField(App.TargetBoard.SerialPorts(), "SERIAL_PORT_NO");
117 this.appendValueInput("BPS")
118 .setCheck("Number")
119 .appendField("ボーレート");
120 this.setInputsInline(true);
121 this.setPreviousStatement(true, null);
122 this.setNextStatement(true, null);
123 this.setColour(160);
124 this.setTooltip("");
125 this.setHelpUrl("http://www.example.com/");
126 }
127 }
128
129 public class SerialPrintBlock : Block
130 {
131 public const string type_name = "serial_print";
132
133 public SerialPrintBlock()
134 : base(type_name)
135 {
136 }
137
138 public void init()
139 {
140 this.appendDummyInput()
141 .appendField("シリアルに出力します")
142 .appendField(App.TargetBoard.SerialPorts(), "SERIAL_PORT_NO");
143 this.appendValueInput("STR")
144 .setCheck("String")
145 .appendField("文字列");
146 this.setInputsInline(true);
147 this.setPreviousStatement(true, null);
148 this.setNextStatement(true, null);
149 this.setColour(160);
150 this.setTooltip("");
151 this.setHelpUrl("http://www.example.com/");
152 }
153 }
154
155 public class SerialPrintlnBlock : Block
156 {
157 public const string type_name = "serial_println";
158
159 public SerialPrintlnBlock()
160 : base(type_name)
161 {
162 }
163
164 public void init()
165 {
166 this.appendDummyInput()
167 .appendField("シリアルに\\r\\n付きで出力します")
168 .appendField(App.TargetBoard.SerialPorts(), "SERIAL_PORT_NO");
169 this.appendValueInput("STR")
170 .setCheck("String")
171 .appendField("文字列");
172 this.setInputsInline(true);
173 this.setPreviousStatement(true, null);
174 this.setNextStatement(true, null);
175 this.setColour(160);
176 this.setTooltip("");
177 this.setHelpUrl("http://www.example.com/");
178 }
179 }
180
181 public class SerialAvailableBlock : Block
182 {
183 public const string type_name = "serial_available";
184
185 public SerialAvailableBlock()
186 : base(type_name)
187 {
188 }
189
190 public void init()
191 {
192 this.appendDummyInput()
193 .appendField("シリアルデータがあるかどうか調べます")
194 .appendField(App.TargetBoard.SerialPorts(), "SERIAL_PORT_NO");
195 this.setInputsInline(true);
196 this.setOutput(true, "Number");
197 this.setColour(160);
198 this.setTooltip("");
199 this.setHelpUrl("http://www.example.com/");
200 }
201 }
202
203 public class SerialReadBlock : Block
204 {
205 public const string type_name = "serial_read";
206
207 public SerialReadBlock()
208 : base(type_name)
209 {
210 }
211
212 public void init()
213 {
214 this.appendDummyInput()
215 .appendField("シリアルからデータを取得します")
216 .appendField(App.TargetBoard.SerialPorts(), "SERIAL_PORT_NO");
217 this.setInputsInline(true);
218 this.setOutput(true, "Array");
219 this.setColour(160);
220 this.setTooltip("");
221 this.setHelpUrl("http://www.example.com/");
222 }
223 }
224
225 public class SerialWriteBlock : Block
226 {
227 public const string type_name = "serial_write";
228
229 public SerialWriteBlock()
230 : base(type_name)
231 {
232 }
233 public void init()
234 {
235 this.appendDummyInput()
236 .appendField("シリアルにデータを出力します")
237 .appendField(App.TargetBoard.SerialPorts(), "SERIAL_PORT_NO");
238 this.appendValueInput("DATA")
239 .setCheck("String")
240 .appendField("データ");
241 this.appendValueInput("LENGTH")
242 .setCheck("Number")
243 .appendField("データサイズ");
244 this.setInputsInline(true);
245 this.setOutput(true, "Array");
246 this.setColour(160);
247 this.setTooltip("");
248 this.setHelpUrl("http://www.example.com/");
249 }
250 }
251
252 public class SerialFlashBlock : Block
253 {
254 public const string type_name = "serial_flash";
255
256 public SerialFlashBlock()
257 : base(type_name)
258 {
259 }
260
261 public void init()
262 {
263 this.appendDummyInput()
264 .appendField("シリアルデータをフラッシュします")
265 .appendField(App.TargetBoard.SerialPorts(), "SERIAL_PORT_NO");
266 this.setInputsInline(true);
267 this.setPreviousStatement(true, null);
268 this.setNextStatement(true, null);
269 this.setColour(160);
270 this.setTooltip("");
271 this.setHelpUrl("http://www.example.com/");
272 }
273 }
274
275 partial class Ruby
276 {
277 public node bps_value(BpsValueBlock block)
278 {
279 var value = block.getFieldValue("VALUE");
280 return new int_node(this, value == null ? 0 : Bridge.Script.ParseInt(value, 10));
281 }
282
283 public node serial_new(SerialNewBlock block)
284 {
285 var dropdown_serial_port_no = block.getFieldValue("SERIAL_PORT_NO");
286 var value_bps = valueToCode(block, "BPS");
287 var a = new gvar_node(this, intern(App.TargetBoard.SerialPortNameToVariable(dropdown_serial_port_no)));
288 var c = new const_node(this, intern("Serial"));
289 var p = new node[] {
290 new int_node(this, App.TargetBoard.SerialPortNameToNum(dropdown_serial_port_no)),
291 value_bps
292 };
293 return new asgn_node(this, a, new call_node(this, c, intern("new"), p, null));
294 }
295
296 public node serial_bps(SerialBpsBlock block)
297 {
298 var dropdown_serial_port_no = block.getFieldValue("SERIAL_PORT_NO");
299 var value_bps = valueToCode(block, "BPS");
300 var a = new gvar_node(this, intern(App.TargetBoard.SerialPortNameToVariable(dropdown_serial_port_no)));
301 var p = new node[] {
302 value_bps
303 };
304 return new call_node(this, a, intern("bps"), p, null);
305 }
306
307 public node serial_print(SerialPrintBlock block)
308 {
309 var dropdown_serial_port_no = block.getFieldValue("SERIAL_PORT_NO");
310 var value_str = valueToCode(block, "STR");
311 var a = new gvar_node(this, intern(App.TargetBoard.SerialPortNameToVariable(dropdown_serial_port_no)));
312 var p = new node[] {
313 value_str
314 };
315 return new call_node(this, a, intern("print"), p, null);
316 }
317
318 public node serial_println(SerialPrintlnBlock block)
319 {
320 var dropdown_serial_port_no = block.getFieldValue("SERIAL_PORT_NO");
321 var value_str = valueToCode(block, "STR");
322 var a = new gvar_node(this, intern(App.TargetBoard.SerialPortNameToVariable(dropdown_serial_port_no)));
323 var p = new node[] {
324 value_str
325 };
326 return new call_node(this, a, intern("println"), p, null);
327 }
328
329 public node serial_available(SerialAvailableBlock block)
330 {
331 var dropdown_serial_port_no = block.getFieldValue("SERIAL_PORT_NO");
332 var a = new gvar_node(this, intern(App.TargetBoard.SerialPortNameToVariable(dropdown_serial_port_no)));
333 var p = new node[0];
334 return new call_node(this, a, intern("available"), p, null);
335 }
336
337 public node serial_read(SerialReadBlock block)
338 {
339 var dropdown_serial_port_no = block.getFieldValue("SERIAL_PORT_NO");
340 var a = new gvar_node(this, intern(App.TargetBoard.SerialPortNameToVariable(dropdown_serial_port_no)));
341 var p = new node[0];
342 return new call_node(this, a, intern("read"), p, null);
343 }
344
345 public node serial_write(SerialWriteBlock block)
346 {
347 var dropdown_serial_port_no = block.getFieldValue("SERIAL_PORT_NO");
348 var value_data = valueToCode(block, "DATA");
349 var value_length = valueToCode(block, "LENGTH");
350 var a = new gvar_node(this, intern(App.TargetBoard.SerialPortNameToVariable(dropdown_serial_port_no)));
351 var p = new node[] {
352 value_data,
353 value_length
354 };
355 return new call_node(this, a, intern("write"), p, null);
356 }
357
358 public node serial_flash(SerialFlashBlock block)
359 {
360 var dropdown_serial_port_no = block.getFieldValue("SERIAL_PORT_NO");
361 var a = new gvar_node(this, intern(App.TargetBoard.SerialPortNameToVariable(dropdown_serial_port_no)));
362 var p = new node[0];
363 return new call_node(this, a, intern("flash"), p, null);
364 }
365 }
366}
Note: See TracBrowser for help on using the repository browser.