资源简介
在上位机开发中,时常会引入输入信号作为启动信号,此Demo完美解决使用脚踏开关作输入信号的问题

代码片段和文件信息
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace RTS
{
public partial class Form1 : Form
{
//将ComDevice.RtsEnable置为True,表示启用发送请求(RST)信号,将请求发送/可以发送 (RTS/CTS)[第7和第8针脚]硬件握手时[脚踏短接],会触发ComDevice.PinChanged事件及ComDevice.CtsHolding的Bool值变化。
public Form1()
{
InitializeComponent();
}
SerialPort sp = new SerialPort();
private void Form1_Load(object sender EventArgs e)
{
sp.RtsEnable=true;
cmb_JtCom.Items.AddRange(SerialPort.GetPortNames());
//sp.DataReceived += new SerialDataReceivedEventHandler(sp_DataReceived) ;
sp.PinChanged += new SerialPinChangedEventHandler(sp_DataReceived);
}
private void btn_Open_Click(object sender EventArgs e)
{
if(cmb_JtCom.Items.Count<=0)
{
MessageBox.Show(“没有发现串口,请重试“);
return;
}
if (sp.IsOpen==false)
{
sp.PortName = cmb_JtCom.SelectedItem.ToString();
sp.BaudRate = 9600;
sp.DataBits = 8;
sp.StopBits = StopBits.One;
sp.Parity = Parity.None;
try
{
sp.Open();
timer1.Enabled = true;
}
catch(Exception ex)
{
MessageBox.Show(ex.Message “错误“ MessageBoxButtons.OK MessageBoxIcon.Error);
}
btn_Open.Text = “关闭串口“;
}
else
{
try
{
sp.Close();
timer1.Enabled = false;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message “错误“ MessageBoxButtons.OK MessageBoxIcon.Error);
}
btn_Open.Text = “打开串口“;
}
cmb_JtCom.Enabled = !sp.IsOpen;
}
bool b;
void sp_DataReceived(object sender SerialPinChangedEventArgs e)
{
MessageBox.Show(“RTS触发成功“);
}
private void timer1_Tick(object sender EventArgs e)
{
label1.Text = sp.CtsHolding.ToString();
}
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 187 2018-03-15 10:40 RTS\RTS\App.config
文件 10240 2018-03-20 17:12 RTS\RTS\bin\Debug\RTS.exe
文件 187 2018-03-15 10:40 RTS\RTS\bin\Debug\RTS.exe.config
文件 24064 2018-03-20 17:12 RTS\RTS\bin\Debug\RTS.pdb
文件 24224 2018-03-20 17:11 RTS\RTS\bin\Debug\RTS.vshost.exe
文件 187 2018-03-15 10:40 RTS\RTS\bin\Debug\RTS.vshost.exe.config
文件 490 2013-03-18 17:00 RTS\RTS\bin\Debug\RTS.vshost.exe.manifest
文件 2824 2018-03-20 17:12 RTS\RTS\Form1.cs
文件 3503 2018-03-15 13:25 RTS\RTS\Form1.Designer.cs
文件 6011 2018-03-15 13:25 RTS\RTS\Form1.resx
文件 865 2018-03-15 10:40 RTS\RTS\obj\Debug\DesignTimeResolveAssemblyReferences.cache
文件 6959 2018-03-15 10:44 RTS\RTS\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
文件 627 2018-03-20 17:11 RTS\RTS\obj\Debug\RTS.csproj.FileListAbsolute.txt
文件 977 2018-03-15 13:25 RTS\RTS\obj\Debug\RTS.csproj.GenerateResource.Cache
文件 2211 2018-03-15 11:12 RTS\RTS\obj\Debug\RTS.csprojResolveAssemblyReference.cache
文件 10240 2018-03-20 17:12 RTS\RTS\obj\Debug\RTS.exe
文件 180 2018-03-15 13:25 RTS\RTS\obj\Debug\RTS.Form1.resources
文件 24064 2018-03-20 17:12 RTS\RTS\obj\Debug\RTS.pdb
文件 180 2018-03-15 11:12 RTS\RTS\obj\Debug\RTS.Properties.Resources.resources
文件 0 2018-03-15 10:40 RTS\RTS\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
文件 0 2018-03-15 10:40 RTS\RTS\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
文件 0 2018-03-15 10:40 RTS\RTS\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
文件 515 2018-03-15 10:40 RTS\RTS\Program.cs
文件 1348 2018-03-15 10:40 RTS\RTS\Properties\AssemblyInfo.cs
文件 2858 2018-03-15 10:40 RTS\RTS\Properties\Resources.Designer.cs
文件 5612 2018-03-15 10:40 RTS\RTS\Properties\Resources.resx
文件 1090 2018-03-15 10:40 RTS\RTS\Properties\Settings.Designer.cs
文件 249 2018-03-15 10:40 RTS\RTS\Properties\Settings.settings
文件 3786 2018-03-15 11:12 RTS\RTS\RTS.csproj
文件 978 2018-03-15 10:40 RTS\RTS.sln
............此处省略12个文件信息
- 上一篇:C#多线程进度条
- 下一篇:采集卡 C# Demo
相关资源
- 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#版保龄球记分代码
- C#自定义控件
- 基于c#的实验室设备管理系统621530
- C# 使用ListView控件实现图片浏览器(源
- C#简单窗体聊天程序
评论
共有 条评论