• 大小: 1.58MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-09-02
  • 语言: 其他
  • 标签: C#  串口  

资源简介

使用STM32搭配OV7670采集图像,并将图像通过串口上传到上位机,上位机接受数据并处理数据,最终显示彩色图像

资源截图

代码片段和文件信息

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;
using System.IO;

namespace image
{
    public partial class Form1 : Form
    {

        #region 全局变量

        int bmp_width  = 240;                           //定义接收数据的宽度
        int bmp_height = 320;                           //定义接受图片的高度

        Bitmap bmp;                                     //定义一个bmp变量用于显示与储存图片

        int hang = 0 lie = 0;                          //用于写入图像时的行列指针
        //串口发送回的数据以8为为依据将rgb565拆分成2个字节发送故需要以下变量
        bool isheight = true;                           //判断是否为高位的标志位true表示当前数据为高位数据
        int heightdate = 0;                             //用于存储高8位的储存单元

        bool pic_MoveFlag = false;                      //pic移动的标志位
        int pic_xPos = 0;                               //鼠标移动的偏移量
        int pic_yPos = 0;

        string SelectPath = ““;

        int orderID = 1;

        #endregion

        /// 
        /// 窗口初始化
        /// 

        public Form1()
        {
            InitializeComponent();
        }

        private void ShowDebug(string str)
        {
            try
            {
                int MaxLength = 14;
                int lines = (str.Length / MaxLength) + 1;
                textBox1.Text += DateTime.Now.ToString(orderID.ToString(“000“) + “·[yy-MM-dd HH:mm:ss]:\r\n“);
                orderID++;
                for (int i = 0; i < lines; i++)
                {
                    if (i == lines - 1)
                    {
                        textBox1.Text += “- “
                            + str.Substring(i * MaxLength str.Length % MaxLength)
                            + “\r\n“;
                    }
                    else
                    {
                        textBox1.Text += “- “
                            + str.Substring(i * MaxLength MaxLength) + “\r\n“;
                    }
                }
                textBox1.Text += “\r\n\r\n“;
            }
            catch { }
        }

        /// 
        /// 窗口UI初始化调用
        /// 

        /// 
        /// 
        private void Form1_Load(object sender EventArgs e)
        {
            button1_Click(null null);                  //更新串口号   
            comboBox2.SelectedIndex = 4;                //选中默认波特率
            ShowDebug(“系统开始运行。“);
            bmp = new Bitmap(bmp_height bmp_width);
        }

        /// 
        /// 更新按键按下可自动查找可用串口
        /// 

        /// 
        /// 
        private void button1_Click(object sender EventArgs e)
        {
            comboBox1.Items.Clear();
            for (int i = 0; i < 30; i++) 

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

     文件        187  2018-07-03 23:00  (2017.09.16)串口图像上位机\image\App.config

     文件     158208  2018-07-03 23:16  (2017.09.16)串口图像上位机\image\bin\Debug\image.exe

     文件        187  2018-07-03 23:16  (2017.09.16)串口图像上位机\image\bin\Debug\image.exe.config

     文件      46592  2018-07-03 23:16  (2017.09.16)串口图像上位机\image\bin\Debug\image.pdb

     文件      23168  2018-07-03 23:16  (2017.09.16)串口图像上位机\image\bin\Debug\image.vshost.exe

     文件        187  2018-07-03 23:16  (2017.09.16)串口图像上位机\image\bin\Debug\image.vshost.exe.config

     文件        490  2018-07-03 23:16  (2017.09.16)串口图像上位机\image\bin\Debug\image.vshost.exe.manifest

     文件      67646  2018-07-03 23:00  (2017.09.16)串口图像上位机\image\Demo.ico

     文件      17792  2018-07-03 23:00  (2017.09.16)串口图像上位机\image\Form1.cs

     文件      17951  2018-07-03 23:00  (2017.09.16)串口图像上位机\image\Form1.Designer.cs

     文件     107997  2018-07-03 23:00  (2017.09.16)串口图像上位机\image\Form1.resx

     文件       3945  2018-07-03 23:00  (2017.09.16)串口图像上位机\image\image.csproj

     文件       1609  2018-07-03 23:16  (2017.09.16)串口图像上位机\image\obj\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       7087  2018-07-03 23:16  (2017.09.16)串口图像上位机\image\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件       3068  2018-07-03 23:16  (2017.09.16)串口图像上位机\image\obj\Debug\image.csproj.FileListAbsolute.txt

     文件        977  2018-07-03 23:16  (2017.09.16)串口图像上位机\image\obj\Debug\image.csproj.GenerateResource.Cache

     文件       2211  2018-07-03 23:16  (2017.09.16)串口图像上位机\image\obj\Debug\image.csprojResolveAssemblyReference.cache

     文件     158208  2018-07-03 23:16  (2017.09.16)串口图像上位机\image\obj\Debug\image.exe

     文件      68212  2018-07-03 23:16  (2017.09.16)串口图像上位机\image\obj\Debug\image.Form1.resources

     文件      46592  2018-07-03 23:16  (2017.09.16)串口图像上位机\image\obj\Debug\image.pdb

     文件        180  2018-07-03 23:16  (2017.09.16)串口图像上位机\image\obj\Debug\image.Properties.Resources.resources

     文件          0  2018-07-03 23:16  (2017.09.16)串口图像上位机\image\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs

     文件          0  2018-07-03 23:16  (2017.09.16)串口图像上位机\image\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs

     文件          0  2018-07-03 23:16  (2017.09.16)串口图像上位机\image\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs

     文件        579  2018-07-03 23:00  (2017.09.16)串口图像上位机\image\Program.cs

     文件       1434  2018-07-03 23:09  (2017.09.16)串口图像上位机\image\Properties\AssemblyInfo.cs

     文件       2862  2018-07-03 23:09  (2017.09.16)串口图像上位机\image\Properties\Resources.Designer.cs

     文件       5612  2018-07-03 23:09  (2017.09.16)串口图像上位机\image\Properties\Resources.resx

     文件       1092  2018-07-03 23:09  (2017.09.16)串口图像上位机\image\Properties\Settings.Designer.cs

     文件        249  2018-07-03 23:09  (2017.09.16)串口图像上位机\image\Properties\Settings.settings

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

评论

共有 条评论