资源简介
vs2005环境下利用frame.net 提供的serialport类

代码片段和文件信息
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 RS232
{
public partial class fclsRS232Tester : Form
{
string InputData = String.Empty;
// This delegate enables asynchronous calls for setting
// the text property on a TextBox control:
delegate void SetTextCallback(string text);
public fclsRS232Tester()
{
InitializeComponent();
// Nice methods to browse all available ports:
string[] ports = SerialPort.GetPortNames();
// Add all port names to the combo box:
foreach (string port in ports)
{
cmbComSelect.Items.Add(port);
}
}
private void cmbComSelect_SelectionchangeCommitted(object sender EventArgs e)
{
if (port.IsOpen) port.Close();
port.PortName = cmbComSelect.SelectedItem.ToString();
stsStatus.Text = port.PortName + “: 96008N1“;
// try to open the selected port:
try
{
port.Open();
}
// give a message if the port is not available:
catch
{
MessageBox.Show(“Serial port “ + port.PortName + “ cannot be opened!“ “RS232 tester“ MessageBoxButtons.OK MessageBoxIcon.Warning);
cmbComSelect.SelectedText = ““;
stsStatus.Text = “Select serial port!“;
}
}
private void btnSend_Click(object sender EventArgs e)
{
if (port.IsOpen) port.WriteLine(txtOut.Text);
else MessageBox.Show(“Serial port is closed!“ “RS232 tester“ MessageBoxButtons.OK MessageBoxIcon.Error);
txtOut.Clear();
}
private void btnClear_Click(object sender EventArgs e)
{
txtIn.Clear();
}
private void port_DataReceived_1(object sender SerialDataReceivedEventArgs e)
{
InputData = port.ReadExisting();
if (InputData != String.Empty)
{
// txtIn.Text = InputData; // because of different threads this does not work properly !!
SetText(InputData);
}
}
/*
To make a thread-safe call a Windows Forms control:
1. Query the control‘s InvokeRequired property.
2. If InvokeRequired returns true call Invoke with a delegate that makes the actual call to the control.
3. If InvokeRequired returns false call the control directly.
In the following code example this logic is implemented in a utility method called SetText.
A delegate type named SetTextDelegate encapsulates the SetText method.
When the TextBox control‘s
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 24576 2009-11-07 23:11 RS232_C#\RS232\bin\Debug\RS232.exe
文件 32256 2009-11-07 23:11 RS232_C#\RS232\bin\Debug\RS232.pdb
文件 5632 2005-12-08 14:51 RS232_C#\RS232\bin\Debug\RS232.vshost.exe
文件 24576 2007-01-22 14:33 RS232_C#\RS232\bin\Release\RS232.exe
文件 5632 2005-09-23 06:56 RS232_C#\RS232\bin\Release\RS232.vshost.exe
文件 4446 2009-11-07 23:11 RS232_C#\RS232\Form1.cs
文件 8602 2009-10-18 18:49 RS232_C#\RS232\Form1.Designer.cs
文件 6207 2009-10-18 18:49 RS232_C#\RS232\Form1.resx
文件 842 2009-10-18 18:49 RS232_C#\RS232\obj\Debug\RS232.csproj.GenerateResource.Cache
文件 24576 2009-11-07 23:11 RS232_C#\RS232\obj\Debug\RS232.exe
文件 180 2009-10-18 18:49 RS232_C#\RS232\obj\Debug\RS232.fclsRS232Tester.resources
文件 32256 2009-11-07 23:11 RS232_C#\RS232\obj\Debug\RS232.pdb
文件 180 2009-10-18 16:35 RS232_C#\RS232\obj\Debug\RS232.Properties.Resources.resources
文件 264 2009-10-10 10:07 RS232_C#\RS232\obj\RS232.csproj.FileList.txt
文件 688 2009-11-11 17:24 RS232_C#\RS232\obj\RS232.csproj.FileListAbsolute.txt
文件 482 2007-01-09 11:09 RS232_C#\RS232\Program.cs
文件 1262 2007-01-09 11:08 RS232_C#\RS232\Properties\AssemblyInfo.cs
文件 2837 2007-01-09 11:08 RS232_C#\RS232\Properties\Resources.Designer.cs
文件 5612 2007-01-09 11:08 RS232_C#\RS232\Properties\Resources.resx
文件 1088 2007-01-09 11:08 RS232_C#\RS232\Properties\Settings.Designer.cs
文件 249 2007-01-09 11:08 RS232_C#\RS232\Properties\Settings.settings
文件 3217 2007-01-09 11:19 RS232_C#\RS232\RS232.csproj
文件 904 2007-01-09 11:08 RS232_C#\RS232.sln
..A..H. 18432 2009-11-11 17:31 RS232_C#\RS232.suo
目录 0 2009-10-10 16:19 RS232_C#\RS232\obj\Debug\Refactor
目录 0 2009-10-10 16:19 RS232_C#\RS232\obj\Debug\TempPE
目录 0 2009-10-10 16:19 RS232_C#\RS232\obj\Release\TempPE
目录 0 2009-10-10 16:19 RS232_C#\RS232\bin\Debug
目录 0 2009-10-10 16:19 RS232_C#\RS232\bin\Release
目录 0 2009-11-07 23:11 RS232_C#\RS232\obj\Debug
............此处省略9个文件信息
相关资源
- 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 操作摄像头录像附
- c# 实现的最大最小距离方法对鸢尾花
- C#版保龄球记分代码
评论
共有 条评论