1、发送内码文字内容 0x31
**************************************************
FE 5C 4B 89 包头
5E 00 00 00 总长
31 消息类型
00 00 9E E4 ID
4B 00 00 00 数据长度(不包括此四字节及包尾)
30 30 30 30 30 30 30 30 31 素材UID
2C 分隔符‘,‘
01 移动方式
01 移动速度
01 停留时间
30 31 30 31 30 31 39 39 31 32 33 31 播放时间段
13 00 00 00 素材属性长度(不包括此四字节)
55 AA 标志字节
00 00 保留字节
37 内容属性,默认37
31 存储方式
31 更新时间
31 文本起始标志
32 显示屏颜色(单、双基色)
31 图片编码方式
00 00 保留字节
08 00 区域宽度 64
10 00 区域高度 16
01 11 颜色(红) 字体字号(宋体16*16)
00 保留字节
14 00 00 00 素材内容长度(不含此四字节)
31 32 33 34 35 36 37 38 39 30 素材内容“1234567890”
FF 00 素材内容特性字
01 00 本次素材内容的序号
01 00 01 00 固定字节
10 48 保留字节
2D 31 2C 素材内容结束标志
FF FF 包尾
往UID为000000001发送“1234567890”
发送:
FE 5C 4B 89 5E 00 00 00 31 00 00 9E E4 4B 00 00 00 30 30 30 30 30 30 30 30 31 2C 01 01 01 30 31 30 31 30 31 39 39 31 32 33 31 13 00 00 00 55 AA 00 00 37 31 31 31 32 31 00 00 08 00 10 00 01 11 00 14 00 00 00 31 32 33 34 35 36 37 38 39 30 FF 00 01 00 01 00 01 00 10 48 2D 31 2C FF FF
返回:FE 5C 4B 89 15 00 00 00 81 00 00 9E E4 02 00 00 00 31 23 FF FF
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.Net;
using System.Net.Sockets;
namespace 内码文字协议发送
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
UdpNet();
}
public void UdpNet()
{
Socket socketClient = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse(txtIP.Text), 8800);
byte[] data = Senddata();
socketClient.SendTo(data, endPoint);
IPEndPoint send = new IPEndPoint(IPAddress.Any,0);
EndPoint Remote = (EndPoint)send;
byte[] rec = new byte[21];
int receive = socketClient.ReceiveFrom(rec, ref Remote);
if (rec[17] == 0x31)
{
MessageBox.Show("成功");
}
else
{
MessageBox.Show("失败");
}
}
public byte[] Senddata()
{
byte[] SendBuffer = new byte[500];
int TotalLenth,//总产
OrderLenth,//具体指令的字符串长度
//ScLenth,
StrLen,//发送字符串长度
DataLen;//字符串数据长度
string txt=txtStr.Text.Trim();
//声明字符集
System.Text.Encoding utf8, gb2312;
//utf8
utf8 = System.Text.Encoding.GetEncoding("utf-8");
//gb2312
gb2312 = System.Text.Encoding.GetEncoding("gb2312");
byte[] Str;
Str = utf8.GetBytes(txt);
Str = System.Text.Encoding.Convert(utf8, gb2312, Str);
// byte[] Str = UTF8Encoding.UTF8.GetBytes(txt);
DataLen = Str.Length;
byte[] SData = new byte[84 + DataLen];
//int Width, Height;
//Width = Convert.ToInt32(textBoxWidth.Text.Trim());
//Height = Convert.ToInt32(textBoxHeight.Text.Trim());
//1.帧开始符
SendBuffer[0] = 0xfe;
SendBuffer[1] = 0x5C;
SendBuffer[2] = 0x4B;
SendBuffer[3] = 0x89;
//2.所有字节的长度
//低字节在前,高字节在后
TotalLenth = 84 + DataLen;
SendBuffer[7] = (Byte)(TotalLenth /(256*256*256));
TotalLenth = TotalLenth % (256 * 256 * 256);
SendBuffer[6] = (Byte)(TotalLenth /(256*256));
TotalLenth = TotalLenth % (256 * 256);
SendBuffer[5] =(Byte)( TotalLenth/256);
TotalLenth = TotalLenth % 256;
SendBuffer[4] = (Byte)(TotalLenth);
//3. 固定字符31
SendBuffer[8] = 0x31;
//4.辅助字段无意义(固定)
SendBuffer[9] = 0x00;
SendBuffer[10] = 0x00;
SendBuffer[11] = 0x9E;
SendBuffer[12] = 0xE4;
//5.具体指令的字符串长度
OrderLenth = 65 + DataLen;
SendBuffer[16] = (Byte)(OrderLenth / (256 * 256 * 256));
OrderLenth = OrderLenth % (256 * 256 * 256);
SendBuffer[15] = (Byte)(OrderLenth / (256 * 256));
OrderLenth = OrderLenth % (256 * 256);
SendBuffer[14] = (Byte)(OrderLenth /256);
OrderLenth = OrderLenth % 256;
SendBuffer[13] = (Byte)(OrderLenth);
//6.UID 地址
SendBuffer[17] = 0x30;
SendBuffer[18] = 0x30;
SendBuffer[19] = 0x30;
SendBuffer[20] = 0x30;
SendBuffer[21] = 0x30;
SendBuffer[22] = 0x30;
SendBuffer[23] = 0x30;
SendBuffer[24] = 0x30;
SendBuffer[25] = 0x31;
//7.固定
SendBuffer[26] = 0x2C;
//8.移动方式
SendBuffer[27] = 0x01;
//9.移动速度
SendBuffer[28] = 0x01;
//10.显示方
SendBuffer[29] = 0x01;
//11.固定-播放结束起始年月日
SendBuffer[30] = 0x30;
SendBuffer[31] = 0x31;
SendBuffer[32] = 0x30;
SendBuffer[33] = 0x31;
SendBuffer[34] = 0x30;
SendBuffer[35] = 0x31;
SendBuffer[36] = 0x39;
SendBuffer[37] = 0x39;
SendBuffer[38] = 0x31;
SendBuffer[39] = 0x32;
SendBuffer[40] = 0x33;
SendBuffer[41] = 0x31;
//12.素材指令长度
SendBuffer[42] = 0x13;
SendBuffer[43] = 0x00;
SendBuffer[44] = 0x00;
SendBuffer[45] = 0x00;
//13.素材开始格式标志
SendBuffer[46] = 0x55;
SendBuffer[47] = 0xAA;
//14.固定
SendBuffer[48] = 0x00;
SendBuffer[49] = 0x00;
SendBuffer[50] = 0x37;
SendBuffer[51] = 0x31;
SendBuffer[52] = 0x31; //刷新本区域
//与素材内容属性段配合的12个字节:
SendBuffer[53] = 0x31;
//15.示屏像素色彩:0x31:单基色,0x32:双基色
SendBuffer[54] = 0x32;
//16.固定
SendBuffer[55] = 0x31;
SendBuffer[56] = 0x00;
SendBuffer[57] = 0x00;
//17.长度 64
//SendBuffer[58] =(Byte)( Width % 256);
//SendBuffer[59] =(Byte)( Width / 256);
SendBuffer[58] = 0x08;
SendBuffer[59] = 0x00;
//18.高度 16
//SendBuffer[60] = (Byte)(Height % 256);
//SendBuffer[61] = (Byte)(Height/ 256);
SendBuffer[60] = 0x10;
SendBuffer[61] = 0x00;
//19.字符颜色
SendBuffer[62] =0x01;
//20.字符大小
SendBuffer[63] =0x11;
//21.固定
SendBuffer[64] = 0x00;
//22.发送字符串长度
StrLen = 10 + DataLen;
SendBuffer[68] = (Byte)(StrLen / (256 * 256 * 256));
StrLen = StrLen % (256 * 256 * 256);
SendBuffer[67] = (Byte)(StrLen / (256 * 256));
StrLen = StrLen % (256 * 256);
SendBuffer[66] = (Byte)(StrLen / 256);
StrLen = StrLen % 256;
SendBuffer[65] =(Byte) (StrLen);
//23.字符串数据
for (int i = 0; i < DataLen; i++)
SendBuffer[69 + i ] = Str[i];
//24.传送控制
SendBuffer[69 + DataLen] = 0xFF;
SendBuffer[70 + DataLen] = 0x00;
//25.本次通讯发送文本素材的序号
SendBuffer[71 + DataLen] = 0x01;
SendBuffer[72 + DataLen] = 0x00;
//26.固定
SendBuffer[73 + DataLen] = 0x01;
SendBuffer[74 + DataLen] = 0x00;
SendBuffer[75 + DataLen] = 0x01;
SendBuffer[76 + DataLen] = 0x00;
SendBuffer[77 + DataLen] = 0x10;
SendBuffer[78 + DataLen] = 0x48;
//27.发送过程结束标记
SendBuffer[79 + DataLen] = 0x2D;
SendBuffer[80 + DataLen] = 0x31;
SendBuffer[81 + DataLen] = 0x2C;
//28.包尾
SendBuffer[82 + DataLen] = 0xFF;
SendBuffer[83 + DataLen] = 0xFF;
for (int i = 0; i < 84 + DataLen; i++)
SData[i] = SendBuffer[i];
return SData;
}
}
}