void GoOnSearchingDifferentType() { try { if (messagesSupportInProject == null || messagesSupportInProject.Count == 0) { return; } for (int i = 0; i < messagesSupportInProject.Count; i++) { messagesAutoGet oTmp = messagesSupportInProject[i]; if (oTmp.bIsNeedReadRemark == true) { byte[] ArayTmp = new byte[3] { oTmp.bigType, oTmp.smallType, oTmp.bChnId }; // { bytTypeB,oTmp.FunctionType,i}; if (CsConst.mySends.AddBufToSndList(ArayTmp, 0xE44A, oTmp.bSubNetId, oTmp.bDeviceId, false, false, true, false) == true) //少于3次发送命令 { byte[] arayRemark = new byte[20]; Array.Copy(CsConst.myRevBuf, 28, arayRemark, 0, 20); messagesSupportInProject[i].sMessage = System.Text.ASCIIEncoding.Default.GetString(arayRemark); messagesSupportInProject[i].bIsNeedReadRemark = false; } } } } catch { } }
private void AddSimpleFUnctionListToPublicClasses(Byte[] FunctionsGroupE549Respond) { if (FunctionsGroupE549Respond == null) { return; } if (messagesSupportInProject == null) { messagesSupportInProject = new List <messagesAutoGet>(); } try { byte[] arayRemark = new byte[20]; Array.Copy(FunctionsGroupE549Respond, 27, arayRemark, 0, 20); String tmpRemark = System.Text.ASCIIEncoding.ASCII.GetString(arayRemark); Byte subnetId = FunctionsGroupE549Respond[17]; Byte deviceId = FunctionsGroupE549Respond[18]; Int32 deviceType = FunctionsGroupE549Respond[19] * 256 + FunctionsGroupE549Respond[20]; Byte packetLength = (Byte)(FunctionsGroupE549Respond[16] - 20 - 13); for (Byte bTmp = 0; bTmp < packetLength / 3; bTmp++) { Byte bigType = FunctionsGroupE549Respond[47 + bTmp * 3]; #region Byte bSumChn = FunctionsGroupE549Respond[49 + bTmp * 3]; for (Byte bytChnID = 1; bytChnID <= bSumChn; bytChnID++) { messagesAutoGet temp = new messagesAutoGet(); temp.bSubNetId = subnetId; temp.bDeviceId = deviceId; temp.sMessage = tmpRemark; temp.iDeviceType = deviceType; temp.bigType = FunctionsGroupE549Respond[47 + bTmp * 3]; temp.smallType = FunctionsGroupE549Respond[48 + bTmp * 3]; temp.bChnId = bytChnID; temp.bIsNeedReadRemark = true; messagesSupportInProject.Add(temp); } #endregion } } catch { } }
private void AddDeviceToList() { Int16 iSendCount = 0; try { Resend: DateTime d1, d2; d1 = DateTime.Now; d2 = DateTime.Now; List <Byte> listSendBuf = new List <byte>(); listSendBuf.AddRange(randomSearchBuffer); while (CsConst.MySimpleSearchQuene.Count > 0 || HDLUDP.Compare(d2, d1) < 2000) { #region d2 = DateTime.Now; if (CsConst.MySimpleSearchQuene.Count == 0) { continue; } if (CsConst.MySimpleSearchQuene[0] != null) { byte[] readData = CsConst.MySimpleSearchQuene[0]; int index = 1; if (messagesSupportInProject != null && messagesSupportInProject.Count > 0) { index = messagesSupportInProject.Count + 1; } int iDeviceType = readData[19] * 256 + readData[20]; //简易编程操作码返回 Boolean isAdd = true; // 是否要增加 #region Byte bSubNetId = readData[17]; Byte bDeviceId = readData[18]; if (messagesSupportInProject.Count > 0) { foreach (messagesAutoGet tmp in messagesSupportInProject) { if (bSubNetId == tmp.bSubNetId && bDeviceId == tmp.bDeviceId) { isAdd = false; break; } } } else { isAdd = true; } #endregion if (isAdd) { listSendBuf.Add(bSubNetId); listSendBuf.Add(bDeviceId); if (readData[21] == 0xE5 && readData[22] == 0x49 && readData.Length >= 20) { #region AddSimpleFUnctionListToPublicClasses(readData); #endregion } else if (readData[21] == 0x00 && readData[22] == 0x0E && CsConst.AudioBoxDeviceTypeList.Contains(iDeviceType)) { #region messagesAutoGet temp = new messagesAutoGet(); index = index + 1; byte[] arayRemark = new byte[20]; Array.Copy(readData, 25, arayRemark, 0, 20); temp.sMessage = System.Text.ASCIIEncoding.ASCII.GetString(arayRemark); temp.bSubNetId = readData[17]; temp.bDeviceId = readData[18]; temp.bChnId = readData[25]; temp.bigType = 9; temp.bIsNeedReadRemark = false; messagesSupportInProject.Add(temp); #endregion } } } #endregion CsConst.MySimpleSearchQuene.RemoveAt(0); } iSendCount++; if (iSendCount < 4) { CsConst.mySends.AddBufToSndList(listSendBuf.ToArray(), 0xE548, 255, 255, false, false, false, false); goto Resend; } GoOnSearchingDifferentType(); DisplayLockInformationToListview(); } catch { } }
private void ConvertorMessageToLocalControlCommand(String sRemark) { if (sRemark == null || sRemark == "") { return; } if (messagesSupportInProject == null || messagesSupportInProject.Count == 0) { return; } try { for (int i = 0; i < messagesSupportInProject.Count; i++) { messagesAutoGet otmp = messagesSupportInProject[i]; if (otmp == null) { continue; } if (sRemark.StartsWith(otmp.sMessage)) // 找到对应的设备备注 { Byte bSubNetId = otmp.bSubNetId; Byte bDeviceId = otmp.bDeviceId; Byte bChnId = otmp.bChnId; int iOperationCode = -1; Byte[] arrTmpSend = null; #region switch (otmp.bigType) { case 1: iOperationCode = 0x0031; arrTmpSend = new Byte[4]; arrTmpSend[0] = bChnId; if (sRemark.Contains("on") || sRemark.Contains("ON")) { arrTmpSend[1] = 100; } break; case 2: iOperationCode = 0xE3E4; arrTmpSend = new Byte[4]; arrTmpSend[0] = bChnId; if (sRemark.Contains("open") || sRemark.Contains("OPEN")) { arrTmpSend[1] = 1; } else if (sRemark.Contains("close") || sRemark.Contains("CLOSE")) { arrTmpSend[1] = 2; } else if (sRemark.Contains("stop") || sRemark.Contains("STOP")) { arrTmpSend[1] = 0; } break; case 4: iOperationCode = 0xE3D8; arrTmpSend = new Byte[4]; arrTmpSend[2] = bChnId; arrTmpSend[0] = 18; if (sRemark.Contains("on") || sRemark.Contains("ON")) { arrTmpSend[1] = 255; } else if (sRemark.Contains("OFF") || sRemark.Contains("off")) { arrTmpSend[1] = 0; } break; case 9: iOperationCode = 0xE01C; arrTmpSend = new Byte[4]; arrTmpSend[0] = 201; if (sRemark.Contains("play") || sRemark.Contains("PLAY")) { arrTmpSend[1] = 255; } else if (sRemark.Contains("stop") || sRemark.Contains("STOP")) { arrTmpSend[1] = 0; } break; } #endregion if (iOperationCode != -1) { CsConst.mySends.AddBufToSndList(arrTmpSend, iOperationCode, bSubNetId, bDeviceId, false, false, false, false); } } } } catch { } }