资源简介
通过串口进行图片的传递,图片是以byte[]形式传递的,并能显示出传递后的图片

代码片段和文件信息
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;
using System.IO.Ports;
using System.Text.Regularexpressions;
namespace WindowsFormsApplication21
{
public partial class Form1 : Form
{
private StringBuilder builder = new StringBuilder();//避免在事件处理方法中反复的创建,定义到外面。
private long received_count = 0;//接收计数
private long send_count = 0;//发送计数
private bool Listening = false;//是否没有执行完invoke相关操作
private bool closing = false;//是否正在关闭串口,执行Application.DoEvents,并阻止再次invoke
string curFileName;
static int width;
static int height;
Bitmap bmp1 = null;
byte[] d =null;//设置缓存区用来接收完整的传送数据
public static int x = 0;//与d配套使用,用来记录每次接收缓存区里数据的个数
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender EventArgs e)
{
//初始化下拉串口名称列表框
string[] ports = SerialPort.GetPortNames();
Array.Sort(ports);
comboBox1.Items.AddRange(ports);
comboBox1.SelectedIndex = comboBox1.Items.Count > 0 ? 0 : -1;
comboBox2.SelectedIndex = comboBox2.Items.IndexOf(“9600“);
//初始化SerialPort对象
serialPort1.NewLine = “/r/n“;
serialPort1.RtsEnable = true;//设置是否启用发送请求信号
}
//该事件在一次传送过程中会触发多次,每次都把系统分配的缓存区里数据读至buf数组里
private void serialPort1_DataReceived(object sender SerialDataReceivedEventArgs e)
{
if (closing) return;//如果正在关闭,忽略操作,直接返回,尽快的完成串口监听线程的一次循环
try
{
Listening = true;//设置标记,说明我已经开始处理数据,一会儿要使用系统UI的。
int n = serialPort1.BytesToRead;//先记录下来,避免某种原因,人为的原因,操作几次之间时间长,缓存不一致
byte[] buf = new byte[n];//声明一个临时数组存储当前来的串口数据
received_count += n;//增加接收计数
serialPort1.Read(buf 0 n);//读取缓冲数据
builder.Remove(0 builder.Length);//清除字符串构造器的内容
//因为要访问ui资源,所以需要使用invoke方式同步ui。
this.Invoke((EventHandler)(delegate
{
for (int i = 0; i < n; i++)
{
//richTextBox2.Text = richTextBox2.Text + buf[i].ToString() + ““;
d[x + i] = buf[i];
}
x = x + n;
}));
}
finally
{
Listening = false;//我用完了,ui可以关闭串口了。
}
}
private void button1_Click(object sender EventArgs e)//打开串口
{
button1.Enabled = false;
button2.Enabled = true;
button3.Enabled = true;
serialPort1.PortName = comboBox1.Tex
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 965 2011-09-02 14:45 通过串口传送图片实例\WindowsFormsApplication21.sln
..A..H. 34304 2012-02-23 08:49 通过串口传送图片实例\WindowsFormsApplication21.suo
文件 506 2011-09-02 14:45 通过串口传送图片实例\WindowsFormsApplication21\Program.cs
文件 3796 2011-09-02 15:18 通过串口传送图片实例\WindowsFormsApplication21\WindowsFormsApplication21.csproj
文件 1406 2011-09-02 14:45 通过串口传送图片实例\WindowsFormsApplication21\Properties\AssemblyInfo.cs
文件 2900 2011-09-02 14:45 通过串口传送图片实例\WindowsFormsApplication21\Properties\Resources.Designer.cs
文件 5612 2011-09-02 14:45 通过串口传送图片实例\WindowsFormsApplication21\Properties\Resources.resx
文件 1110 2011-09-02 14:45 通过串口传送图片实例\WindowsFormsApplication21\Properties\Settings.Designer.cs
文件 249 2011-09-02 14:45 通过串口传送图片实例\WindowsFormsApplication21\Properties\Settings.settings
文件 5690 2012-02-23 08:49 通过串口传送图片实例\WindowsFormsApplication21\obj\Debug\WindowsFormsApplication21.csproj.FileListAbsolute.txt
文件 15360 2012-02-23 08:49 通过串口传送图片实例\WindowsFormsApplication21\obj\Debug\WindowsFormsApplication21.exe
文件 180 2012-02-23 08:49 通过串口传送图片实例\WindowsFormsApplication21\obj\Debug\WindowsFormsApplication21.Form1.resources
文件 180 2011-09-02 15:24 通过串口传送图片实例\WindowsFormsApplication21\obj\Debug\WindowsFormsApplication21.Properties.Resources.resources
文件 847 2012-02-23 08:49 通过串口传送图片实例\WindowsFormsApplication21\obj\Debug\WindowsFormsApplication21.csproj.GenerateResource.Cache
文件 28160 2012-02-23 08:49 通过串口传送图片实例\WindowsFormsApplication21\obj\Debug\WindowsFormsApplication21.pdb
文件 15360 2012-02-23 08:49 通过串口传送图片实例\WindowsFormsApplication21\bin\Debug\WindowsFormsApplication21.exe
文件 28160 2012-02-23 08:49 通过串口传送图片实例\WindowsFormsApplication21\bin\Debug\WindowsFormsApplication21.pdb
文件 14328 2012-02-23 08:49 通过串口传送图片实例\WindowsFormsApplication21\bin\Debug\WindowsFormsApplication21.vshost.exe
文件 490 2007-07-21 01:33 通过串口传送图片实例\WindowsFormsApplication21\bin\Debug\WindowsFormsApplication21.vshost.exe.manifest
文件 6217 2012-02-23 08:49 通过串口传送图片实例\WindowsFormsApplication21\Form1.resx
文件 11625 2012-02-23 08:49 通过串口传送图片实例\WindowsFormsApplication21\Form1.Designer.cs
文件 7758 2012-02-23 08:49 通过串口传送图片实例\WindowsFormsApplication21\Form1.cs
文件 189 2012-02-23 08:51 通过串口传送图片实例\使用说明.txt
目录 0 2012-02-23 08:45 通过串口传送图片实例\WindowsFormsApplication21\obj\Debug\TempPE
目录 0 2012-02-23 08:45 通过串口传送图片实例\WindowsFormsApplication21\obj\Debug\Refactor
目录 0 2012-02-23 08:45 通过串口传送图片实例\WindowsFormsApplication21\obj\Debug
目录 0 2012-02-23 08:45 通过串口传送图片实例\WindowsFormsApplication21\bin\Debug
目录 0 2012-02-23 08:45 通过串口传送图片实例\WindowsFormsApplication21\Properties
目录 0 2012-02-23 08:45 通过串口传送图片实例\WindowsFormsApplication21\obj
目录 0 2012-02-23 08:45 通过串口传送图片实例\WindowsFormsApplication21\bin
............此处省略5个文件信息
- 上一篇:C#连接Oracle含源码和数据库
- 下一篇:模糊均值聚类算法FCM(C#)
相关资源
- C# IP地址输入控件
- C#在一个窗口刷新更改另一个窗口控件
- C# TIP文件生成和拆解
- C#解析HL7消息的库135797
- C# OCR数字识别实例,采用TessnetOcr,对
- 考试管理系统 - C#源码
- asp.net C#购物车源代码
- C#实时网络流量监听源码
- C#百度地图源码
- Visual C#.2010从入门到精通配套源程序
- C# 软件版本更新
- C#屏幕软键盘源码,可以自己定制界面
- 智慧城市 智能家居 C# 源代码
- c#获取mobile手机的IMEI和IMSI
- C#实现简单QQ聊天程序
- 操作系统 模拟的 欢迎下载 C#版
- C#写的计算机性能监控程序
- 用C#实现邮件发送,有点类似于outlo
- MVC model层代码生成器 C#
- c#小型图书销售系统
- C# Socket Server Client 通讯应用 完整的服
- c# winform 自动登录 百度账户 源代码
- C#编写的16进制计算器
- C#TCP通信协议
- C# 数据表(Dataset)操作 合并 查询一
- C#语音识别系统speechsdk51,SpeechSDK51L
- 数据库备份还原工具1.0 C# 源码
-
[免费]xm
lDocument 节点遍历C# - EQ2008LEDc#开发实例
- DirectX.Capturec# winform 操作摄像头录像附
评论
共有 条评论