|
一様このように組んでみたのですが。 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.IO.Ports;
namespace 三次元超音波画像ユニットセンサ { public partial class Form1 : Form { private byte[] myData; private byte[] rcvData; public Form1() { InitializeComponent(); serialPort1.PortName = "COM1"; serialPort1.BaudRate = 57600; serialPort1.DataBits = 8; serialPort1.StopBits = StopBits.One; serialPort1.Parity = Parity.None; serialPort1.PortName = "COM1"; if (serialPort1.IsOpen == true) { serialPort1.Close(); } try { serialPort1.Open(); } catch { MessageBox.Show("RS232Cポート1が接続されていません"); } }
private void button1_Click(object sender, EventArgs e) { myData = new byte[5]; myData[0] = Convert.ToByte(textBox1.Text); myData[1] = Convert.ToByte(textBox2.Text); myData[2] = Convert.ToByte(textBox3.Text); myData[3] = Convert.ToByte(textBox4.Text); myData[4] = Convert.ToByte(textBox5.Text); serialPort1.Write(myData, 0, 5); }
private void button2_Click(object sender, EventArgs e) { myData = new byte[5]; myData[0] = Convert.ToByte(textBox1.Text); myData[1] = Convert.ToByte(textBox2.Text); myData[2] = Convert.ToByte(textBox3.Text); myData[3] = Convert.ToByte(textBox4.Text); myData[4] = Convert.ToByte(textBox5.Text); serialPort1.Write(myData, 0, 5); }
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e) { string result; rcvData = new byte[5]; serialPort1.Read(rcvData, 0, 5); result = rcvData[0]; textBox6.Text = result; } } }
これを最初に述べたようにつくるにはどうしたらいいでしょうか?
|