• 大小: 1.03MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-08-29
  • 语言: C#
  • 标签: 杜洋  上位机  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;

namespace 串口控制
{
    public partial class Form1 : Form
    {
        //device 1
        const byte DeviceOpen1 = 0x01;
        const byte DeviceClose1 = 0x81;
        //device 2
        const byte DeviceOpen2 = 0x02;
        const byte DeviceClose2 = 0x82;
        //device 3
        const byte DeviceOpen3 = 0x03;
        const byte DeviceClose3 = 0x83;
        //SerialPort Write Buffer
        bool Button1Statue;
        byte[] SerialPortDataBuffer = new byte[1];
        public Form1()
        {
            InitializeComponent();                                      //窗口构造
        }
        private void button1_Click(object sender EventArgs e)
        {
            if (serialPort1.IsOpen)                                     //串口打开就关闭
            {
                try
                {
                    serialPort1.Close();
                }
                catch { }                                               //确保万无一失
                //button1.Text = “打开串口“;
                button1.BackgroundImage = Properties.Resources.Image2;  //灭
                Button1Statue = false;                                  //按钮状态
            }
            else
            {
                try
                {
                    serialPort1.PortName = comboBox1.Text;              //端口号
                    serialPort1.Open();                                 //打开端口
                    //button1.Text = “关闭串口“;
                    button1.BackgroundImage = Properties.Resources.Image1;//亮
                    Button1Statue = true;                                //按钮状态
                }
                catch
                {
                    MessageBox.Show(“串口打开失败““错误“);
                }
            }
        }

        private void Form1_Load(object sender EventArgs e)
        {
            SearchAndAddSerialToComboBox(serialPort1 comboBox1);
        }

        private void WriteByteToSerialPort(byte data)                   //单字节写入串口
        {
            byte[] Buffer = new byte [2]{0x00 data };                       //定义数组
            if (serialPort1.IsOpen)                                     //传输数据的前提是端口已打开
            {
                try
                {
                    serialPort1.Write(Buffer 0 2);                    //写数据
                }
                catch 
                {
                    MessageBox.Show(“串口数据发送出错,请检查.““错误“);//错误处理
                }
            }
        }

        private void SearchAndAddSerialToComboBox(SerialPort MyPortComboBox MyBox)
        {                                                               //将可用端口号添加到ComboBox
            string[] MyString = new string[20];                         //最多容纳20个,太多会影响调试效率
 

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        962  2013-07-16 00:16  杜洋C#资料\第2、3集:C#软件项目\WindowsFormsApplication1\WindowsFormsApplication1.sln

    ..A..H.     43520  2013-07-31 11:42  杜洋C#资料\第2、3集:C#软件项目\WindowsFormsApplication1\WindowsFormsApplication1.v11.suo

     文件       1843  2013-12-05 09:47  杜洋C#资料\第2、3集:C#软件项目\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs

     文件       5391  2013-07-17 00:45  杜洋C#资料\第2、3集:C#软件项目\WindowsFormsApplication1\WindowsFormsApplication1\Form1.Designer.cs

     文件       6011  2013-07-17 00:47  杜洋C#资料\第2、3集:C#软件项目\WindowsFormsApplication1\WindowsFormsApplication1\Form1.resx

     文件        505  2013-07-16 00:16  杜洋C#资料\第2、3集:C#软件项目\WindowsFormsApplication1\WindowsFormsApplication1\Program.cs

     文件       3761  2013-07-16 00:22  杜洋C#资料\第2、3集:C#软件项目\WindowsFormsApplication1\WindowsFormsApplication1\WindowsFormsApplication1.csproj

     文件       3072  2013-12-05 11:39  杜洋C#资料\第2、3集:C#软件项目\WindowsFormsApplication1\WindowsFormsApplication1\WindowsFormsApplication1.suo

     文件       1368  2013-07-16 00:16  杜洋C#资料\第2、3集:C#软件项目\WindowsFormsApplication1\WindowsFormsApplication1\Properties\AssemblyInfo.cs

     文件       2900  2013-07-16 00:16  杜洋C#资料\第2、3集:C#软件项目\WindowsFormsApplication1\WindowsFormsApplication1\Properties\Resources.Designer.cs

     文件       5612  2013-07-16 00:16  杜洋C#资料\第2、3集:C#软件项目\WindowsFormsApplication1\WindowsFormsApplication1\Properties\Resources.resx

     文件       1111  2013-07-16 00:16  杜洋C#资料\第2、3集:C#软件项目\WindowsFormsApplication1\WindowsFormsApplication1\Properties\Settings.Designer.cs

     文件        249  2013-07-16 00:16  杜洋C#资料\第2、3集:C#软件项目\WindowsFormsApplication1\WindowsFormsApplication1\Properties\Settings.settings

     文件       6868  2013-07-16 00:22  杜洋C#资料\第2、3集:C#软件项目\WindowsFormsApplication1\WindowsFormsApplication1\obj\Release\DesignTimeResolveAssemblyReferencesInput.cache

     文件       1415  2013-07-16 22:15  杜洋C#资料\第2、3集:C#软件项目\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       6250  2013-12-05 13:33  杜洋C#资料\第2、3集:C#软件项目\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件       2901  2013-12-05 13:33  杜洋C#资料\第2、3集:C#软件项目\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.csproj.FileListAbsolute.txt

     文件        975  2013-07-17 00:47  杜洋C#资料\第2、3集:C#软件项目\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.csproj.GenerateResource.Cache

     文件       2143  2013-07-16 00:22  杜洋C#资料\第2、3集:C#软件项目\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.csprojResolveAssemblyReference.cache

     文件      10240  2013-12-05 09:47  杜洋C#资料\第2、3集:C#软件项目\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.exe

     文件        180  2013-12-05 09:46  杜洋C#资料\第2、3集:C#软件项目\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.Form1.resources

     文件      34304  2013-12-05 09:47  杜洋C#资料\第2、3集:C#软件项目\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.pdb

     文件        180  2013-12-05 09:46  杜洋C#资料\第2、3集:C#软件项目\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.Properties.Resources.resources

     文件        512  2013-12-05 09:46  杜洋C#资料\第2、3集:C#软件项目\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\GenerateResource.read.1.tlog

     文件       1174  2013-12-05 09:46  杜洋C#资料\第2、3集:C#软件项目\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\GenerateResource.write.1.tlog

     文件      22472  2013-07-16 00:22  杜洋C#资料\第2、3集:C#软件项目\WindowsFormsApplication1\WindowsFormsApplication1\bin\Release\WindowsFormsApplication1.vshost.exe

     文件        490  2009-08-31 00:40  杜洋C#资料\第2、3集:C#软件项目\WindowsFormsApplication1\WindowsFormsApplication1\bin\Release\WindowsFormsApplication1.vshost.exe.manifest

     文件      10240  2013-12-05 09:47  杜洋C#资料\第2、3集:C#软件项目\WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.exe

     文件      34304  2013-12-05 09:47  杜洋C#资料\第2、3集:C#软件项目\WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.pdb

     文件      11592  2013-12-05 13:33  杜洋C#资料\第2、3集:C#软件项目\WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.vshost.exe

............此处省略555个文件信息

评论

共有 条评论