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

资源简介

c#控制stme32 驱动电机,同时还有红外线判断电机移动位置

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;

namespace test_app
{
    public partial class fish : Form
    {
        private SerialPort ComDevice = new SerialPort();
        public fish()
        {
            InitializeComponent();
            this.init();
        }
        public void init()
        {
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            comboBox_COMList.Items.AddRange(SerialPort.GetPortNames());
            if (comboBox_COMList.Items.Count > 0)
            {
                comboBox_COMList.SelectedIndex = 0;
            }
            
            comboBox_rate.SelectedIndex = 5;
            comboBox_databit.SelectedIndex = 0;
            comboBox_parity.SelectedIndex = 0;
            comboBox_stopbit.SelectedIndex = 0;
            //pictureBox1.BackgroundImage = Properties.Resources.red;

            //ComDevice.DataReceived += new SerialDataReceivedEventHandler(Com_DataReceived);//绑定事件
            
        }




        private void btn_openCOM_Click(object sender EventArgs e)
        {
            if (comboBox_COMList.Items.Count <= 0)
            {
                MessageBox.Show(“没有发现串口请检查线路!“);
                return;
            }

            if (ComDevice.IsOpen == false)
            {
                ComDevice.PortName = comboBox_COMList.SelectedItem.ToString();
                ComDevice.BaudRate = Convert.ToInt32(comboBox_rate.SelectedItem.ToString());
                ComDevice.Parity = (Parity)Convert.ToInt32(comboBox_parity.SelectedIndex.ToString());
                ComDevice.DataBits = Convert.ToInt32(comboBox_databit.SelectedItem.ToString());
                ComDevice.StopBits = (StopBits)Convert.ToInt32(comboBox_stopbit.SelectedItem.ToString());
                try
                {
                    ComDevice.Open();
                    //btnSend.Enabled = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message “错误“ MessageBoxButtons.OK MessageBoxIcon.Error);
                    return;
                }
                btn_openCOM.Text = “关闭串口“;
                //pictureBox1.BackgroundImage = Properties.Resources.green;
            }
            else
            {
                try
                {
                    ComDevice.Close();
                    //btnSend.Enabled = false;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message “错误“ MessageBoxButtons.OK MessageBoxIcon.Error);
                }
                btn_openCOM.Text = “打开串口“;
                //pictureBox1.BackgroundImage = Properties.Resources.red;
            }

            comboBox_COM

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

     文件        142  2018-08-26 22:08  test_app\.vs\test_app\DesignTimeBuild\.dtbcache

    ..A..H.     52736  2018-11-14 22:20  test_app\.vs\test_app\v15\.suo

     文件          0  2018-08-05 00:20  test_app\.vs\test_app\v15\Server\sqlite3\db.lock

     文件     585728  2018-08-10 07:54  test_app\.vs\test_app\v15\Server\sqlite3\storage.ide

     文件      32768  2018-11-05 22:00  test_app\.vs\test_app\v15\Server\sqlite3\storage.ide-shm

     文件    4120032  2018-09-09 20:48  test_app\.vs\test_app\v15\Server\sqlite3\storage.ide-wal

     文件        189  2018-08-05 00:19  test_app\test_app\App.config

     文件      16384  2018-08-10 21:57  test_app\test_app\bin\Debug\test_app.exe

     文件        189  2018-08-05 00:19  test_app\test_app\bin\Debug\test_app.exe.config

     文件      26112  2018-08-10 21:57  test_app\test_app\bin\Debug\test_app.pdb

     文件      35840  2018-09-08 10:30  test_app\test_app\bin\Release\Fishing.exe

     文件        189  2018-08-05 00:19  test_app\test_app\bin\Release\Fishing.exe.config

     文件      26112  2018-09-08 10:30  test_app\test_app\bin\Release\Fishing.pdb

     文件       9662  2018-08-11 08:40  test_app\test_app\favicon-20180811083905493.ico

     文件       7366  2018-09-08 10:30  test_app\test_app\Form1.cs

     文件      18594  2018-09-08 10:30  test_app\test_app\Form1.Designer.cs

     文件      20617  2018-09-08 10:30  test_app\test_app\Form1.resx

     文件       1443  2018-08-05 21:06  test_app\test_app\obj\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       7156  2018-08-05 00:22  test_app\test_app\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件          0  2018-08-05 00:19  test_app\test_app\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs

     文件          0  2018-08-05 00:19  test_app\test_app\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs

     文件          0  2018-08-05 00:19  test_app\test_app\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs

     文件         42  2018-08-10 21:49  test_app\test_app\obj\Debug\test_app.csproj.CoreCompileInputs.cache

     文件        674  2018-08-10 21:49  test_app\test_app\obj\Debug\test_app.csproj.FileListAbsolute.txt

     文件       1012  2018-08-10 21:57  test_app\test_app\obj\Debug\test_app.csproj.GenerateResource.cache

     文件      16384  2018-08-10 21:57  test_app\test_app\obj\Debug\test_app.exe

     文件        180  2018-08-10 21:57  test_app\test_app\obj\Debug\test_app.fish.resources

     文件      26112  2018-08-10 21:57  test_app\test_app\obj\Debug\test_app.pdb

     文件        180  2018-08-10 21:49  test_app\test_app\obj\Debug\test_app.Properties.Resources.resources

     文件       1605  2018-09-02 17:19  test_app\test_app\obj\Release\DesignTimeResolveAssemblyReferences.cache

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

评论

共有 条评论