日期:2014-05-17 浏览次数:20875 次
//定义数据段类型枚举
public enum Type
{
zdfs
}
public class Test
{
public void aaa()
{
byte[] send = new byte[1024 * 10]; //打包后的字节数组
string baoliu1 = "aa"; //保留字段一
string baoliu2 = "bb"; //保留字段二
string tdId = "123"; //通道编号
ushort stPoint = 1; //温度开始点
ushort sjjg = 1; //数据点间隔
ushort sjdgs = 1; //数据点个数
int cjjgcs = 1; //采集间隔次数
int typeLen = 4; //枚举值长度为4 如果传字符串就参考保留字节的传法
byte[] typeByte = BitConverter.GetBytes(Convert.ToInt32(Type.zdfs));
int baoliu1Len = baoliu1.Length; //保留字段一的长度
byte[] baoliu1LenByte = BitConverter.GetBytes(baoliu1Len);//长度数组
byte[] baoliu1Byte = Encoding.UTF8.GetBytes(baoliu1); //保留字段一本身的数组
int baoliu2Len = baoliu2.Length;
byte[] baoliu2LenByte = BitConverter.GetBytes(baoliu2Len);
byte[] baoliu2Byte = Encoding.UTF8.GetBytes(baoliu2);
int tdIdLen = tdId.Length;
byte[] tdIdLenByte = BitConverter.GetBytes(tdIdLen);
byte[] tdIdByte = Encoding.UTF8.GetBytes(tdId);
byte[] stPointByte = BitConverter.GetBytes(stPoint); &n