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

资源简介

用c#中的控件SerialPort写的串口调试,上位机程序,内附串口通信协议,下位机有AVR单片机写成!

资源截图

代码片段和文件信息

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;
using System.Threading;
namespace serialize
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
         /* 
             * 部分代码对照表
             * 
               FROM       TO       代码(CODE)       CMD            意思(CMD)           NOTE(注视)
             *  PC       单片机      0X11         CMD_JOINED     告知单片机已加入网络    不用查看bodylength
             *  PC       单片机      0X12         CMD_TABINFO    告知单片机输入桌位信息
             *  PC       单片机      0X13         CMD_TABINFO    告知单片机下单成功      不用查看bodylength
             *  
             * 
             * 
              单片机      PC         0X21         CMD_JOIN       单片机申请加入网络      不用查看bodylength
             *单片机      PC         0X22         CMD_EXIT       单片机申请退出网络      不用查看bodylength
             *单片机      PC         0X23         CMD_TABLE      单片机申请查看空桌      不用查看bodylength
             *单片机      PC         0X24         CMD_DISH       单片机发送菜单   
             *单片机      PC         0X25         CMD_DELTAB     单片机申请删除桌号
          */

        /* 单片机与PC的传输协议:
         *  CMD(1Byte)       bodylength(1Byte)   Body[0]   Body[1]   ...    Body[29]
         * 0X11(CMD_JOINED)  
         * 0X12(CMD_TABINFO)   0X02                51       53                      // 告知单片机有空桌为 51,53号;
         * 0X25(CMD_DELTAB)    0X01                51
         * 0X24(CMD_DISH)      0X03                0X01   0X87   0X6F  //点了三种菜,每种几份见编码规则;
         * 
         * */

        private string binary=““;//用于临时存储从下位机来的字符码。
        private static string received_code;//根据其中的内容执行相应的操作。
        private static string received_cmdcode;//用于从receive_code提取命令的代码(即received_code的第一Byte);
        private static string send_code;//发送给单片机的代码只可能取以下的三个值,发送前必须转换为Binary码;

        private static int  joined=17;//代指 CMD_JOIN(0X11)命令;
        private static int exit_ack = 18;//回复单片机退出网络的确认信号;
        private static UInt32[] protocol=new UInt32[32];
      
        
       //委托类的对象,用于在接收线程中访问主线程的资源receive_textbox;
        private delegate void SetTextbox(string str);
        private SetTextbox set_textboxset_reflectionbox;
        private void Setbox(string str)
        {
            receive_textbox.Text = receive_textbox.Text + “下位机:\n“ + str;
        }

        private void Set_Reflectionbox(string str)
        {
            reflection_textBox.Text = str;
        }

        
        private void send_Click(object sender EventArgs e)
        {

            Test(36 10 19);
            
            /*char  character = Convert.ToChar(joined);
            char[] cha = new char[1];
            cha[0] = character;
            byte[] data = Encoding.ASCII.GetBytes(cha);          
            //send_textbo

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件       19968  2010-03-11 12:19  无线网络协议表.xls
     目录           0  2010-03-22 10:53  serialize\
     目录           0  2010-03-17 21:32  serialize\serialize\
     目录           0  2010-03-29 19:45  serialize\serialize\serialize\
     目录           0  2010-03-22 10:59  serialize\serialize\serialize\bin\
     目录           0  2010-03-28 14:35  serialize\serialize\serialize\bin\Debug\
     文件       53248  2010-03-27 22:02  serialize\serialize\serialize\bin\Debug\AxInterop.WMPLib.dll
     文件      290816  2010-03-27 22:02  serialize\serialize\serialize\bin\Debug\Interop.WMPLib.dll
     文件       13824  2010-03-29 19:45  serialize\serialize\serialize\bin\Debug\serialize.exe
     文件       32256  2010-03-29 19:45  serialize\serialize\serialize\bin\Debug\serialize.pdb
     文件       14328  2010-03-30 20:17  serialize\serialize\serialize\bin\Debug\serialize.vshost.exe
     文件         490  2007-07-21 01:33  serialize\serialize\serialize\bin\Debug\serialize.vshost.exe.manifest
     目录           0  2010-03-22 10:59  serialize\serialize\serialize\bin\Release\
     文件        9216  2010-03-22 11:06  serialize\serialize\serialize\bin\Release\serialize.exe
     文件       19968  2010-03-22 11:06  serialize\serialize\serialize\bin\Release\serialize.pdb
     文件       14328  2010-03-22 11:09  serialize\serialize\serialize\bin\Release\serialize.vshost.exe
     文件         490  2007-07-21 01:33  serialize\serialize\serialize\bin\Release\serialize.vshost.exe.manifest
     文件       16085  2010-03-29 19:45  serialize\serialize\serialize\Form1.cs
     文件        7557  2010-03-29 19:41  serialize\serialize\serialize\Form1.Designer.cs
     文件        6013  2010-03-29 19:41  serialize\serialize\serialize\Form1.resx
     文件        1078  2010-03-22 20:25  serialize\serialize\serialize\Icon.ico
     目录           0  2010-03-22 10:59  serialize\serialize\serialize\obj\
     目录           0  2010-03-29 19:45  serialize\serialize\serialize\obj\Debug\
     文件       53248  2010-03-27 22:02  serialize\serialize\serialize\obj\Debug\AxInterop.WMPLib.dll
     文件      290816  2010-03-27 22:02  serialize\serialize\serialize\obj\Debug\Interop.WMPLib.dll
     目录           0  2010-03-17 21:32  serialize\serialize\serialize\obj\Debug\Refactor\
     文件        2183  2010-03-30 20:17  serialize\serialize\serialize\obj\Debug\serialize.csproj.FileListAbsolute.txt
     文件         847  2010-03-29 19:41  serialize\serialize\serialize\obj\Debug\serialize.csproj.GenerateResource.Cache
     文件         547  2010-03-27 22:02  serialize\serialize\serialize\obj\Debug\serialize.csproj.ResolveComReference.cache
     文件       13824  2010-03-29 19:45  serialize\serialize\serialize\obj\Debug\serialize.exe
     文件         180  2010-03-29 19:41  serialize\serialize\serialize\obj\Debug\serialize.Form1.resources
............此处省略21个文件信息

评论

共有 条评论

相关资源