wyd1520 发表于 2013-8-8 00:15 
Arduino接收是一个字符一个字符的接的。你发16进制与发byte是一样的,直接
bytesp[0]=0x01就是了,
然后 ...
C#代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button5_Click(object sender, EventArgs e)
{
if(button5.Text == "打开串口")
{
button5.Text = "关闭串口";
serialPort1.Open();
}
else
{
button5.Text = "打开串口";
serialPort1.Close();
}
}
private void button1_Click(object sender, EventArgs e)
{
Byte[] BSendTemp = new Byte[1]; //建立临时字节数组对象
BSendTemp[0] = 3; //由文本框读入想要发送的数据
serialPort1.Write(BSendTemp, 0, 1);//发送数据 //up
}
private void button2_Click(object sender, EventArgs e)
{
Byte[] BSendTemp = new Byte[1]; //建立临时字节数组对象
BSendTemp[0] = 4;//由文本框读入想要发送的数据
serialPort1.Write(BSendTemp, 0, 1);//发送数据 //down
}
private void button3_Click(object sender, EventArgs e)
{
Byte[] BSendTemp = new Byte[1]; //建立临时字节数组对象
BSendTemp[0] = 1;//由文本框读入想要发送的数据
serialPort1.Write(BSendTemp, 0, 1);//发送数据 //left
}
private void button4_Click(object sender, EventArgs e)
{
Byte[] BSendTemp = new Byte[1]; //建立临时字节数组对象
BSendTemp[0] =2;//由文本框读入想要发送的数据
serialPort1.Write(BSendTemp, 0, 1);//发送数据
}
}
}
|