c#winform做接口实现接受udp报文和发送UDP报文

dssdfs232342 2011-08-25 04:11:30
1. 使用UDP 协议,RCU模块在UDP 3341端口接收外部软件发送过来的控制指令
2. UDP报文数据部分格式:
union host2rcu_frame_type //主机到RCU数据结构
{
unsigned char bytes[1600];
struct{
union
{
unsigned char bytes[SYSTEM_HEADER_LEN];
system_header_type header_data;
}system_header_union;
union {
unsigned char bytes[DEVICE_HEADER_LEN];
device_header_type device_data;
}device_header_union;
union
{
unsigned char bytes[1550];
scene_ctrl_type scene_ctrl_cmd;
}data_union;
}st;
};

#define SYSTEM_HEADER_LEN 14
//系统通信网络数据报文头协议,最长限定30字节,目前使用18字节
struct system_header_type{
unsigned char reserved; //必须是0x00
unsigned char frame_len; //帧总字节数,包括头部和数据
char system_id[4]; //固定为”HMIS”
unsigned char dest_devid; //目标设备,要求为0x00
unsigned char src_devid; //源设备,要求为0x08
unsigned short packet_id; //为0
unsigned long project_id; //为0xffffffff
};

#define DEVICE_HEADER_LEN 8
//设备头协议,最长限定20字节,目前使用10字节
struct device_header_type
{
unsigned char nodeaddr; //目标模块设备, 0是主控器,其它的模块按地址拨码开关
unsigned short cmdtype; //必须为0x60
unsigned char askack; //必须为0x00
unsigned char nbuild; //必须为0xff
unsigned char nfloor; //必须为0xff
unsigned char nroom; //必须为0xff
unsigned char nunit; //必须为0xff
};

struct scene_ctrl_type
{
unsigned char srcdev; //必须为0x41
unsigned char srcnet; //必须为0xff
unsigned char snumh; //场景命令代号(高字节)
unsigned char snuml; //场景命令代号(低字节)
unsigned char flag1; //必须为0x00
unsigned char flag2; //必须为0x00
unsigned char flag3; //必须为0x00
};

场景命令代号即功能号,外部软件将每个控制事件编成一个命令代号。


UDP数据格式实例:
Byte0 Byte1 Byte2-5 Byte6 Byte7 Byte8-9 Byte10-13
LEN 帧长度
为0x1b =byte0
=0x1b 系统标识码“HMIS”
Byte2:0x48
Byte3:0x4d
Byte4:0x49
Byte5:0x53 目标设备号
必须为0x00 源设备号
必须为0x05 报文号
为0x0000 工程号
为0xffffffff

Byte14 Byte15-16 Byte17 Byte18-21 Byte22-26 (数据部分)
目标模块
必须为0xff
命令代号
Byte15:0x81
Byte16:0x01 ASK
必须为0x01
0x00无应答 目标主机编码
必须为0xffffffff Byte22:0x00
Byte23:这个控制对应的通道号,计算方法((n-1)<<1)+s
N为 对应的通道号,s为按下抬起状态,例如对应为in2,则这个字节计算为((2-1)<<1)+1按下,抬起((2-1)<<1)+0
Byte24:0x01
Byte25:0x00
Byte26:0x00

例子数据:
1b 1b 48 4d 49 53 00 05 00 00 ff ff ff ff ff 81 01 01 ff ff ff ff 00 00 01 00 00
...全文
706 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
dssdfs232342 2011-08-28
  • 打赏
  • 举报
回复
还是没人会啊?
lewhile1 2011-08-25
  • 打赏
  • 举报
回复
无人路过,走过别错过,大侠们啊,抽空看看吧!
lewhile1 2011-08-25
  • 打赏
  • 举报
回复
顶,求高手指点!
dssdfs232342 2011-08-25
  • 打赏
  • 举报
回复
哪位大侠指点一下迷津啊,摆脱!
dssdfs232342 2011-08-25
  • 打赏
  • 举报
回复
在线等候,顶一下
dssdfs232342 2011-08-25
  • 打赏
  • 举报
回复
谁知道怎么做啊?我想用一个button来接收和发送相应的报文。比如接受到这个报文,我的按钮就变红,或者我用这个按钮发送这个报文,主机接受到这个消息后,我的按钮就变红。
ohkuy 2011-08-25
  • 打赏
  • 举报
回复
先sf

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧