0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

cscの作法 その604

Posted at

概要

cscの作法、調べてみた。
練習問題やってみた。

練習問題

ラズベリーパイ picoに、シリアルからコードを送り、実行せよ。

写真

image.png

サンプルコード


using System;
using System.Windows.Forms;
using System.Drawing;
using System.IO.Ports;
using System.Text;
using System.Threading;

class form1: Form {
	private Button button1;
	private Button button2;
	private TextBox textBox0;
	private TextBox textBox1;
	private static TextBox textBox2;
	private SerialPort port1;
	form1() {
		Text = "pico IDE";
		ClientSize = new Size(800, 400);
		button1 = new Button();
		button1.Location = new Point(300, 340);
		button1.Text = "setup";
		button1.Click += new EventHandler(button1_Click);
		button2 = new Button();
		button2.Location = new Point(700, 50);
		button2.Text = "send";
		button2.Click += new EventHandler(button2_Click);
		textBox0 = new TextBox();
		textBox0.Location = new Point(30, 20);
		textBox0.Multiline = true;
		textBox0.Size = new Size(300, 300);
		textBox0.Text = @"
from machine import Pin
from rp2 import PIO, StateMachine, asm_pio
@asm_pio(set_init = PIO.OUT_LOW)
def tic():
   set(pins, 1)
   set(pins, 0)
sm = StateMachine(0, tic, freq = 3000, set_base = Pin(25))
";
		textBox1 = new TextBox();
		textBox1.Location = new Point(400, 20);
		textBox1.Multiline = false;
		textBox1.Size = new Size(300, 20);
		textBox1.Text = @"sm.active(1)";
		textBox2 = new TextBox();
		textBox2.Location = new Point(400, 80);
		textBox2.Multiline = true;
		textBox2.Size = new Size(380, 300);
		textBox2.Text = @"";
		port1 = new SerialPort("COM3", 115200, Parity.None, 8, StopBits.One);
		port1.BaudRate = 115200;
		port1.Parity = Parity.None;
		port1.DataBits = 8;
		port1.StopBits = StopBits.One;
		port1.Handshake = Handshake.None;
		port1.PortName = "COM3";
		port1.Encoding = System.Text.Encoding.ASCII;
		port1.NewLine = "\r\n";
		port1.DtrEnable = true;
		port1.RtsEnable = true;
		port1.DataReceived += new SerialDataReceivedEventHandler(DataReceived_Handler);
		port1.Open();
		Controls.AddRange(new Control[] {
			button1,
			button2,
			textBox0,
			textBox1,
			textBox2
		});
	}
	private void button1_Click(object sender, EventArgs e) {
		string s = "e";
		byte[] array = Encoding.UTF8.GetBytes(s);
		array[0] = 5;
		string ctrl_e = Encoding.UTF8.GetString(array);
		array[0] = 4;
		string ctrl_d = Encoding.UTF8.GetString(array);
		string msg;
		msg = ctrl_e + textBox0.Text + "\r\n\r\n" + ctrl_d + textBox1.Text;
		port1.WriteLine(msg);
	}
	private void button2_Click(object sender, EventArgs e) {
		string msg;
		msg = textBox1.Text;
		port1.WriteLine(msg);
	}
	private delegate void SetTextDelegate(string msg);
	private static void SetText(string msg) {
		textBox2.Text = msg;
	}
	private void DataReceived_Handler(object sender, SerialDataReceivedEventArgs e) {
		SerialPort sp = (SerialPort) sender;
		string msg = sp.ReadExisting();
		this.Invoke(new SetTextDelegate(SetText), new object[] { msg });
	}
	[STAThread]
	public static void Main() {
		Application.Run(new form1());
	}
}



以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?