using System;
来源:互联网 发布:2017年十大网络用语 编辑:程序博客网 时间:2024/06/04 18:42
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace cj1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
if(this.button1.Text == "打开串口")
{
this.serialPort1.PortName = comboBox1.Text;
try
{
this.serialPort1.Open();
if (this.serialPort1.IsOpen)
{
this.button1.Text = "关闭串口";
}
}
catch( Exception ee)
{
MessageBox.Show("串口打开失败!");
}
}
else
{
this.serialPort1.Close();
if (!this.serialPort1.IsOpen)
{
this.button1.Text = "打开串口";
}
}
}
private void button2_Click(object sender, EventArgs e)
{
if (!this.serialPort1.IsOpen)
{
MessageBox.Show("串口未打开!");
return;
}
if(this.textBox2.Text == "")
{
MessageBox.Show("数据为空!");
return;
}
this.serialPort1.Write(this.textBox2.Text);
}
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
int len = this.serialPort1.ReceivedBytesThreshold;
Byte[] buffer = new Byte[5000];
this.serialPort1.Read(buffer, 0, 5000-1);
this.textBox3.Text += Encoding.Default.GetString(buffer);
//MessageBox.Show("收到1次");
// string response = Encoding.ASCII.GetString(ss_port.Read(128));
}
}
}
- using System;
- using System;
- using System;
- using System;
- using System;
- using System;
- using System
- using System..................
- 【System Icon】using system icon
- using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin
- Using Ubuntu System
- Using System Calls
- Invoke methods using System.Reflection
- AJAX Login System using XMLHttpRequest
- using System.Transactions时报错
- 系统托盘使用 Using system tray
- using System.Transactions时报错
- using System.ComponentModel.DataAnnotations
- ios调试发布出去得软件版本
- 通过并发程序名称,反查所在Menu
- 初学Android,使用Service的音乐播放器(七十二)
- wordpress主循环显示文章方法
- JavaScript monitor hidden input value change
- using System;
- 52.IO流-对象的序列化
- Sqlit3 简单操作
- Eclipse/RAD平台中一些名词术语缩写的介绍
- 一个判断字符串是否是数字的正则表达式
- 梦断代码--一个程序员的自白 笔记
- C++的虚函数理解
- 根据功能名称, 追溯所属菜单和职责
- emule中节点加入Kad网络过程(源代码详解)【对原文部分改进】