资源简介
c# 串口扫描枪 com口 源码 最简单的程序 可以选择com口,点击开始,开始进入扫描模式,关闭则关闭。

代码片段和文件信息
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.IO;
namespace SerialPortCommunication
{
public partial class Form1 : Form
{
private SerialPort sp = new SerialPort();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender EventArgs e)
{
string[] PortName = SerialPort.GetPortNames();
cbPortName.Items.Clear();
foreach (string str in PortName)
{
cbPortName.Items.Add(str);
}
cbPortName.SelectedIndex = 0;
cbBaudRate.SelectedIndex = 1;
cbDataBit.SelectedIndex = 3;
cbParityBit.SelectedIndex = 0;
cbStopBit.SelectedIndex = 1;
sp.Close();
updateText = new UpdateTextEventHandler(UpdateTextBox); //实例化委托对象
sp.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(sp_DataReceived);
}
private void cbPortName_SelectedIndexChanged(object sender EventArgs e)
{
sp.PortName = cbPortName.Items[cbPortName.SelectedIndex].ToString();
}
private void cbBaudRate_SelectedIndexChanged(object sender EventArgs e)
{
sp.BaudRate = int.Parse(cbBaudRate.Items[cbBaudRate.SelectedIndex].ToString());
}
private void cbDataBit_SelectedIndexChanged(object sender EventArgs e)
{
sp.DataBits = int.Parse(cbDataBit.Items[cbDataBit.SelectedIndex].ToString());
}
private void cbStopBit_SelectedIndexChanged(object sender EventArgs e)
{
sp.StopBits = (StopBits)(cbStopBit.SelectedIndex);
}
private void cbParityBit_SelectedIndexChanged(object sender EventArgs e)
{
sp.Parity = (Parity)System.Enum.Parse(typeof(Parity) (cbParityBit.SelectedIndex).ToString());
}
delegate void UpdateTextEventHandler(string text); //委托,此为重点
UpdateTextEventHandler updateText;
private void button1_Click(object sender EventArgs e)
{ if(!sp.IsOpen)
sp.Open();
}
private void button2_Click(object sender EventArgs e)
{
sp.Close();
}
public void sp_DataReceived(object senderSystem.IO.Ports.SerialDataReceivedEventArgs e)
{
System.Threading.Thread.Sleep(100);
string readString = sp.ReadExisting();
this.Invoke(updateText new string[] { readString });
}
private void UpdateTextBox(string text)
{
textBox1.Text = text;
}
private void Form1_FormClosing(object sender FormClosingEventArgs
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 144 2014-01-06 18:13 SerialPort\SerialPort\app.config
文件 13312 2014-01-06 19:02 SerialPort\SerialPort\bin\Debug\SCOM.exe
文件 144 2014-01-06 18:13 SerialPort\SerialPort\bin\Debug\SCOM.exe.config
文件 46592 2014-01-06 19:02 SerialPort\SerialPort\bin\Debug\SCOM.pdb
文件 22472 2014-01-06 19:03 SerialPort\SerialPort\bin\Debug\SCOM.vshost.exe
文件 144 2014-01-06 18:13 SerialPort\SerialPort\bin\Debug\SCOM.vshost.exe.config
文件 490 2012-06-06 17:06 SerialPort\SerialPort\bin\Debug\SCOM.vshost.exe.manifest
文件 3104 2014-01-06 19:02 SerialPort\SerialPort\Form1.cs
文件 9860 2014-01-06 18:55 SerialPort\SerialPort\Form1.Designer.cs
文件 5814 2014-01-06 18:55 SerialPort\SerialPort\Form1.resx
文件 3887 2014-01-06 18:54 SerialPort\SerialPort\obj\Debug\DesignTimeResolveAssemblyReferences.cache
文件 6777 2014-01-06 19:01 SerialPort\SerialPort\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
文件 13312 2014-01-06 19:02 SerialPort\SerialPort\obj\Debug\SCOM.exe
文件 180 2013-07-01 21:04 SerialPort\SerialPort\obj\Debug\SCOM.Form2.resources
文件 46592 2014-01-06 19:02 SerialPort\SerialPort\obj\Debug\SCOM.pdb
文件 180 2014-01-06 18:13 SerialPort\SerialPort\obj\Debug\SCOM.Properties.Resources.resources
文件 5579 2014-01-06 19:03 SerialPort\SerialPort\obj\Debug\SerialPortCommunication.csproj.FileListAbsolute.txt
文件 975 2014-01-06 18:55 SerialPort\SerialPort\obj\Debug\SerialPortCommunication.csproj.GenerateResource.Cache
文件 11273 2014-01-06 18:13 SerialPort\SerialPort\obj\Debug\SerialPortCommunication.csprojResolveAssemblyReference.cache
文件 180 2014-01-06 18:55 SerialPort\SerialPort\obj\Debug\SerialPortCommunication.Form1.resources
文件 0 2013-06-30 19:51 SerialPort\SerialPort\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
文件 0 2013-06-30 19:51 SerialPort\SerialPort\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
文件 0 2013-06-30 19:51 SerialPort\SerialPort\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
文件 4608 2014-01-06 18:54 SerialPort\SerialPort\obj\Debug\TempPE\Properties.Resources.Designer.cs.dll
文件 515 2012-05-09 15:48 SerialPort\SerialPort\Program.cs
文件 1450 2012-05-09 15:40 SerialPort\SerialPort\Properties\AssemblyInfo.cs
文件 2848 2014-01-06 18:13 SerialPort\SerialPort\Properties\Resources.Designer.cs
文件 5612 2012-05-09 15:40 SerialPort\SerialPort\Properties\Resources.resx
文件 1104 2014-01-06 18:13 SerialPort\SerialPort\Properties\Settings.Designer.cs
文件 249 2012-05-09 15:40 SerialPort\SerialPort\Properties\Settings.settings
............此处省略18个文件信息
相关资源
- 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 操作摄像头录像附
评论
共有 条评论