• 大小: 0.10M
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2024-05-03
  • 语言: C#
  • 标签: C#  UDP  udp通信  UDP  DP  通信  

资源简介


资源截图

代码片段和文件信息

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.Net;
using System.Threading;
using System.Net.Sockets;

namespace 上位控制程序
{
    public partial class Form1 : Form
    {
        public static IPEndPoint udpPoint = new IPEndPoint(IPAddress.Any 16006);
        public static UdpClient udpClient = new UdpClient(udpPoint);
        public static IPEndPoint serverPoint = new IPEndPoint(IPAddress.Parse(“192.168.1.91“) 16006);
        public Form1()
        {
            InitializeComponent();

            this.StartPosition = FormStartPosition.Manual;
            this.Left = 1366;
            this.Top = 0;
            this.Width = 800;
            this.Height = 600;

        }

        private void btnGoWorkPos_Click(object sender EventArgs e)
        {
            byte[] buf = new byte[20];
            buf[0] = 0xeb;
            buf[1] = 0x90;
            buf[2] = 0x91;
            buf[3] = 0xa0;
            buf[4] = 0x00;
            buf[5] = 0x01;
            buf[6] = 0x00;

            ushort ret = SetCheck(buf 7);
            udpClient.Send(buf 9 serverPoint);
        }

        private void btnGoLiaoTong_Click(object sender EventArgs e)
        {
            byte[] buf = new byte[20];
            buf[0] = 0xeb;
            buf[1] = 0x90;
            buf[2] = 0x91;
            buf[3] = 0xa1;
            buf[4] = 0x00;
            buf[5] = 0x01;
            buf[6] = 0x00;

            ushort ret = SetCheck(buf 7);
            udpClient.Send(buf 9 serverPoint);
        }

        private void btnGoStandby_Click(object sender EventArgs e)
        {
            byte[] buf = new byte[20];
            buf[0] = 0xeb;
            buf[1] = 0x90;
            buf[2] = 0x91;
            buf[3] = 0xa2;
            buf[4] = 0x00;
            buf[5] = 0x01;
            buf[6] = 0x00;

            ushort ret = SetCheck(buf 7);
            udpClient.Send(buf 9 serverPoint);
        }

        ushort CRC16(byte[] pszBuf UInt16 unLength)
        {
            UInt16 i j CurVal;
            UInt16 CrcReg = 0xFFFF;

            for (i = 0; i < unLength; i++)
            {
                CurVal = (UInt16)((pszBuf[i]) << 8);

                for (j = 0; j < 8; j++)
                {
                    if ((short)(CrcReg ^ CurVal) < 0)
                        CrcReg = (ushort)((CrcReg << 1) ^ (ushort)(0x1021));
                    else
                        CrcReg <<= 1;
                    CurVal <<= 1;
                }
            }
            return CrcReg;
        }
        ushort SetCheck(byte[] pszBuf UInt16 unLength)
        {
            UInt16 ret = CRC16(pszBuf unLength);
            pszBuf[unLength] = (byte)(ret);
            pszBuf[unLength+1] = (byte)(ret>>8);

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2021-01-20 11:02  上位控制程序(c#网络通信例程)\
     目录           0  2021-01-20 11:02  上位控制程序(c#网络通信例程)\上位控制程序\
     文件         157  2020-11-11 21:11  上位控制程序(c#网络通信例程)\上位控制程序\App.config
     文件        6536  2020-11-12 13:46  上位控制程序(c#网络通信例程)\上位控制程序\Form1.Designer.cs
     文件        4333  2020-12-29 09:03  上位控制程序(c#网络通信例程)\上位控制程序\Form1.cs
     文件        5817  2020-11-12 13:46  上位控制程序(c#网络通信例程)\上位控制程序\Form1.resx
     文件         534  2020-11-11 21:11  上位控制程序(c#网络通信例程)\上位控制程序\Program.cs
     目录           0  2021-01-20 11:02  上位控制程序(c#网络通信例程)\上位控制程序\Properties\
     文件        1360  2020-11-11 15:32  上位控制程序(c#网络通信例程)\上位控制程序\Properties\AssemblyInfo.cs
     文件        2876  2020-11-11 21:11  上位控制程序(c#网络通信例程)\上位控制程序\Properties\Resources.Designer.cs
     文件        5612  2020-11-11 15:32  上位控制程序(c#网络通信例程)\上位控制程序\Properties\Resources.resx
     文件        1118  2020-11-11 21:11  上位控制程序(c#网络通信例程)\上位控制程序\Properties\Settings.Designer.cs
     文件         249  2020-11-11 15:32  上位控制程序(c#网络通信例程)\上位控制程序\Properties\Settings.settings
     目录           0  2021-01-20 11:02  上位控制程序(c#网络通信例程)\上位控制程序\bin\
     目录           0  2021-01-20 11:02  上位控制程序(c#网络通信例程)\上位控制程序\bin\Debug\
     文件       10752  2020-11-11 21:16  上位控制程序(c#网络通信例程)\上位控制程序\bin\Debug\上位控制程序.exe
     文件         157  2020-11-11 21:11  上位控制程序(c#网络通信例程)\上位控制程序\bin\Debug\上位控制程序.exe.config
     文件       28160  2020-11-11 21:16  上位控制程序(c#网络通信例程)\上位控制程序\bin\Debug\上位控制程序.pdb
     文件       22704  2020-11-11 21:16  上位控制程序(c#网络通信例程)\上位控制程序\bin\Debug\上位控制程序.vshost.exe
     文件         157  2020-11-11 21:11  上位控制程序(c#网络通信例程)\上位控制程序\bin\Debug\上位控制程序.vshost.exe.config
     文件         490  2019-03-19 12:46  上位控制程序(c#网络通信例程)\上位控制程序\bin\Debug\上位控制程序.vshost.exe.manifest
     目录           0  2021-01-20 11:02  上位控制程序(c#网络通信例程)\上位控制程序\bin\Release\
     文件       10752  2020-12-29 09:03  上位控制程序(c#网络通信例程)\上位控制程序\bin\Release\上位控制程序.exe
     文件         157  2020-11-11 21:11  上位控制程序(c#网络通信例程)\上位控制程序\bin\Release\上位控制程序.exe.config
     文件       32256  2020-12-29 09:03  上位控制程序(c#网络通信例程)\上位控制程序\bin\Release\上位控制程序.pdb
     文件       22704  2021-01-20 11:01  上位控制程序(c#网络通信例程)\上位控制程序\bin\Release\上位控制程序.vshost.exe
     文件         157  2020-11-11 21:11  上位控制程序(c#网络通信例程)\上位控制程序\bin\Release\上位控制程序.vshost.exe.config
     文件         490  2019-03-19 12:46  上位控制程序(c#网络通信例程)\上位控制程序\bin\Release\上位控制程序.vshost.exe.manifest
     目录           0  2021-01-20 11:02  上位控制程序(c#网络通信例程)\上位控制程序\obj\
     目录           0  2021-01-20 11:02  上位控制程序(c#网络通信例程)\上位控制程序\obj\Debug\
     文件        1087  2020-11-11 21:11  上位控制程序(c#网络通信例程)\上位控制程序\obj\Debug\DesignTimeResolveAssemblyReferences.cache
............此处省略27个文件信息

评论

共有 条评论