-
大小: 108KB文件類型: .rar金幣: 2下載: 0 次發布日期: 2021-05-12
- 語言: C#
- 標簽:
資源簡介
modbus C#串口調試源碼(功能完善最完美非常具有參考價值)而且運行穩定

代碼片段和文件信息
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.Threading;
using?System.IO;
namespace?Demo
{
????public?partial?class?myForm?:?Form
????{
????????private?string?btn_sender?=?““;
????????private?const?int?read_num?=?99;
????????private?const?int?read_num2?=?60;
????????private?Boolean?received?=?false;
????????public?myForm()
????????{
????????????InitializeComponent();
????????}
????????private?void?myForm_Load(object?sender?EventArgs?e)
????????{
????????????comboBoxPortName.SelectedIndex?=?0;
????????????comboBoxBaudRate.SelectedIndex?=?6;
????????????comboBoxParity.SelectedIndex?=?1;
????????????comboBoxDataBits.SelectedIndex?=?0;
????????????comboBoxStopBits.SelectedIndex?=?0;
????????????combo3.SelectedIndex?=?1;
????????????TxtMachAdd.Text?=?“1“;
????????????btnClose.Enabled?=?false;
????????????btnOpen.Enabled?=?true;
????????????btnsend.Enabled?=?false;
????????????btnread.Enabled?=?false;
????????????btnswitch.Enabled?=?false;
????????????btnget.Enabled?=?false;
????????????btnmulsend.Enabled?=?false;
????????????textBoxInformation.Text?=?“系統初始化成功!\r\n“;
????????}
????????private?void?btnOpen_Click(object?sender?EventArgs?e)
????????{
????????????String?myParity;
????????????String?myStopBits;
????????????myParity?=?comboBoxParity.SelectedItem.ToString();
????????????myStopBits?=?comboBoxStopBits.SelectedItem.ToString();
????????????//設置端口號
????????????mySerialPort.PortName?=?comboBoxPortName.SelectedItem.ToString();
????????????//設置波特率
????????????mySerialPort.BaudRate?=?Convert.ToInt32(comboBoxBaudRate.SelectedItem);
????????????//設置校驗位
????????????switch?(myParity)
????????????{
????????????????case?“None“:
????????????????????mySerialPort.Parity?=?Parity.None;
????????????????????break;
????????????????case?“Even“:
????????????????????mySerialPort.Parity?=?Parity.Even;
????????????????????break;
????????????????case?“Odd“:
????????????????????mySerialPort.Parity?=?Parity.Odd;
????????????????????break;
????????????????default:
????????????????????mySerialPort.Parity?=?Parity.None;
????????????????????break;
????????????}
????????????//設置數據位
????????????mySerialPort.DataBits?=?Convert.ToInt32(comboBoxDataBits.SelectedItem);
????????????//設置停止位
????????????switch?(myStopBits)
????????????{
????????????????case?“1“:
????????????????????mySerialPort.StopBits?=?StopBits.One;
????????????????????break;
????????????????case?“2“:
????????????????????mySerialPort.StopBits?=?StopBits.Two;
????????????????????break;
????????????????default:
????????????????????mySerialPort.StopBits?=?StopBits.One;
????????????????????break;
????????????}
????????????//采用ASCII編碼方式
????????????mySerialPort.Encoding?=?Encoding.ASCII;
????????????//接收到一個字符就觸發接收事件
????????????mySerialPort
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????3754??2012-10-07?08:31??ModbusDemo\Backup\Demo\Demo.csproj
?????文件??????39159??2012-10-10?15:41??ModbusDemo\Backup\Demo\Form1.cs
?????文件??????55435??2012-10-10?15:10??ModbusDemo\Backup\Demo\Form1.Designer.cs
?????文件???????6382??2012-10-10?15:10??ModbusDemo\Backup\Demo\Form1.resx
?????文件????????486??2010-09-25?13:17??ModbusDemo\Backup\Demo\Program.cs
?????文件???????1364??2010-09-25?13:03??ModbusDemo\Backup\Demo\Properties\AssemblyInfo.cs
?????文件???????2858??2010-09-25?13:03??ModbusDemo\Backup\Demo\Properties\Resources.Designer.cs
?????文件???????5612??2010-09-25?13:03??ModbusDemo\Backup\Demo\Properties\Resources.resx
?????文件???????1089??2010-09-25?13:03??ModbusDemo\Backup\Demo\Properties\Settings.Designer.cs
?????文件????????249??2010-09-25?13:03??ModbusDemo\Backup\Demo\Properties\Settings.settings
?????文件????????902??2010-09-25?13:03??ModbusDemo\Backup\Demo.sln
????..A..H.?????25600??2012-10-11?11:21??ModbusDemo\Backup\Demo.suo
?????文件??????36352??2015-07-05?23:00??ModbusDemo\Demo\bin\Debug\Demo.exe
?????文件??????62976??2015-07-05?23:00??ModbusDemo\Demo\bin\Debug\Demo.pdb
?????文件??????11608??2016-06-29?10:21??ModbusDemo\Demo\bin\Debug\Demo.vshost.exe
?????文件????????490??2009-08-31?00:40??ModbusDemo\Demo\bin\Debug\Demo.vshost.exe.manifest
?????文件???????4073??2015-07-05?22:59??ModbusDemo\Demo\Demo.csproj
?????文件??????39159??2012-10-10?15:41??ModbusDemo\Demo\Form1.cs
?????文件??????55435??2012-10-10?15:10??ModbusDemo\Demo\Form1.Designer.cs
?????文件???????6382??2012-10-10?15:10??ModbusDemo\Demo\Form1.resx
?????文件???????3287??2016-06-29?10:21??ModbusDemo\Demo\obj\Debug\Demo.csproj.FileListAbsolute.txt
?????文件????????902??2015-07-05?23:00??ModbusDemo\Demo\obj\Debug\Demo.csproj.GenerateResource.Cache
?????文件??????36352??2015-07-05?23:00??ModbusDemo\Demo\obj\Debug\Demo.exe
?????文件????????180??2015-07-05?23:00??ModbusDemo\Demo\obj\Debug\Demo.myForm.resources
?????文件??????62976??2015-07-05?23:00??ModbusDemo\Demo\obj\Debug\Demo.pdb
?????文件????????180??2015-07-05?23:00??ModbusDemo\Demo\obj\Debug\Demo.Properties.Resources.resources
?????文件???????1229??2016-06-29?10:21??ModbusDemo\Demo\obj\Debug\DesignTimeResolveAssemblyReferences.cache
?????文件???????6083??2015-08-17?22:49??ModbusDemo\Demo\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件???????4608??2015-07-05?22:59??ModbusDemo\Demo\obj\Debug\TempPE\Properties.Resources.Designer.cs.dll
?????文件????????486??2010-09-25?13:17??ModbusDemo\Demo\Program.cs
............此處省略29個文件信息
- 上一篇:ASP.NET外文翻譯
- 下一篇:C#調用打印機打印
評論
共有 條評論