资源简介
完整的RS232串口通讯示例

代码片段和文件信息
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO.Ports;
using System.Text;
using System.Threading;
using System.Windows.Forms;
namespace RS232串口通讯CSharp
{
public partial class frmTest : Form
{
public frmTest()
{
InitializeComponent();
}
///
/// SerialPort串行端口
///
private SerialPort Com_SerialPort = new SerialPort();
///
/// 是否没有执行完invoke相关操作
///
private bool IsListening = false;
///
/// 是否正在关闭串口,执行Application.DoEvents,并阻止再次invoke
///
private bool IsClosing = false;
private void button1_Click(object sender EventArgs e)
{
//MCJS50.ReadValue(Com_SerialPort);
//MessageBox.Show(MCJS50.intJs.ToString());
}
void Com_SerialPort_DataReceived(object sender SerialDataReceivedEventArgs e)
{
if (IsClosing) { return; }
try
{
if (Com_SerialPort.BytesToRead <= 0) return;
Thread.Sleep(50);
IsListening = true;
int intBytesToRead = Com_SerialPort.BytesToRead;
byte[] buffer = new byte[intBytesToRead];
Com_SerialPort.Read(buffer 0 intBytesToRead);
if (buffer.Length >= 6)
{
if (buffer[0] == 0xAC && buffer[buffer.Length - 1] == 0x84)
{
//读计数值
string strValue = buffer[5].ToString(“X2“) + “ “ + buffer[6].ToString(“X2“) + “ “ + buffer[7].ToString(“X2“) + “ “ + buffer[8].ToString(“X2“) + “ “ + buffer[9].ToString(“X2“) + “ “ + buffer[10].ToString(“X2“);
Int64 intValue = Int64.Parse(buffer[5].ToString() + buffer[6].ToString() + buffer[7].ToString() + buffer[8].ToString() + buffer[9].ToString() + buffer[10].ToString());
this.Invoke((EventHandler)(delegate
{
this.label1.Text = intValue.ToString();
}));
}
else
{
buffer = null;
}
}
}
finally
{
IsListening = false;
}
}
private void frmTest_Load(object sender EventArgs e)
{
Com_SerialPort = new SerialPort();
MCJS50.SetSerialPort(Com_SerialPort IsClosing IsListening);
Com_SerialPort.DataReceived += Com_SerialPort_DataReceived;
}
private void button2_Click(object sender EventArgs e)
{
MCJS50.ReadValue(Com_SerialPort);
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
..A..H. 58880 2016-09-21 16:18 RS232串口通讯CSharp\.vs\RS232串口通讯CSharp\v14\.suo
文件 157 2016-09-07 16:06 RS232串口通讯CSharp\RS232串口通讯CSharp\App.config
文件 35840 2016-09-20 10:55 RS232串口通讯CSharp\RS232串口通讯CSharp\bin\Debug\RS232串口通讯CSharp.dll
文件 157 2016-09-07 16:06 RS232串口通讯CSharp\RS232串口通讯CSharp\bin\Debug\RS232串口通讯CSharp.dll.config
文件 54784 2016-09-20 10:55 RS232串口通讯CSharp\RS232串口通讯CSharp\bin\Debug\RS232串口通讯CSharp.pdb
文件 21680 2016-09-19 08:30 RS232串口通讯CSharp\RS232串口通讯CSharp\bin\Debug\RS232串口通讯CSharp.vshost.exe
文件 157 2016-09-07 16:06 RS232串口通讯CSharp\RS232串口通讯CSharp\bin\Debug\RS232串口通讯CSharp.vshost.exe.config
文件 490 2015-06-04 12:48 RS232串口通讯CSharp\RS232串口通讯CSharp\bin\Debug\RS232串口通讯CSharp.vshost.exe.manifest
文件 180904 2013-07-09 11:04 RS232串口通讯CSharp\RS232串口通讯CSharp\bin\Debug\System.Net.Http.dll
文件 148528 2015-11-02 01:02 RS232串口通讯CSharp\RS232串口通讯CSharp\bin\Debug\System.Net.Http.xm
文件 17576 2013-07-09 11:34 RS232串口通讯CSharp\RS232串口通讯CSharp\bin\Debug\zh-Hans\System.Net.Http.resources.dll
文件 3088 2016-09-07 17:28 RS232串口通讯CSharp\RS232串口通讯CSharp\frmTest.cs
文件 3299 2016-09-07 17:27 RS232串口通讯CSharp\RS232串口通讯CSharp\frmTest.Designer.cs
文件 5817 2016-09-07 17:27 RS232串口通讯CSharp\RS232串口通讯CSharp\frmTest.resx
文件 1788 2016-09-07 16:39 RS232串口通讯CSharp\RS232串口通讯CSharp\frmUserVerification.cs
文件 4930 2016-09-07 16:27 RS232串口通讯CSharp\RS232串口通讯CSharp\frmUserVerification.Designer.cs
文件 5817 2016-09-07 16:27 RS232串口通讯CSharp\RS232串口通讯CSharp\frmUserVerification.resx
文件 3203 2016-09-20 10:54 RS232串口通讯CSharp\RS232串口通讯CSharp\MCJS50.cs
文件 18783 2016-09-08 10:40 RS232串口通讯CSharp\RS232串口通讯CSharp\MCJS50_Rs232.cs
文件 46603 2016-09-07 18:23 RS232串口通讯CSharp\RS232串口通讯CSharp\MCJS50_Rs232.Designer.cs
文件 6414 2016-09-07 18:23 RS232串口通讯CSharp\RS232串口通讯CSharp\MCJS50_Rs232.resx
文件 2410 2016-09-13 17:07 RS232串口通讯CSharp\RS232串口通讯CSharp\obj\Debug\DesignTimeResolveAssemblyReferences.cache
文件 6243 2016-09-20 10:55 RS232串口通讯CSharp\RS232串口通讯CSharp\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
文件 2423 2016-09-20 10:55 RS232串口通讯CSharp\RS232串口通讯CSharp\obj\Debug\RS232串口通讯CSharp.csproj.FileListAbsolute.txt
文件 986 2016-09-20 10:55 RS232串口通讯CSharp\RS232串口通讯CSharp\obj\Debug\RS232串口通讯CSharp.csproj.GenerateResource.Cache
文件 35840 2016-09-20 10:55 RS232串口通讯CSharp\RS232串口通讯CSharp\obj\Debug\RS232串口通讯CSharp.dll
文件 180 2016-09-20 10:55 RS232串口通讯CSharp\RS232串口通讯CSharp\obj\Debug\RS232串口通讯CSharp.frmTest.resources
文件 180 2016-09-20 10:55 RS232串口通讯CSharp\RS232串口通讯CSharp\obj\Debug\RS232串口通讯CSharp.frmUserValidating.resources
文件 180 2016-09-20 10:55 RS232串口通讯CSharp\RS232串口通讯CSharp\obj\Debug\RS232串口通讯CSharp.MCJS50_Rs232.resources
文件 54784 2016-09-20 10:55 RS232串口通讯CSharp\RS232串口通讯CSharp\obj\Debug\RS232串口通讯CSharp.pdb
............此处省略29个文件信息
相关资源
- C#串口通信程序(VS2010)(serialPort组
- 最新Trimble全站仪串口通讯
- c#串口通信(支持Hex/ascii码消息发送)
- C#串口通信之基恩士读码器读二维码
- 串口调试助手代码(XCOM V2.0)
- 多功能串口助手(附源码)
- 电子秤重量读取(串口通讯)
- 串口数据监测助手(工程源码)
- C#实现串口上位机
- C# RS232串口通信
- 三菱Q-PLC与C#串口
- c# 串口通讯的(收发数据)
- Csharp串口通讯
- c#获取串口
- WPF开发串口调试助手
- 串口通讯工具源码
- C#串口通讯
- 串口上位机
- Modbus通讯 串口通讯
- C# 串口通讯源码(简易串口助手)
- IAP小工具(Ymodem-IAP)源码
- C#串口dll及
- 松下PLC与C#通讯串口调试入门教程.z
- vb调用c#编写的串口DLL文件(vb源码
- C#串口通讯代码
- C#串口通信及数据表格存储
- c# 波形显示上位机代码
- 串口通讯助手C#源代码
- C#串口调试工具源码
- RFID仓储管理系统
评论
共有 条评论