Beispiel #1
0
        public bool UploadNewIRInfosToDevice(string DevName, int intDeviceType, int intActivePage)
        {
            //保存basic informations
            string strMainRemark = DevName.Split('\\')[1].Trim().Split('(')[0].Trim();

            DevName = DevName.Split('\\')[0].Trim();

            //保存basic informations
            byte bytSubID = byte.Parse(DevName.Split('-')[0].ToString());
            byte bytDevID = byte.Parse(DevName.Split('-')[1].ToString());

            byte[] ArayMain      = new byte[20];
            byte[] arayTmpRemark = HDLUDP.StringToByte(strMainRemark);
            if (arayTmpRemark.Length > 20)
            {
                Array.Copy(arayTmpRemark, 0, ArayMain, 0, 20);
            }
            else
            {
                Array.Copy(arayTmpRemark, 0, ArayMain, 0, arayTmpRemark.Length);
            }
            if (CsConst.isRestore)
            {
                if (CsConst.mySends.AddBufToSndList(ArayMain, 0x0010, bytSubID, bytDevID, false, true, true, CsConst.minAllWirelessDeviceType.Contains(intDeviceType)) == true)
                {
                    HDLUDP.TimeBetwnNext(20);
                }
                else
                {
                    return(false);
                }
            }
            if (CsConst.calculationWorker != null && CsConst.calculationWorker.IsBusy)
            {
                CsConst.calculationWorker.ReportProgress(5);
            }
            byte[] ArayTmp = new byte[0];
            if (intActivePage == 0 || intActivePage == 1)
            {
                if (IRCodes != null && IRCodes.Count != 0)
                {
                    #region
                    for (int i = 0; i < IRCodes.Count; i++)  //IRCodes.Count
                    {
                        NewIRCode temp = IRCodes[i];
                        ArayTmp = new byte[26];
                        if (intDeviceType == 1301 || intDeviceType == 1300 || intDeviceType == 6100)
                        {
                            ArayTmp = new byte[27];
                        }
                        ArayTmp[0]    = Convert.ToByte(temp.KeyID);
                        ArayTmp[1]    = 0;
                        ArayTmp[2]    = temp.DevID;
                        ArayTmp[3]    = (byte)(temp.IRIndex / 256);
                        ArayTmp[4]    = (byte)(temp.IRIndex % 256);
                        ArayTmp[5]    = (byte)temp.IRLength;
                        arayTmpRemark = new Byte[20];
                        arayTmpRemark = HDLUDP.StringToByte(temp.Remark);
                        if (arayTmpRemark.Length > 20)
                        {
                            Array.Copy(arayTmpRemark, 0, ArayTmp, 6, 20);
                        }
                        else
                        {
                            Array.Copy(arayTmpRemark, 0, ArayTmp, 6, arayTmpRemark.Length);
                        }

                        if (intDeviceType == 1301 || intDeviceType == 1300)
                        {
                            if (temp.DevID < 4)
                            {
                                ArayTmp[26] = 0;
                            }
                            else
                            {
                                ArayTmp[26] = 1;
                            }
                            if (temp.DevID != 5)
                            {
                                ArayTmp[0] = Convert.ToByte(ArayTmp[0] - 4);
                            }
                        }
                        else if (intDeviceType == 6100)
                        {
                            if (i < 3 && temp.DevID == 255)
                            {
                                ArayTmp[2] = 1;
                            }
                            else if (temp.DevID == 255)
                            {
                                ArayTmp[2] = 0;
                            }
                            // 空调设置标识,固定存储为1
                            if (i < 3)
                            {
                                ArayTmp[26] = 1;
                            }
                            else
                            {
                                ArayTmp[26] = 0;
                            }
                        }

                        if (CsConst.calculationWorker != null && CsConst.calculationWorker.IsBusy)
                        {
                            CsConst.calculationWorker.ReportProgress(5 + i);
                        }
                        if (CsConst.mySends.AddBufToSndList(ArayTmp, 0x137A, bytSubID, bytDevID, false, true, true, CsConst.minAllWirelessDeviceType.Contains(intDeviceType)) == true) //请求空间
                        {
                            byte[] arayCodes = GlobalClass.HexToByte(temp.Codes);
                            if (arayCodes.Length > 62)
                            {
                                #region
                                int Count = arayCodes.Length / 62;
                                if (arayCodes.Length % 124 != 0)
                                {
                                    Count = Count + 1;
                                }
                                for (int j = 0; j < Count; j++)
                                {
                                    if (arayCodes.Length % 62 != 0)
                                    {
                                        if (i == (Count - 1))
                                        {
                                            ArayTmp    = new byte[2 + arayCodes.Length % 124];
                                            ArayTmp[0] = Convert.ToByte(temp.KeyID);
                                            ArayTmp[1] = Convert.ToByte(j + 1);
                                            for (int k = 0; k < arayCodes.Length % 62; k++)
                                            {
                                                ArayTmp[2 + k] = arayCodes[j * 62 + k];
                                            }
                                        }
                                        else
                                        {
                                            ArayTmp    = new byte[2 + 62];
                                            ArayTmp[0] = Convert.ToByte(temp.KeyID);
                                            ArayTmp[1] = Convert.ToByte(j + 1);
                                            for (int k = 0; k < 62; k++)
                                            {
                                                ArayTmp[2 + k] = arayCodes[j * 62 + k];
                                            }
                                        }
                                    }
                                    else
                                    {
                                        ArayTmp    = new byte[2 + 62];
                                        ArayTmp[0] = Convert.ToByte(temp.KeyID);
                                        ArayTmp[1] = Convert.ToByte(j + 1);
                                        for (int k = 0; k < 62; k++)
                                        {
                                            ArayTmp[2 + k] = arayCodes[j * 62 + k];
                                        }
                                        ;
                                    }
                                    if (CsConst.mySends.AddBufToSndList(ArayTmp, 0x137A, bytSubID, bytDevID, false, true, true, CsConst.minAllWirelessDeviceType.Contains(intDeviceType)) == true)
                                    {
                                    }
                                    else
                                    {
                                        return(false);
                                    }
                                }
                                #endregion
                            }
                            else if (arayCodes.Length > 0)
                            {
                                #region
                                ArayTmp    = new byte[2 + arayCodes.Length];
                                ArayTmp[0] = Convert.ToByte(temp.KeyID);
                                ArayTmp[1] = 1;

                                arayCodes.CopyTo(ArayTmp, 2);
                                // 上传试红外码
                                if (CsConst.mySends.AddBufToSndList(ArayTmp, 0x137A, bytSubID, bytDevID, false, true, true, CsConst.minAllWirelessDeviceType.Contains(intDeviceType)) == true)
                                {
                                }
                                #endregion
                            }
                        }
                    }
                    #endregion
                }
                if (intDeviceType == 729 || intDeviceType == 1300)
                {
                    ArayTmp = new byte[4];
                    for (int i = 0; i < 4; i++)
                    {
                        ArayTmp[i] = arayBrocast[i];
                    }
                    if (CsConst.mySends.AddBufToSndList(ArayTmp, 0xE0FA, bytSubID, bytDevID, false, true, true, CsConst.minAllWirelessDeviceType.Contains(intDeviceType)) == true)
                    {
                    }
                    else
                    {
                        return(false);
                    }
                }
                if (intDeviceType == 6100)
                {
                    ArayTmp = new byte[7];
                    for (int i = 0; i < 7; i++)
                    {
                        ArayTmp[i] = arayTime[i];
                    }
                    if (CsConst.mySends.AddBufToSndList(ArayTmp, 0xDA02, bytSubID, bytDevID, false, true, true, CsConst.minAllWirelessDeviceType.Contains(intDeviceType)) == true)
                    {
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            if (CsConst.calculationWorker != null && CsConst.calculationWorker.IsBusy)
            {
                CsConst.calculationWorker.ReportProgress(40);
            }
            if (intActivePage == 0 || intActivePage == 6)
            {
                #region
                if (intDeviceType == 6100)
                {
                    for (int i = 0; i < Clocks.Count; i++)
                    {
                        ArayTmp    = new byte[9];
                        ArayTmp[0] = Clocks[i].ID;
                        ArayTmp[1] = Clocks[i].Enable;
                        ArayTmp[2] = Clocks[i].Type;
                        Array.Copy(Clocks[i].arayParam, 0, ArayTmp, 3, 5);
                        ArayTmp[8] = Clocks[i].SceneID;
                        if (CsConst.mySends.AddBufToSndList(ArayTmp, 0xE46C, bytSubID, bytDevID, false, true, true, CsConst.minAllWirelessDeviceType.Contains(intDeviceType)) == true)
                        {
                            HDLUDP.TimeBetwnNext(20);
                        }
                        else
                        {
                            return(false);
                        }
                        if (CsConst.calculationWorker != null && CsConst.calculationWorker.IsBusy)
                        {
                            CsConst.calculationWorker.ReportProgress(40 + i);
                        }
                    }
                    if (CsConst.isRestore)
                    {
                        if (Scenes != null && Scenes.Count == 8)
                        {
                            #region
                            for (int i = 1; i <= 8; i++)
                            {
                                Scene temp = Scenes[i - 1];
                                if (temp.Targets != null && temp.Targets.Count > 0)
                                {
                                    foreach (UVCMD.ControlTargets TmpCmd in temp.Targets)
                                    {
                                        if (TmpCmd.Type != 0 && TmpCmd.Type != 255)
                                        {
                                            byte[] arayCMD = new byte[9];
                                            arayCMD[0] = Convert.ToByte(i);
                                            arayCMD[1] = Convert.ToByte(TmpCmd.ID);
                                            arayCMD[2] = TmpCmd.Type;
                                            arayCMD[3] = TmpCmd.SubnetID;
                                            arayCMD[4] = TmpCmd.DeviceID;
                                            arayCMD[5] = TmpCmd.Param1;
                                            arayCMD[6] = TmpCmd.Param2;
                                            arayCMD[7] = TmpCmd.Param3;   // save targets
                                            arayCMD[8] = TmpCmd.Param4;
                                            if (CsConst.mySends.AddBufToSndList(arayCMD, 0x1400, bytSubID, bytDevID, false, true, true, CsConst.minAllWirelessDeviceType.Contains(intDeviceType)) == true)
                                            {
                                                HDLUDP.TimeBetwnNext(20);
                                            }
                                            else
                                            {
                                                return(false);
                                            }
                                        }
                                    }
                                }
                                if (CsConst.calculationWorker != null && CsConst.calculationWorker.IsBusy)
                                {
                                    CsConst.calculationWorker.ReportProgress(60 + i);
                                }
                            }
                            #endregion
                        }
                    }
                }
                #endregion
            }
            if (CsConst.calculationWorker != null && CsConst.calculationWorker.IsBusy)
            {
                CsConst.calculationWorker.ReportProgress(100);
            }
            return(true);
        }
Beispiel #2
0
        private void btnModify_Click(object sender, EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;

                NewDS.CardInfo tmp  = new NewDS.CardInfo();
                string         str1 = txtBuilding.Text;
                string         str2 = txtUnit.Text;
                string         str3 = txtRoom.Text;
                if (oDS != null)
                {
                    tmp.CardNum = oDS.MyCardInfo[ID].CardNum;
                }
                else if (oNewDS != null)
                {
                    tmp.CardNum = oNewDS.MyCardInfo[ID].CardNum;
                }
                tmp.CardType   = Convert.ToByte(cbType.SelectedIndex + 1);
                tmp.BuildingNO = Convert.ToInt32(str1, 16);
                tmp.UnitNO     = Convert.ToInt32(str2, 16);
                tmp.RoomNO     = Convert.ToInt32(str3, 16);
                tmp.UIDL       = Convert.ToByte(lbUIDLV.Text);
                tmp.UID        = new byte[10];
                byte[] arayUIDTmp = GlobalClass.HexToByte(lbUIDDV.Text);
                if (arayUIDTmp.Length > 10)
                {
                    Array.Copy(arayUIDTmp, 0, tmp.UID, 0, 10);
                }
                else
                {
                    Array.Copy(arayUIDTmp, 0, tmp.UID, 0, arayUIDTmp.Length);
                }
                tmp.arayDate    = new byte[5];
                tmp.arayDate[0] = Convert.ToByte(TimePicker.Value.Year - 2000);
                tmp.arayDate[1] = Convert.ToByte(TimePicker.Value.Month);
                tmp.arayDate[2] = Convert.ToByte(TimePicker.Value.Day);
                tmp.arayDate[3] = Convert.ToByte(numTime1.Value);
                tmp.arayDate[4] = Convert.ToByte(numTime2.Value);
                tmp.arayPhone   = new byte[11];
                byte[] arayTmpRemark = HDLUDP.StringToByte(txtPhone.Text);
                if (arayTmpRemark.Length > 11)
                {
                    Array.Copy(arayTmpRemark, 0, tmp.arayPhone, 0, 11);
                }
                else
                {
                    Array.Copy(arayTmpRemark, 0, tmp.arayPhone, 0, arayTmpRemark.Length);
                }

                tmp.arayName  = new byte[10];
                arayTmpRemark = HDLUDP.StringToByte(txtName.Text);
                if (arayTmpRemark.Length > 10)
                {
                    Array.Copy(arayTmpRemark, 0, tmp.arayName, 0, 10);
                }
                else
                {
                    Array.Copy(arayTmpRemark, 0, tmp.arayName, 0, arayTmpRemark.Length);
                }

                tmp.Remark = txtRemark.Text.Trim();
                byte[] arayTmp = new byte[64];
                arayTmp[0] = tmp.UIDL;
                Array.Copy(tmp.UID, 0, arayTmp, 1, tmp.UIDL);
                arayTmp[11] = tmp.CardType;
                arayTmp[12] = Convert.ToByte(tmp.CardNum / 256);
                arayTmp[13] = Convert.ToByte(tmp.CardNum % 256);
                arayTmp[14] = Convert.ToByte(tmp.BuildingNO / 256);
                arayTmp[15] = Convert.ToByte(tmp.BuildingNO % 256);
                arayTmp[16] = Convert.ToByte(tmp.UnitNO / 256);
                arayTmp[17] = Convert.ToByte(tmp.UnitNO % 256);
                arayTmp[18] = Convert.ToByte(tmp.RoomNO / 256);
                arayTmp[19] = Convert.ToByte(tmp.RoomNO % 256);
                Array.Copy(tmp.arayDate, 0, arayTmp, 20, tmp.arayDate.Length);
                Array.Copy(tmp.arayName, 0, arayTmp, 25, tmp.arayName.Length);
                Array.Copy(tmp.arayPhone, 0, arayTmp, 35, tmp.arayPhone.Length);

                arayTmpRemark = HDLUDP.StringToByte(tmp.Remark);
                if (arayTmpRemark.Length > 18)
                {
                    Array.Copy(arayTmpRemark, 0, arayTmp, 46, 18);
                }
                else
                {
                    Array.Copy(arayTmpRemark, 0, arayTmp, 46, arayTmpRemark.Length);
                }

                if (CsConst.mySends.AddBufToSndList(arayTmp, 0x3518, SubnetID, DeviceID, false, false, true, CsConst.minAllWirelessDeviceType.Contains(DeviceType)) == true)
                {
                    if (oNewDS != null)
                    {
                        oNewDS.MyCardInfo[ID] = tmp;
                    }
                    else if (oDS != null)
                    {
                        oDS.MyCardInfo[ID] = tmp;
                    }
                    this.Close();
                }
                else
                {
                    MessageBox.Show(CsConst.mstrINIDefault.IniReadValue("Public", "99777", ""), ""
                                    , MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                    return;
                }
            }
            catch
            {
            }
            Cursor.Current = Cursors.Default;
        }
Beispiel #3
0
 /// <summary>
 /// 获取CEMI
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 public string GetCEMI(string data)
 {
     return(GetCEMI(GlobalClass.HexToByte(data)));
 }
Beispiel #4
0
 /// <summary>
 /// 获取头部信息,16进制
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 public string GetHeader(string data)
 {
     return(GetHeader(GlobalClass.HexToByte(data)));
 }
 void calculationWorker_DoWork(object sender, DoWorkEventArgs e)
 {
     try
     {
         #region
         if (tempSend.IRCodes == null)
         {
             return;
         }
         Cursor.Current = Cursors.WaitCursor;
         List <string> listCode   = new List <string>();
         List <string> listRemark = new List <string>();
         int           RowIndex   = dgvIR.CurrentRow.Index;
         int           RowCount   = dgvIR.RowCount;
         for (int i = 0; i < tvIR.Nodes.Count; i++)
         {
             if (tvIR.Nodes[i].Checked)
             {
                 for (int j = 0; j < tvIR.Nodes[i].Nodes.Count; j++)
                 {
                     int    DeviceID = Convert.ToInt32(tvIR.Nodes[i].Name);
                     int    KeyID    = Convert.ToInt32(tvIR.Nodes[i].Nodes[j].Name);
                     string strCodes = "";
                     for (int k = 0; k < tempSend.IRCodes.Count; k++)
                     {
                         if (tempSend.IRCodes[k].KeyID == KeyID && tempSend.IRCodes[k].IRLoation == DeviceID)
                         {
                             strCodes = tempSend.IRCodes[k].Codes;
                             break;
                         }
                     }
                     if (strCodes != "")
                     {
                         listCode.Add(strCodes);
                         listRemark.Add(tvIR.Nodes[i].Text.ToString() + "-" + tvIR.Nodes[i].Nodes[j].Text.ToString());
                     }
                 }
             }
             else
             {
                 for (int j = 0; j < tvIR.Nodes[i].Nodes.Count; j++)
                 {
                     if (tvIR.Nodes[i].Nodes[j].Checked)
                     {
                         int    DeviceID = Convert.ToInt32(tvIR.Nodes[i].Name);
                         int    KeyID    = Convert.ToInt32(tvIR.Nodes[i].Nodes[j].Name);
                         string strCodes = "";
                         for (int k = 0; k < tempSend.IRCodes.Count; k++)
                         {
                             if (tempSend.IRCodes[k].KeyID == KeyID && tempSend.IRCodes[k].IRLoation == DeviceID)
                             {
                                 strCodes = tempSend.IRCodes[k].Codes;
                                 break;
                             }
                         }
                         if (strCodes != "")
                         {
                             listCode.Add(strCodes);
                             listRemark.Add(tvIR.Nodes[i].Text.ToString() + "-" + tvIR.Nodes[i].Nodes[j].Text.ToString());
                         }
                     }
                 }
             }
         }
         int CodeIndex  = 0;
         int FirstIndex = dgvIR.CurrentRow.Index;
         if (MyBackGroup != null && MyBackGroup.IsBusy)
         {
             MyBackGroup.ReportProgress(0);
         }
         for (int i = RowIndex; i < RowCount; i++)
         {
             string   strCodes = listCode[CodeIndex];
             string[] ListData = new string[0];
             if (strCodes.Contains(";"))
             {
                 ListData = strCodes.Split(';');
             }
             else
             {
                 ListData    = new string[1];
                 ListData[0] = strCodes;
             }
             byte[] arayCode = new byte[ListData.Length * 16];
             for (int j = 0; j < ListData.Length; j++)
             {
                 byte[] arayCodeTmp = GlobalClass.HexToByte(ListData[j]);
                 Array.Copy(arayCodeTmp, 0, arayCode, 16 * j, 16);
             }
             byte[] arayTmp = new byte[3];
             arayTmp[0] = Convert.ToByte(Convert.ToInt32(dgvIR[0, dgvIR.CurrentRow.Index].Value.ToString()) - 1);
             arayTmp[1] = arayCode[2];
             arayTmp[2] = arayCode[3];
             if (CsConst.mySends.AddBufToSndList(arayTmp, 0xD900, SubNetID, DevID, false, true, true, false) == true)
             {
                 if (CsConst.myRevBuf[25] == 0xF8)
                 {
                     CsConst.myRevBuf = new byte[1200];
                     for (int j = 0; j < ListData.Length; j++)
                     {
                         arayTmp = new byte[16];
                         Array.Copy(arayCode, j * 16, arayTmp, 0, 16);
                         if (CsConst.mySends.AddBufToSndList(arayTmp, 0xD906, SubNetID, DevID, false, true, true, false) == true)
                         {
                             CsConst.myRevBuf = new byte[1200];
                         }
                         else
                         {
                             return;
                         }
                         HDLUDP.TimeBetwnNext(20);
                     }
                     arayTmp    = new byte[12];
                     arayTmp[0] = Convert.ToByte(Convert.ToInt32(dgvIR[0, dgvIR.CurrentRow.Index].Value.ToString()) - 1);
                     arayTmp[1] = 0;
                     string strRemark     = listRemark[CodeIndex];
                     byte[] arayTmpRemark = HDLUDP.StringToByte(strRemark);
                     if (arayTmpRemark.Length >= 10)
                     {
                         Array.Copy(arayTmpRemark, 0, arayTmp, 2, 10);
                     }
                     else
                     {
                         Array.Copy(arayTmpRemark, 0, arayTmp, 2, arayTmpRemark.Length);
                     }
                     if (CsConst.mySends.AddBufToSndList(arayTmp, 0xD90E, SubNetID, DevID, false, true, true, false) == true)
                     {
                         CsConst.myRevBuf = new byte[1200];
                     }
                     else
                     {
                         return;
                     }
                     HDLUDP.TimeBetwnNext(arayTmp.Length);
                     arayTmp    = new byte[12];
                     arayTmp[0] = Convert.ToByte(Convert.ToInt32(dgvIR[0, dgvIR.CurrentRow.Index].Value.ToString()) - 1);
                     arayTmp[1] = 1;
                     if (arayTmpRemark.Length >= 20)
                     {
                         Array.Copy(arayTmpRemark, 10, arayTmp, 2, 10);
                     }
                     else if (arayTmpRemark.Length > 10 && arayTmpRemark.Length < 20)
                     {
                         Array.Copy(arayTmpRemark, 10, arayTmp, 2, arayTmpRemark.Length - 10);
                     }
                     if (CsConst.mySends.AddBufToSndList(arayTmp, 0xD90E, SubNetID, DevID, false, true, true, false) == true)
                     {
                         CsConst.myRevBuf = new byte[1200];
                     }
                     else
                     {
                         return;
                     }
                     dgvIR.Rows[FirstIndex + CodeIndex].Cells[1].Value = strRemark;
                     dgvIR.Rows[FirstIndex + CodeIndex].Cells[2].Value = CsConst.mstrINIDefault.IniReadValue("public", "00042", "");
                     CodeIndex = CodeIndex + 1;
                     dgvIR.Rows[FirstIndex + CodeIndex].Selected = true;
                     this.dgvIR.CurrentCell = this.dgvIR.Rows[FirstIndex + CodeIndex].Cells[0];
                     if (isStopDownloadCodes)
                     {
                         break;
                     }
                     if (CodeIndex >= listCode.Count)
                     {
                         break;
                     }
                 }
             }
             else
             {
                 break;
             }
             if (MyBackGroup != null && MyBackGroup.IsBusy)
             {
                 MyBackGroup.ReportProgress(i * 90 / RowCount);
             }
         }
         if (btnFree.Visible)
         {
             btnFree_Click(null, null);
         }
         #endregion
     }
     catch
     {
     }
 }