using System; using System.Collections.Generic; using System.Linq; namespace WebMrbc { public class BpsValueBlock : Block { public const string type_name = "bps_value"; public BpsValueBlock() : base(type_name) { } public void init() { this.appendDummyInput() .appendField(new FieldDropdown(new[] { new[] { "115.2kbps", "115200" }, new[] { "57.6kbps", "57600" }, new[] { "38.4kbps", "38400" }, new[] { "31.25kbps", "31250" }, new[] { "28.8kbps", "28800" }, new[] { "19.2kbps", "19200" }, new[] { "14.4kbps", "14400" }, new[] { "9.6kbps", "9600" }, new[] { "4.8kbps", "4800" }, new[] { "2.4kbps", "2400" }, new[] { "1.2kbps", "1200" }, new[] { "600bps", "600" }, new[] { "300bps", "300" } }), "VALUE"); this.setInputsInline(true); this.setOutput(true, "Number"); this.setColour(160); this.setTooltip(""); this.setHelpUrl("http://www.example.com/"); } } public class SerialNewBlock : Block { public const string type_name = "serial_new"; public SerialNewBlock() : base(type_name) { } public void init() { this.appendDummyInput() .appendField("シリアル通信を初期化します") .appendField(GrPeach.SerialPorts(), "SERIAL_PORT_NO"); this.appendValueInput("BPS") .setCheck("Number") .appendField("ボーレート"); this.setInputsInline(true); this.setOutput(true, "Number"); this.setColour(160); this.setTooltip(""); this.setHelpUrl("http://www.example.com/"); } } public class SerialBpsBlock : Block { public const string type_name = "serial_bps"; public SerialBpsBlock() : base(type_name) { } public void init() { this.appendDummyInput() .appendField("ボーレートを設定します") .appendField(GrPeach.SerialPorts(), "SERIAL_PORT_NO"); this.appendValueInput("BPS") .setCheck("Number") .appendField("ボーレート"); this.setInputsInline(true); this.setPreviousStatement(true, null); this.setNextStatement(true, null); this.setColour(160); this.setTooltip(""); this.setHelpUrl("http://www.example.com/"); } } public class SerialPrintBlock : Block { public const string type_name = "serial_print"; public SerialPrintBlock() : base(type_name) { } public void init() { this.appendDummyInput() .appendField("シリアルに出力します") .appendField(GrPeach.SerialPorts(), "SERIAL_PORT_NO"); this.appendValueInput("STR") .setCheck("String") .appendField("文字列"); this.setInputsInline(true); this.setPreviousStatement(true, null); this.setNextStatement(true, null); this.setColour(160); this.setTooltip(""); this.setHelpUrl("http://www.example.com/"); } } public class SerialPrintlnBlock : Block { public const string type_name = "serial_println"; public SerialPrintlnBlock() : base(type_name) { } public void init() { this.appendDummyInput() .appendField("シリアルに\\r\\n付きで出力します") .appendField(GrPeach.SerialPorts(), "SERIAL_PORT_NO"); this.appendValueInput("STR") .setCheck("String") .appendField("文字列"); this.setInputsInline(true); this.setPreviousStatement(true, null); this.setNextStatement(true, null); this.setColour(160); this.setTooltip(""); this.setHelpUrl("http://www.example.com/"); } } public class SerialAvailableBlock : Block { public const string type_name = "serial_available"; public SerialAvailableBlock() : base(type_name) { } public void init() { this.appendDummyInput() .appendField("シリアルデータがあるかどうか調べます") .appendField(GrPeach.SerialPorts(), "SERIAL_PORT_NO"); this.setInputsInline(true); this.setOutput(true, "Number"); this.setColour(160); this.setTooltip(""); this.setHelpUrl("http://www.example.com/"); } } public class SerialReadBlock : Block { public const string type_name = "serial_read"; public SerialReadBlock() : base(type_name) { } public void init() { this.appendDummyInput() .appendField("シリアルからデータを取得します") .appendField(GrPeach.SerialPorts(), "SERIAL_PORT_NO"); this.setInputsInline(true); this.setOutput(true, "Array"); this.setColour(160); this.setTooltip(""); this.setHelpUrl("http://www.example.com/"); } } public class SerialWriteBlock : Block { public const string type_name = "serial_write"; public SerialWriteBlock() : base(type_name) { } public void init() { this.appendDummyInput() .appendField("シリアルにデータを出力します") .appendField(GrPeach.SerialPorts(), "SERIAL_PORT_NO"); this.appendValueInput("DATA") .setCheck("String") .appendField("データ"); this.appendValueInput("LENGTH") .setCheck("Number") .appendField("データサイズ"); this.setInputsInline(true); this.setOutput(true, "Array"); this.setColour(160); this.setTooltip(""); this.setHelpUrl("http://www.example.com/"); } } public class SerialFlashBlock : Block { public const string type_name = "serial_flash"; public SerialFlashBlock() : base(type_name) { } public void init() { this.appendDummyInput() .appendField("シリアルデータをフラッシュします") .appendField(GrPeach.SerialPorts(), "SERIAL_PORT_NO"); this.setInputsInline(true); this.setPreviousStatement(true, null); this.setNextStatement(true, null); this.setColour(160); this.setTooltip(""); this.setHelpUrl("http://www.example.com/"); } } partial class Ruby { public node bps_value(BpsValueBlock block) { var value = block.getFieldValue("VALUE"); return new int_node(this, value == null ? 0 : Bridge.Script.ParseInt(value, 10)); } public node serial_new(SerialNewBlock block) { var dropdown_serial_port_no = block.getFieldValue("SERIAL_PORT_NO"); var value_bps = valueToCode(block, "BPS"); var a = new gvar_node(this, intern(GrPeach.SerialPortNameToVariable(dropdown_serial_port_no))); var c = new const_node(this, intern("Serial")); var p = new node[] { new int_node(this, GrPeach.SerialPortNameToNum(dropdown_serial_port_no)), value_bps }; return new asgn_node(this, a, new call_node(this, c, intern("new"), p, null)); } public node serial_bps(SerialBpsBlock block) { var dropdown_serial_port_no = block.getFieldValue("SERIAL_PORT_NO"); var value_bps = valueToCode(block, "BPS"); var a = new gvar_node(this, intern(GrPeach.SerialPortNameToVariable(dropdown_serial_port_no))); var p = new node[] { value_bps }; return new call_node(this, a, intern("bps"), p, null); } public node serial_print(SerialPrintBlock block) { var dropdown_serial_port_no = block.getFieldValue("SERIAL_PORT_NO"); var value_str = valueToCode(block, "STR"); var a = new gvar_node(this, intern(GrPeach.SerialPortNameToVariable(dropdown_serial_port_no))); var p = new node[] { value_str }; return new call_node(this, a, intern("print"), p, null); } public node serial_println(SerialPrintlnBlock block) { var dropdown_serial_port_no = block.getFieldValue("SERIAL_PORT_NO"); var value_str = valueToCode(block, "STR"); var a = new gvar_node(this, intern(GrPeach.SerialPortNameToVariable(dropdown_serial_port_no))); var p = new node[] { value_str }; return new call_node(this, a, intern("println"), p, null); } public node serial_available(SerialAvailableBlock block) { var dropdown_serial_port_no = block.getFieldValue("SERIAL_PORT_NO"); var a = new gvar_node(this, intern(GrPeach.SerialPortNameToVariable(dropdown_serial_port_no))); var p = new node[0]; return new call_node(this, a, intern("available"), p, null); } public node serial_read(SerialReadBlock block) { var dropdown_serial_port_no = block.getFieldValue("SERIAL_PORT_NO"); var a = new gvar_node(this, intern(GrPeach.SerialPortNameToVariable(dropdown_serial_port_no))); var p = new node[0]; return new call_node(this, a, intern("read"), p, null); } public node serial_write(SerialWriteBlock block) { var dropdown_serial_port_no = block.getFieldValue("SERIAL_PORT_NO"); var value_data = valueToCode(block, "DATA"); var value_length = valueToCode(block, "LENGTH"); var a = new gvar_node(this, intern(GrPeach.SerialPortNameToVariable(dropdown_serial_port_no))); var p = new node[] { value_data, value_length }; return new call_node(this, a, intern("write"), p, null); } public node serial_flash(SerialFlashBlock block) { var dropdown_serial_port_no = block.getFieldValue("SERIAL_PORT_NO"); var a = new gvar_node(this, intern(GrPeach.SerialPortNameToVariable(dropdown_serial_port_no))); var p = new node[0]; return new call_node(this, a, intern("flash"), p, null); } } }