使用COM口的2、3针的通断作为中端源(有一个读图像的摄像头,当把卡插到位时触发中端,防止在插卡的过程中出现不稳定的图像)
2014-04-05 15:45
176 查看
利用串口2读,串口3发数据的特点。建立不断的发送流,再从接收端接收。如果收到,则数据畅通,否则断开。相当于产生一个中断。这样电脑对外部事件可作出反应。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
int i = 0;
bool myflag = true;
public Form1()
{
InitializeComponent();
}
//开始
private void button2_Click(object sender, EventArgs e)
{
myflag = true;
this.serialPort1.Open();
System.Threading.Thread t = new System.Threading.Thread(send_data);
t.Start();
this.button2.Enabled = false;
this.button3.Enabled = true;
}
//不断的发送数据
private void send_data(object sender)
{
while (myflag)
{
this.serialPort1.WriteLine(i.ToString());
System.Threading.Thread.Sleep(300);
i++;
}
}
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
this.listBox1.Items.Insert(0,this.serialPort1.ReadLine()+" @ "+System.DateTime.Now.ToString());
}
//停止
private void button3_Click(object sender, EventArgs e)
{
myflag = false;
System.Threading.Thread.Sleep(800);
this.serialPort1.Close();
this.button2.Enabled = true;
this.button3.Enabled = false;
}
}
}
![](http://images.cnitblog.com/i/91772/201404/051542187655274.jpg)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
int i = 0;
bool myflag = true;
public Form1()
{
InitializeComponent();
}
//开始
private void button2_Click(object sender, EventArgs e)
{
myflag = true;
this.serialPort1.Open();
System.Threading.Thread t = new System.Threading.Thread(send_data);
t.Start();
this.button2.Enabled = false;
this.button3.Enabled = true;
}
//不断的发送数据
private void send_data(object sender)
{
while (myflag)
{
this.serialPort1.WriteLine(i.ToString());
System.Threading.Thread.Sleep(300);
i++;
}
}
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
this.listBox1.Items.Insert(0,this.serialPort1.ReadLine()+" @ "+System.DateTime.Now.ToString());
}
//停止
private void button3_Click(object sender, EventArgs e)
{
myflag = false;
System.Threading.Thread.Sleep(800);
this.serialPort1.Close();
this.button2.Enabled = true;
this.button3.Enabled = false;
}
}
}
![](http://images.cnitblog.com/i/91772/201404/051542187655274.jpg)
![](http://images.cnitblog.com/i/91772/201404/051543130621719.jpg)
相关文章推荐
- 使用OpenCV 实现多摄像头图像处理笔记(1):DirectShow的配置过程可能出现的问题
- 微信支付使用过程中出现不稳定、偶尔超时的问题
- mysql使用过程中,为防止出现中文乱码需要注意的四个方面
- TensorFlow自带例子已经包含了android和ios下的摄像头图像分类示例Inception v1,这里补充一个Windows下的,使用AForge库(www.aforgenet.com)操作
- 关于使用百度地图安卓SDK的过程中出现“Authentication Error errorcode: 230 uid: -1 appid -1 msg: APP Scode码校验失败”的一个解决方法
- 使用U盘安装Centos 6.5操作系统,磁盘分区过程中出现,"sda必须有一个gpt磁盘标签"
- 关于解决在使用opencv时出现*.exe 已触发了一个断点的问题
- 防止用户同时使用一个存储过程
- 解决OpenCV在使用摄像头捕捉视频流时出现的一个奇怪问题
- ubutun中非root用户使用过程中出现sudo问题
- 使用命名对象防止运行一个程序的多个实例
- rpm和yum的使用,程序包编译安装以及编译apache过程中出现的问题
- Q:我欲使用WinDriver开发一个PCI卡的驱动程序来传输图像,但是当我利用WinDriver进行Virtex5 FPGA进行读取和写入动作时,计算机会当机,请问如何解决?
- 可以在mono下运行的一个ajax web小程序,使用PostgreSQL作为数据库(期待MonoDevelop 2.0)
- [转载] 使用FFmpeg捕获一帧摄像头图像
- win7换背景时出现:“无法将此图像设置为墙纸。出现了一个内部错误。”
- js一个典型的对象写法,推荐使用这种格式,用于处理图像的基本方法、
- 存储过程使用逗号分隔作为IN参数疑难问题解决方法【真正解决】
- 简单的使用自动化技术实现用WORD读取一个XML文件的过程~
- 有一副由NxN矩阵表示的图像,这里每个像素用一个int表示,请编写一个算法,在不占用额外内存空间的情况下(即不使用缓存矩阵),将图像顺时针旋转90度。 给定一个NxN的矩阵,和矩阵的阶数N,请返回旋转