资源简介
点击按钮,搜索所有串口一一匹配波特率,看是否成功,
代码片段和文件信息
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;
using newProtocolLB;
namespace WindowsFormsApp2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
SerialPort serialPort = new SerialPort();
int[] Baud_rate = { 9600 115200 };
int intLenth = 0;
byte[] data = new byte[500];
private DeviceType DeviceState { get; set; }
bool isSuccess = false;
private void Form1_Load(object sender EventArgs e)
{
label3.Text = “就绪“;
string[] ports = SerialPort.GetPortNames();
for (int i = 0; i < ports.Count(); i++)
{
comboBox1.Items.Add(ports[i].ToString());
}
comboBox1.SelectedIndex = 0;///默认选择第一个
comboBox2.Items.Add(Baud_rate[0]);
comboBox2.Items.Add(Baud_rate[1]);
comboBox2.SelectedIndex = 0;
}
private void button1_Click(object sender EventArgs e)
{
comboBox1.Items.Clear();
string[] ports = SerialPort.GetPortNames();
for (int i = 0; i < ports.Count(); i++)
{
comboBox1.Items.Add(ports[i].ToString());
}
comboBox1.SelectedIndex = 0;///默认选择第一个
if (!serialPort.IsOpen)
{
try
{
//serialPort1.BaudRate = 115200;
serialPort.StopBits = StopBits.One;//停止位1
serialPort.DataBits = 8;//设置数据位
serialPort.Parity = Parity.None;
//serialPort.Open();
for (int h = 0; h < Baud_rate.Count(); h++)
{
serialPort.BaudRate = Baud_rate[h];
for (int f = 0; f < ports.Count(); f++)
{
serialPort.PortName = ports[f];
comboBox1.SelectedIndex = f;
comboBox2.SelectedIndex = h;
if (TryRead(serialPort))
{
isSuccess = true;
label3.Text = “连接成功“;
comboBox1.Enabled = false;
comboBox2.Enabled = false;
return;
}
}
}
if (!isSuccess)
{
comboBox1.Enabled = true;
comboBox2.Enabled = true;
label3.Text = “连接失败!!!心里没点B数吗?
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2019-01-16 11:22 WindowsFormsApp2\
目录 0 2019-01-16 11:22 WindowsFormsApp2\.vs\
目录 0 2019-01-16 11:22 WindowsFormsApp2\.vs\WindowsFormsApp2\
目录 0 2019-01-16 11:23 WindowsFormsApp2\.vs\WindowsFormsApp2\v15\
文件 50176 2019-01-17 09:41 WindowsFormsApp2\.vs\WindowsFormsApp2\v15\.suo
目录 0 2019-01-16 11:23 WindowsFormsApp2\.vs\WindowsFormsApp2\v15\Server\
目录 0 2019-01-16 11:23 WindowsFormsApp2\.vs\WindowsFormsApp2\v15\Server\sqlite3\
目录 0 2019-01-16 19:48 WindowsFormsApp2\WindowsFormsApp2\
文件 189 2019-01-16 11:22 WindowsFormsApp2\WindowsFormsApp2\App.config
目录 0 2019-01-16 11:22 WindowsFormsApp2\WindowsFormsApp2\bin\
目录 0 2019-01-16 14:10 WindowsFormsApp2\WindowsFormsApp2\bin\Debug\
文件 16384 2015-05-26 11:52 WindowsFormsApp2\WindowsFormsApp2\bin\Debug\newProtocolLB.dll
文件 20480 2019-01-16 19:48 WindowsFormsApp2\WindowsFormsApp2\bin\Debug\WindowsFormsApp2.exe
文件 189 2019-01-16 11:22 WindowsFormsApp2\WindowsFormsApp2\bin\Debug\WindowsFormsApp2.exe.config
文件 58880 2019-01-16 19:48 WindowsFormsApp2\WindowsFormsApp2\bin\Debug\WindowsFormsApp2.pdb
文件 7761 2019-01-16 19:48 WindowsFormsApp2\WindowsFormsApp2\Form1.cs
文件 4938 2019-01-16 19:48 WindowsFormsApp2\WindowsFormsApp2\Form1.Designer.cs
文件 6016 2019-01-16 19:48 WindowsFormsApp2\WindowsFormsApp2\Form1.resx
目录 0 2019-01-16 11:22 WindowsFormsApp2\WindowsFormsApp2\obj\
目录 0 2019-01-16 19:48 WindowsFormsApp2\WindowsFormsApp2\obj\Debug\
文件 1443 2019-01-16 19:41 WindowsFormsApp2\WindowsFormsApp2\obj\Debug\DesignTimeResolveAssemblyReferences.cache
文件 7334 2019-01-16 14:08 WindowsFormsApp2\WindowsFormsApp2\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
文件 0 2019-01-16 11:22 WindowsFormsApp2\WindowsFormsApp2\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
文件 0 2019-01-16 11:22 WindowsFormsApp2\WindowsFormsApp2\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
文件 0 2019-01-16 11:22 WindowsFormsApp2\WindowsFormsApp2\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
目录 0 2019-01-16 11:22 WindowsFormsApp2\WindowsFormsApp2\obj\Debug\TempPE\
文件 0 2019-01-16 19:48 WindowsFormsApp2\WindowsFormsApp2\obj\Debug\WindowsFormsApp2.csproj.CopyComplete
文件 42 2019-01-16 14:08 WindowsFormsApp2\WindowsFormsApp2\obj\Debug\WindowsFormsApp2.csproj.CoreCompileInputs.cache
文件 1362 2019-01-16 14:10 WindowsFormsApp2\WindowsFormsApp2\obj\Debug\WindowsFormsApp2.csproj.FileListAbsolute.txt
文件 1012 2019-01-16 19:48 WindowsFormsApp2\WindowsFormsApp2\obj\Debug\WindowsFormsApp2.csproj.GenerateResource.cache
文件 46850 2019-01-16 14:09 WindowsFormsApp2\WindowsFormsApp2\obj\Debug\WindowsFormsApp2.csprojAssemblyReference.cache
............此处省略15个文件信息
- 上一篇:程序员项目交接文档
- 下一篇:Burp_suite_Pro_v2.1.txt
相关资源
- QTcreater串口功能代码
- 显示图像的LABVIEW上位机
- 指纹模块测试上位机 .zip
- ESP8266与上位机通信代码
- 基于RFID的同学签到系统的设计
- modbus上位机监控软件
- OpenGL+IMU显示姿态
- 上位机发送FINS TCP命令读写PLC数据
- dalsa线阵相机上位机使用详细文档
- dsp2812的电机调速程序,并可以通过与
- 西门子S7200与上位机TCP通讯协议(破解
- 机器人 控制器上位机
- AVRUSB单片机编程与上位机编程教程重
- vs2017开发的上位机接收下位机工程
- CSerial串口标准函数头文件
- KJ333新型煤矿安全监控系统上位机软件
- GRBL上位机,grbl_controler
- USBCAB.dll、ControlCAN.dll64位库+QT5例程+上
- CoFlash-1.5.1.7z
- 基于Qt的串口上位机控制蓝牙小车程序
- Saleae逻辑分析仪上位机软件
- PN532-NFC上位机破解版
- Labview上位机与西门子PLC系列通信.zi
- ADAM4117研华AD采集器上位机软件配置说
- CANoe写bootloader上位机代码.rar
- 基于CAN通讯的BootLoader上位机
- STM32在线升级IAP boot app 上位机源码.
- 基于QT5.7给STM32F103进行串口升级的上位
- 698_45上位机测试软件(1).zip
- INTOUCH 2017Update3 sp1链接.rar
评论
共有 条评论