|
本帖最后由 3050311118 于 2012-6-26 23:05 编辑
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 DeviceApplication12
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
serialPort1.PortName = "COM2";
serialPort1.BaudRate = 9600;
serialPort1.Open();
byte[] data = Encoding.Unicode.GetBytes(textBox1.Text);
string str = Convert.ToBase64String(data);
serialPort1.WriteLine("HELLO");
MessageBox.Show("数据发送成功!", "系统提示");
}
private void button2_Click(object sender, EventArgs e)
{
byte[] data = Convert.FromBase64String(serialPort1.ReadLine());
// textBox2.Text = Encoding.Unicode.GetString(data);
serialPort1.Close();
MessageBox.Show("数据接收成功!", "系统提示");
}
}
}
发送数据不成功
还有那个电脑端模拟软件可以模拟串口么 |
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|