using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;
namespace WindowsFormsApp1{ public partial class Form1 : Form { Byte[] Btn = new Byte[2];
public Form1() { InitializeComponent(); }
private void Form1_Load(object sender, EventArgs e) { serialPort1.PortName = "COM5"; serialPort1.BaudRate = 4800; serialPort1.Open(); }
private void button1_Click(object sender, EventArgs e) { Btn[0] = 0x01; this.serialPort1.Write(Btn, 0, 1);
}
private void button2_Click(object sender, EventArgs e) { Btn[0] = 0x02; this.serialPort1.Write(Btn, 0, 1); }
private void button3_Click(object sender, EventArgs e) { serialPort1.Close(); Close(); } }}
转载于:https://www.cnblogs.com/https/p/9183226.html
