public void CheckComunication() { EventConfirmItem eci = new EventConfirmItem(); eci.AckDesk = "test"; eci.AckInfo = "test"; eci.AckTime = DateTime.Now.Ticks; eci.AckUser = "******"; eci.AlarmTime = DateTime.Now.Ticks; eci.DBHostIdx = 1; eci.Idx = 123; eci.TagID = 1; eci.TagName = "test"; Byte[] buffer = GetRequestConfirmBytes(eci); SendData(buffer); }
/// <summary> /// 得到请求的内容 /// </summary> /// <param name="ids"></param> /// <returns></returns> public Byte[] GetRequestConfirmContent(EventConfirmItem item) { int contentLen = 39 + 4 + 4 + 32 + 4 + 8 + 32 + 32 + 160 + 8; Byte[] buffer = new Byte[contentLen]; guid = Guid.NewGuid(); Encoding.ASCII.GetBytes("{" + guid.ToString() + "}").CopyTo(buffer, 0); BitConverter.GetBytes(item.Idx).CopyTo(buffer, 39); BitConverter.GetBytes(item.TagID).CopyTo(buffer, 39 + 4); Encoding.ASCII.GetBytes(item.TagName).CopyTo(buffer, 39 + 4 + 4); BitConverter.GetBytes(item.DBHostIdx).CopyTo(buffer, 39 + 4 + 4 + 32); BitConverter.GetBytes(item.AlarmTime).CopyTo(buffer, 39 + 4 + 4 + 32 + 4); Encoding.ASCII.GetBytes(item.AckUser).CopyTo(buffer, 39 + 4 + 4 + 32 + 4 + 8); Encoding.ASCII.GetBytes(item.AckDesk).CopyTo(buffer, 39 + 4 + 4 + 32 + 4 + 8 + 32); Encoding.ASCII.GetBytes(item.AckInfo).CopyTo(buffer, 39 + 4 + 4 + 32 + 4 + 8 + 32 + 32); BitConverter.GetBytes(item.AckTime).CopyTo(buffer, 39 + 4 + 4 + 32 + 4 + 8 + 32 + 32 + 160); return buffer; }
//protected byte[] GetData(byte[] buffer) //{ // ConnectServer(); // try // { // SocketClient.Send(buffer); // int length = 0; // List<byte[]> list = new List<byte[]>(); // while (true) // { // Byte[] part = new Byte[2000]; // int n = 0; // n = SocketClient.Receive(part); // if (n > 12) // length += n; // if (n <= 12) // { // byte[] result = new byte[length]; // int index = 0; // list.ForEach(item => // { // Array.Copy(item, 0, result, index, item.Length); // index += item.Length; // }); // //Array.Copy(part, 0, result, index, n); // return result; // } // Byte[] aBytes = new Byte[n]; // Array.Copy(part, 0, aBytes, 0, n); // list.Add(aBytes); // } // } // catch (Exception ex) // { // DisconnectServer(); // ConnectServer(); // throw ex; // } //} //1、通知报文 //ProcID char[39] 请求的标识 //Idx Int 活动告警表的Idx //TagID Int 测点TagID //TagName Char[32] 测点TagName //DBHostIdx Int 测点所在的数据中心 //AlarmTime Double 告警发生时间 //AckUser Char[32] 确认人 //AckDesk Char[32] 确认的操作站,通常是电脑名称或者手机名称(或手机号码等能标识操作设备的东西) //AckInfo Char[160] 确认信息,用户在确认时可能会输出一些确认信息 //AckTime Double 确认时间 //2、响应报文 //ProcID char[39] 请求的标识 //Result char '1'-成功,'0'-失败 /// <summary> /// 得到请求包 /// </summary> /// <param name="ids"></param> /// <returns></returns> public Byte[] GetRequestConfirmBytes(EventConfirmItem item) { Byte[] buffer = GetRequestConfirmContent(item); buffer = AppendRequestConfirmHeader(buffer); return buffer; }