• 大小: 138KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-14
  • 语言: C#
  • 标签:

资源简介

非常适合新手学习的一款上位机,基本实现所需要的功能。代码简单明了

资源截图

代码片段和文件信息

using System;
using System.IO.Ports;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using INIFILE;
using System.Text.Regularexpressions;

namespace SerialPortConnection
{
    public partial class Form1 : Form
    {
        SerialPort sp1 = new SerialPort();
        //sp1.ReceivedBytesThreshold = 1;//只要有1个字符送达端口时便触发DataReceived事件 
         
        public Form1()
        {
            InitializeComponent();
        }

        //加载
        private void Form1_Load(object sender EventArgs e)
        {
            INIFILE.Profile.LoadProfile();//加载所有
            
           // 预置波特率
            switch (Profile.G_BAUDRATE)
            {
                case “300“:
                    cbBaudRate.SelectedIndex = 0;
                    break;
                case “600“:
                    cbBaudRate.SelectedIndex = 1;
                    break;
                case “1200“:
                    cbBaudRate.SelectedIndex = 2;
                    break; 
                case “2400“:
                    cbBaudRate.SelectedIndex = 3;
                    break;
                case “4800“:
                    cbBaudRate.SelectedIndex = 4;
                    break;
                case “9600“:
                    cbBaudRate.SelectedIndex = 5;
                    break;
                case “19200“:
                    cbBaudRate.SelectedIndex = 6;
                    break; 
                case “38400“:
                    cbBaudRate.SelectedIndex = 7;
                    break;
                case “115200“:
                    cbBaudRate.SelectedIndex = 8;
                    break;
                default:
                    {
                        MessageBox.Show(“波特率预置参数错误。“);
                        return;
                    }                  
            }

            //预置波特率
            switch (Profile.G_DATABITS)
            {
                case “5“:
                    cbDataBits.SelectedIndex = 0;
                    break;
                case “6“:
                    cbDataBits.SelectedIndex = 1;
                    break; 
                case “7“:
                    cbDataBits.SelectedIndex = 2;
                    break; 
                case  “8“:
                    cbDataBits.SelectedIndex = 3;
                    break;
                default:
                    {
                        MessageBox.Show(“数据位预置参数错误。“);
                        return;
                    }

            }
            //预置停止位
            switch (Profile.G_STOP)
            {
                case “1“:
                    cbStop.SelectedIndex = 0;
                        break;
                case “1.5“:
                    cbStop.SelectedIndex = 1;
                    break;
                case “2“:
                    cbStop.Selec

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-10-27 11:15  SerialPortConnection\
     目录           0  2018-10-27 11:15  SerialPortConnection\.vs\
     目录           0  2018-10-27 11:15  SerialPortConnection\.vs\SerialPortConnection\
     目录           0  2018-10-27 11:15  SerialPortConnection\.vs\SerialPortConnection\v14\
     文件       26624  2018-10-27 11:50  SerialPortConnection\.vs\SerialPortConnection\v14\.suo
     目录           0  2018-10-27 11:14  SerialPortConnection\Backup\
     目录           0  2018-10-27 11:14  SerialPortConnection\Backup\SerialPortConnection\
     文件       26561  2012-08-15 14:13  SerialPortConnection\Backup\SerialPortConnection\Form1.Designer.cs
     文件       20297  2012-08-15 17:18  SerialPortConnection\Backup\SerialPortConnection\Form1.cs
     文件        6582  2012-08-15 14:13  SerialPortConnection\Backup\SerialPortConnection\Form1.resx
     文件        7503  2012-08-09 10:13  SerialPortConnection\Backup\SerialPortConnection\IniFile.cs
     文件        1468  2012-08-14 11:37  SerialPortConnection\Backup\SerialPortConnection\Profile.cs
     文件         512  2012-08-06 14:57  SerialPortConnection\Backup\SerialPortConnection\Program.cs
     目录           0  2018-10-27 11:14  SerialPortConnection\Backup\SerialPortConnection\Properties\
     文件        1476  2012-08-06 14:57  SerialPortConnection\Backup\SerialPortConnection\Properties\AssemblyInfo.cs
     文件        2869  2012-08-06 14:57  SerialPortConnection\Backup\SerialPortConnection\Properties\Resources.Designer.cs
     文件        5612  2012-08-06 14:57  SerialPortConnection\Backup\SerialPortConnection\Properties\Resources.resx
     文件        1105  2012-08-06 14:57  SerialPortConnection\Backup\SerialPortConnection\Properties\Settings.Designer.cs
     文件         249  2012-08-06 14:57  SerialPortConnection\Backup\SerialPortConnection\Properties\Settings.settings
     文件        3862  2012-08-09 10:13  SerialPortConnection\Backup\SerialPortConnection\SerialPortConnection.csproj
     文件         950  2012-08-06 14:57  SerialPortConnection\Backup\SerialPortConnection.sln
     文件       17408  2018-05-16 13:49  SerialPortConnection\Backup\SerialPortConnection.v11.suo
     目录           0  2018-11-02 11:34  SerialPortConnection\SerialPortConnection\
     文件       26697  2018-11-02 11:34  SerialPortConnection\SerialPortConnection\Form1.Designer.cs
     文件       20542  2018-11-02 11:34  SerialPortConnection\SerialPortConnection\Form1.cs
     文件        6582  2018-11-02 11:34  SerialPortConnection\SerialPortConnection\Form1.resx
     文件        7503  2012-08-09 10:13  SerialPortConnection\SerialPortConnection\IniFile.cs
     文件        1468  2012-08-14 11:37  SerialPortConnection\SerialPortConnection\Profile.cs
     文件         512  2012-08-06 14:57  SerialPortConnection\SerialPortConnection\Program.cs
     目录           0  2018-10-27 11:14  SerialPortConnection\SerialPortConnection\Properties\
     文件        1476  2012-08-06 14:57  SerialPortConnection\SerialPortConnection\Properties\AssemblyInfo.cs
............此处省略39个文件信息

评论

共有 条评论

相关资源