Пример #1
0
        private void btnRead_Click(object sender, EventArgs e)
        {
            Cursor.Current           = Cursors.WaitCursor;
            ((Button)sender).Enabled = false;

            byte[] ArayTmp = null;
            UDPReceive.ClearQueueData();
            bool isRead = false;

            if (CsConst.mySends.AddBufToSndList(ArayTmp, 0xE5F5, 255, 255, false, false, true, false) == true)
            {
                System.Threading.Thread.Sleep(100);
                for (int i = 0; i < UDPReceive.receiveQueue.Count; i++)
                {
                    byte[] readData = UDPReceive.receiveQueue.ToArray()[i];
                    if (readData[21] == 0xE5 && readData[22] == 0xF6)
                    {
                        tbsub.Text         = readData[25].ToString();
                        tbDev.Text         = readData[26].ToString();
                        MyintDeviceType    = readData[19] * 256 + readData[20];
                        btnModify1.Enabled = true;
                        isRead             = true;
                        break;
                    }
                }
            }
            ((Button)sender).Enabled = true;
            Cursor.Current           = Cursors.Default;
            if (!isRead)
            {
                MessageBox.Show(CsConst.mstrINIDefault.IniReadValue("Public", "99633", ""), ""
                                , MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
            }
        }
Пример #2
0
 private void chbAuto_CheckedChanged(object sender, EventArgs e)
 {
     CsConst.isAutoRefreshCurtainPercent = chbAuto.Checked;
     if (chbAuto.Checked)
     {
         UDPReceive.ClearQueueDataForCurtain();
     }
     timer1.Enabled = chbAuto.Checked;
 }
Пример #3
0
 private void timer1_Tick(object sender, EventArgs e)
 {
     try
     {
         if (UDPReceive.receiveQueueForCurtain.Count > 0)
         {
             byte[] arayTmp = UDPReceive.receiveQueueForCurtain.Dequeue();
             if (arayTmp[21] == 0xE3 && arayTmp[22] == 0xE1 &&
                 arayTmp[17] == SubNetID && arayTmp[18] == DevID)
             {
                 if (arayTmp[25] == 0x11)
                 {
                     if (arayTmp[26] <= 100)
                     {
                         lbPercent.Text = arayTmp[26].ToString() + "%";
                     }
                     else if (arayTmp[26] == 0xDD)
                     {
                         lbPercent.Text = CsConst.mstrINIDefault.IniReadValue("Public", "99905", "");
                     }
                     else if (arayTmp[26] == 0xEE)
                     {
                         lbPercent.Text = CsConst.mstrINIDefault.IniReadValue("Public", "99906", "");
                     }
                     else if (arayTmp[26] == 0xFA)
                     {
                         System.Diagnostics.Debug.WriteLine(arayTmp[21].ToString("X") + " " + arayTmp[22].ToString("X"));
                     }
                 }
                 else if (arayTmp[25] == 0x01)
                 {
                     UDPReceive.ClearQueueDataForCurtain();
                 }
             }
         }
     }
     catch
     {
     }
 }
Пример #4
0
        /// <summary>
        /// 接收线程
        /// </summary>
        private void DealWithRevDatas(byte[] buf)
        {
            byte[] revBuf = buf;
            try
            {
                if ((revBuf[14] != 0xAA) & (revBuf[15] != 0xAA) & (revBuf[15] != 0x55))
                {
                    return;
                }
                if (CsConst.myRevBuf == null)
                {
                    CsConst.myRevBuf = new byte[1200];
                }
                string[] ipHeader   = CsConst.myLocalIP.Split('.'); ////A B C 类地址广播
                int      mhjCommand = revBuf[21] * 256 + revBuf[22];
                int      devType    = revBuf[19] * 256 + revBuf[20];

                int netid = revBuf[17]; //设备子网id
                int devid = revBuf[18]; //设备号

                int wdDeviceType = revBuf[19] * 256 + revBuf[20];
                int intBigSize   = 0; // 大包数据长度默认为0
                if (revBuf[16] == 0xFF)
                {
                    intBigSize = revBuf[25] * 256 + revBuf[26] + 27; // 长度 + 协议头
                }

                #region
                if (CsConst.MyBlnCapture == true)
                {
                    CsConst.myRevBuf = new byte[1200];

                    if (revBuf[16] == 0xFF)
                    {
                        Array.Copy(revBuf, 0, CsConst.myRevBuf, 0, intBigSize);
                    }
                    else
                    {
                        Array.Copy(revBuf, 0, CsConst.myRevBuf, 0, revBuf[16] + 17);// copy to the public buffer
                    }
                    CsConst.MyQuene.Add(CsConst.myRevBuf);
                }
                #endregion
                if (CsConst.bStartSimpleTesting == true)
                {
                    byte[] arayTmp = new byte[revBuf[16] + 17];
                    Array.Copy(revBuf, 0, arayTmp, 0, revBuf[16] + 17);
                    UDPReceive.OnReceive(arayTmp);
                    return;
                }

                if ((revBuf[17] == CsConst.mbytLocalSubNetID) & (revBuf[18] == CsConst.mbytLocalDeviceID))
                {
                    return;
                }
                // 公共的升级或者其他指令
                #region
                if (CsConst.NeedAppendToPublicBufferCommands.Contains(waitCommand) && waitCommand == mhjCommand && waitNetid == revBuf[17] && waitDevid == revBuf[18])
                {
                    if (intBigSize > 0)
                    {
                        byte[] arayTmp = new byte[revBuf[25] * 256 + revBuf[26] + 27];
                        Array.Copy(revBuf, 0, arayTmp, 0, arayTmp.Length);
                        UDPReceive.OnReceiveForBuffer(arayTmp);
                        this.watiforResponse = false;
                    }
                    else
                    {
                        byte[] arayTmp = new byte[revBuf[16] + 17];
                        Array.Copy(revBuf, 0, arayTmp, 0, revBuf[16] + 17);
                        UDPReceive.OnReceiveForBuffer(arayTmp);
                        //revBuf.CopyTo(CsConst.myRevBuf, 0);
                        if (CsConst.MyBlnNeedF8)
                        {
                            if (revBuf[25] == 0xF8)
                            {
                                CsConst.MyBlnNeedF8  = false;
                                this.watiforResponse = false;
                            }
                        }
                        else
                        {
                            this.watiforResponse = false;
                        }
                    }
                }
                #endregion
                if (CsConst.FastSearch)
                {
                    if (mhjCommand == 0x000F || mhjCommand == 0xF004 || mhjCommand == 0x1D35 || mhjCommand == 0xE549)//广播搜索设备
                    {
                        byte[] arayTmp = new byte[revBuf[16] + 17];
                        Array.Copy(revBuf, 0, arayTmp, 0, revBuf[16] + 17);
                        UDPReceive.OnReceive(arayTmp);
                        return;
                    }
                }
                else
                {
                    // if (this.watiforResponse == false) return;
                    if (mhjCommand == 0x3001)
                    {
                        CsConst.mintFactoryTime = revBuf[28];
                        if (this.watiforResponse == true)
                        {
                            this.watiforResponse = false;
                        }
                        return;
                    }
                    else if (mhjCommand == 0x301E)
                    {
                        Byte[] TmpExcahngePort = new Byte[12];
                        TmpExcahngePort[0] = byte.Parse(CsConst.myLocalIP.Split('.')[0].ToString());
                        TmpExcahngePort[1] = byte.Parse(CsConst.myLocalIP.Split('.')[1].ToString());
                        TmpExcahngePort[2] = byte.Parse(CsConst.myLocalIP.Split('.')[2].ToString());
                        TmpExcahngePort[3] = byte.Parse(CsConst.myLocalIP.Split('.')[3].ToString());
                        TmpExcahngePort[4] = 0x17;
                        TmpExcahngePort[5] = 0x70;
                        Array.Copy(CsConst.myRevBuf, 25, TmpExcahngePort, 6, 6);
                        this.AddBufToSndList(TmpExcahngePort, 0x301D, 255, 255, false, false, false, false);
                        ConstPort = CsConst.myRevBuf[29] * 256 + CsConst.myRevBuf[30];
                        string TmpIp = CsConst.myRevBuf[25].ToString() + "."
                                       + CsConst.myRevBuf[26].ToString() + "."
                                       + CsConst.myRevBuf[27].ToString() + "."
                                       + CsConst.myRevBuf[28].ToString();
                        for (int i = 0; i <= 4; i++)
                        {
                            this.SendBufToRemote(null, TmpIp);
                        }
                    }
                    else if (mhjCommand == 0x1365 && revBuf[17] == waitNetid && revBuf[18] == waitDevid)
                    {
                        #region
                        if (revBuf[16] == 0xFF)
                        {
                            if (revBuf[27] == 12)
                            {
                                if (revBuf[28] == 0xFF)
                                {
                                    AudioDeviceTypeList.isEndReceiveFile = true;
                                    return;
                                }
                                byte[] arayTmp = new byte[revBuf[25] * 256 + revBuf[26]];
                                Array.Copy(revBuf, 27, arayTmp, 0, arayTmp.Length);
                                UDPReceive.OnReceiveForAudio(arayTmp);
                                return;
                            }
                            else if (revBuf[27] == 13)
                            {
                                byte[] arayTmp = new byte[revBuf[25] * 256 + revBuf[26] - 12];
                                Array.Copy(revBuf, 39, arayTmp, 0, arayTmp.Length);
                                UDPReceive.OnReceiveForAudio(arayTmp);
                                return;
                            }
                            else //if (revBuf[27] == 11)
                            {
                                revBuf.CopyTo(CsConst.myRevBuf, 0);// copy to the public buffer
                                this.watiforResponse = false;
                                return;
                            }
                        }
                        return;

                        #endregion
                    }
                    else if (waitCommand == mhjCommand && (mhjCommand == 0x300E || mhjCommand == 0x3010 || mhjCommand == 0x3012 ||
                                                           mhjCommand == 0x3014 || mhjCommand == 0x301E || mhjCommand == 0x3020))
                    {
                        revBuf.CopyTo(CsConst.myRevBuf, 0);// copy to the public buffer
                        this.watiforResponse = false;
                        return;
                    }
                    else if ((mhjCommand == 0xE449) && revBuf[17] == waitNetid && revBuf[18] == waitDevid && watiforResponse == false)
                    {
                        byte[] arayTmp = new byte[revBuf[16] + 17];
                        Array.Copy(revBuf, 0, arayTmp, 0, revBuf[16] + 17);
                        UDPReceive.OnReceive(arayTmp);
                        this.watiforResponse = false;
                        return;
                    }
                    else if (CsConst.MyBlnWait15FE == true && mhjCommand == 0x15FE)  //被动等待接收15FE的命令 第一次接收
                    {
                        byte[] arayTmp = new byte[revBuf[16] + 17];
                        Array.Copy(revBuf, 0, arayTmp, 0, revBuf[16] + 17);
                        UDPReceive.OnReceiveForUpgrade(arayTmp);
                        return;
                    }
                    else if (waitCommand == 0xF006)
                    {
                        if (revBuf[17] == CsConst.ModifyDeviceAddressSubNetID && revBuf[18] == CsConst.ModifyDeviceAddressDeviceID)
                        {
                            this.watiforResponse = false;
                            return;
                        }
                    }
                    else if (waitCommand == 0xE5F6 || waitCommand == 0xE5F8 || waitCommand == 0xFE04 || waitCommand == 0xFE06 || waitCommand == 0x1385)
                    {
                        byte[] arayTmp = new byte[revBuf[16] + 17];
                        Array.Copy(revBuf, 0, arayTmp, 0, revBuf[16] + 17);
                        UDPReceive.OnReceive(arayTmp);
                        this.watiforResponse = false;
                        return;
                    }
                    else if (waitCommand == 0xFE06)
                    {
                        if (revBuf[25] == 0xF8)
                        {
                            this.watiforResponse = false;
                            return;
                        }
                    }
                    else if (waitCommand == 0x13F5) //自动修改地址
                    {
                        CsConst.AutoAddress = revBuf[25];
                        return;
                    }
                    else if (mhjCommand == 0xE3E1)
                    {
                        if (CsConst.isAutoRefreshCurtainPercent)
                        {
                            byte[] arayTmp = new byte[revBuf[16] + 17];
                            Array.Copy(revBuf, 0, arayTmp, 0, revBuf[16] + 17);
                            UDPReceive.OnReceiveForCurtain(arayTmp);
                            return;
                        }
                    }
                    else if (mhjCommand == 0x1D51)
                    {
                        byte[] arayTmp = new byte[revBuf[16] + 17];
                        Array.Copy(revBuf, 0, arayTmp, 0, revBuf[16] + 17);
                        UDPReceive.OnReceiveForSingnal(arayTmp);
                        return;
                    }
                    else if (watiforResponse == true && CsConst.MyBlnNeedF8 && CsConst.MybytNeedParm1 != -1 && CsConst.MybytNeedParm2 != -1 &&
                             CsConst.MybytNeedParm3 != -1 && CsConst.mbytCurUsingSubNetID == revBuf[17] &&
                             CsConst.mbytCurUsingDevNetID == revBuf[18] && waitCommand == mhjCommand) //是不是F8 有参数匹配才确认 第一个 第二个  第三个参数匹配
                    {
                        if (CsConst.myRevBuf == null)
                        {
                            CsConst.myRevBuf = new byte[1200];
                        }
                        if (revBuf[25] == 0xF8 && CsConst.MybytNeedParm1 == revBuf[26] && CsConst.MybytNeedParm2 == revBuf[27] && CsConst.MybytNeedParm3 == revBuf[28])
                        {
                            if (revBuf[16] == 0xFF)
                            {
                                Array.Copy(revBuf, 0, CsConst.myRevBuf, 0, revBuf[25] * 256 + revBuf[26] + 27);
                            }
                            else
                            {
                                Array.Copy(revBuf, 0, CsConst.myRevBuf, 0, revBuf[16] + 17);// copy to the public buffer
                            }
                            if (watiforResponse == true)
                            {
                                this.watiforResponse = false;
                            }
                            CsConst.MyBlnNeedF8    = false;
                            CsConst.MybytNeedParm1 = -1;
                            CsConst.MybytNeedParm2 = -1;
                            CsConst.MybytNeedParm3 = -1;
                            return;
                        }
                    }
                    else if (watiforResponse == true && CsConst.MyBlnNeedF8 && CsConst.MybytNeedParm1 != -1 && CsConst.MybytNeedParm2 != -1 && CsConst.mbytLocalSubNetID == revBuf[23] &&
                             CsConst.mbytLocalDeviceID == revBuf[24] && waitCommand == mhjCommand) //是不是F8 有参数匹配才确认 第一个 第二个 参数匹配
                    {
                        if (CsConst.myRevBuf == null)
                        {
                            CsConst.myRevBuf = new byte[1200];
                        }
                        if (revBuf[25] == 0xF8 && CsConst.MybytNeedParm1 == revBuf[26] && CsConst.MybytNeedParm2 == revBuf[27])
                        {
                            if (revBuf[16] == 0xFF)
                            {
                                Array.Copy(revBuf, 0, CsConst.myRevBuf, 0, revBuf[25] * 256 + revBuf[26] + 27);
                            }
                            else
                            {
                                Array.Copy(revBuf, 0, CsConst.myRevBuf, 0, revBuf[16] + 17);// copy to the public buffer
                            }
                            this.watiforResponse   = false;
                            CsConst.MyBlnNeedF8    = false;
                            CsConst.MybytNeedParm1 = -1;
                            CsConst.MybytNeedParm2 = -1;
                            return;
                        }
                    }
                    else if (watiforResponse == true && CsConst.MybytNeedParm1 != -1 && CsConst.MybytNeedParm2 != -1 && waitCommand == mhjCommand) //是不是F8 有参数匹配才确认 第一个 第二个 参数匹配
                    {
                        if (CsConst.myRevBuf == null)
                        {
                            CsConst.myRevBuf = new byte[1200];
                        }
                        if (CsConst.MybytNeedParm1 == revBuf[25] && CsConst.MybytNeedParm2 == revBuf[26])
                        {
                            if (revBuf[16] == 0xFF)
                            {
                                Array.Copy(revBuf, 0, CsConst.myRevBuf, 0, revBuf[25] * 256 + revBuf[26] + 27);
                            }
                            else
                            {
                                Array.Copy(revBuf, 0, CsConst.myRevBuf, 0, revBuf[16] + 17);// copy to the public buffer
                            }
                            this.watiforResponse   = false;
                            CsConst.MybytNeedParm1 = -1;
                            CsConst.MybytNeedParm2 = -1;
                            return;
                        }
                    }
                    else if (watiforResponse == true && CsConst.MyBlnNeedF8 && CsConst.MybytNeedParm1 != -1 && CsConst.mbytLocalSubNetID == revBuf[23] &&
                             CsConst.mbytLocalDeviceID == revBuf[24] && waitCommand == mhjCommand)    //是不是F8 有参数匹配才确认 第一个参数匹配
                    {
                        if (CsConst.myRevBuf == null)
                        {
                            CsConst.myRevBuf = new byte[1200];
                        }
                        if (CsConst.myRevBuf[25] == 0xF8 && CsConst.MybytNeedParm1 == CsConst.myRevBuf[26])
                        {
                            if (revBuf[16] == 0xFF)
                            {
                                Array.Copy(revBuf, 0, CsConst.myRevBuf, 0, revBuf[25] * 256 + revBuf[26] + 27);
                            }
                            else
                            {
                                Array.Copy(revBuf, 0, CsConst.myRevBuf, 0, revBuf[16] + 17);// copy to the public buffer
                            }
                            if (watiforResponse == true)
                            {
                                this.watiforResponse = false;
                            }
                            CsConst.MyBlnNeedF8    = false;
                            CsConst.MybytNeedParm1 = -1;
                            CsConst.MybytNeedParm2 = -1;
                            return;
                        }
                    }
                    else if (watiforResponse == true && CsConst.MyBlnNeedF8 && CsConst.mbytCurUsingSubNetID == revBuf[17] &&
                             CsConst.mbytCurUsingDevNetID == revBuf[18] && waitCommand == mhjCommand) //是不是F8 有参数匹配才确认
                    {
                        if (CsConst.myRevBuf == null)
                        {
                            CsConst.myRevBuf = new byte[1200];
                        }
                        if (CsConst.myRevBuf[25] == 0xF8)
                        {
                            if (revBuf[16] == 0xFF)
                            {
                                Array.Copy(revBuf, 0, CsConst.myRevBuf, 0, revBuf[25] * 256 + revBuf[26] + 27);
                            }
                            else
                            {
                                Array.Copy(revBuf, 0, CsConst.myRevBuf, 0, revBuf[16] + 17);// copy to the public buffer
                            }
                            if (watiforResponse == true)
                            {
                                this.watiforResponse = false;
                            }
                            return;
                        }
                    }
                    else if (watiforResponse == true && CsConst.mbytCurUsingSubNetID == revBuf[17] &&
                             CsConst.mbytCurUsingDevNetID == revBuf[18] && waitCommand == mhjCommand)  //是不是只有参数匹配一才确认
                    {
                        if (CsConst.myRevBuf == null)
                        {
                            CsConst.myRevBuf = new byte[1200];
                        }
                        if (CsConst.myRevBuf[25] == CsConst.MybytNeedParm1)
                        {
                            if (revBuf[16] == 0xFF)
                            {
                                Array.Copy(revBuf, 0, CsConst.myRevBuf, 0, revBuf[25] * 256 + revBuf[26] + 27);
                            }
                            else
                            {
                                Array.Copy(revBuf, 0, CsConst.myRevBuf, 0, revBuf[16] + 17);// copy to the public buffer
                            }
                            if (watiforResponse == true)
                            {
                                this.watiforResponse = false;
                            }
                            return;
                        }
                    }
                    else if (waitCommand == mhjCommand && waitDevid == revBuf[18] && waitNetid == revBuf[17])
                    {
                        revBuf.CopyTo(CsConst.myRevBuf, 0);// copy to the public buffer
                        this.watiforResponse = false;
                    }
                    return;
                }
            }
            catch
            {
            }
        }
Пример #5
0
        void HDLDeviceUploadFirmwareStepByStep()
        {
            string str1 = "";

            try
            {
                CsConst.MyBlnFinish = false;
                FileStream fs = new FileStream(MystrPath, FileMode.Open, FileAccess.Read);//创建文件流

                byte[] source = new byte[fs.Length];

                fs.Read(source, 0, source.Length);
                fs.Flush();
                fs.Close();

                str1 = source.Length.ToString();
                DateTime d1 = DateTime.Now;
                DateTime d2 = DateTime.Now;
                UDPReceive.receiveQueueForUpgrade.Clear();
                CsConst.MyBlnWait15FE = true;
                //再次接收到长度发送文件
                #region
                while (CsConst.MyBlnFinish == false)
                {
                    while (UDPReceive.receiveQueueForUpgrade != null && UDPReceive.receiveQueueForUpgrade.Count > 0)
                    {
                        Byte[] revBuf = UDPReceive.receiveQueueForUpgrade.Dequeue();
                        if (revBuf[17] == CsConst.CurrentUpgradeSubnetID && revBuf[18] == CsConst.CurrentUpgradeDeviceID)
                        {
                            int DeviceType    = revBuf[19] * 256 + revBuf[20];
                            int intMaxPacket  = 0;
                            int intPacketSize = 0;

                            if (DeviceType == 65498)
                            {
                                intPacketSize = 1024;
                            }
                            else
                            {
                                intPacketSize = 64;
                            }

                            if (source.Length % intPacketSize != 0)
                            {
                                intMaxPacket = Convert.ToInt32(source.Length / intPacketSize + 1);
                            }
                            else
                            {
                                intMaxPacket = Convert.ToInt32(source.Length / intPacketSize);
                            }

                            //回复文件大小
                            int UpgradeID = revBuf[25] * 256 + revBuf[26];
                            if (UpgradeID == 0)
                            {
                                #region
                                Byte[] ArayTmp = new Byte[4];
                                ArayTmp[0] = Convert.ToByte((intMaxPacket & 0xFF000000) >> 24);
                                ArayTmp[1] = Convert.ToByte((intMaxPacket & 0xFF0000) >> 16);
                                ArayTmp[2] = Convert.ToByte((intMaxPacket & 0xFF00) >> 8);
                                ArayTmp[3] = Convert.ToByte(intMaxPacket & 0xFF);

                                if (CsConst.mySends.AddBufToSndList(ArayTmp, 0x15FF, CsConst.CurrentUpgradeSubnetID, CsConst.CurrentUpgradeDeviceID, (intPacketSize == 1024), false, false, false) == true)
                                {
                                    UDPReceive.ClearQueueDataForUpgrade();
                                }

                                #endregion
                            }
                            else if (UpgradeID != 0xF8F8)
                            {
                                byte[] ArayFirmware = new byte[intPacketSize + 2];
                                ArayFirmware[0] = Convert.ToByte((UpgradeID & 0xFF00) >> 8);
                                ArayFirmware[1] = Convert.ToByte(UpgradeID & 0xFF);

                                if (UpgradeID < intMaxPacket)
                                {
                                    Array.Copy(source, (UpgradeID - 1) * intPacketSize, ArayFirmware, 2, intPacketSize);
                                }
                                else if (UpgradeID == intMaxPacket)
                                {
                                    if (source.Length % intPacketSize == 0)
                                    {
                                        Array.Copy(source, (UpgradeID - 1) * intPacketSize, ArayFirmware, 2, intPacketSize);
                                    }
                                    else
                                    {
                                        ArayFirmware    = new byte[source.Length % intPacketSize + 2];
                                        ArayFirmware[0] = Convert.ToByte((UpgradeID & 0xFF00) >> 8);
                                        ArayFirmware[1] = Convert.ToByte(UpgradeID & 0xFF);
                                        Array.Copy(source, (UpgradeID - 1) * intPacketSize, ArayFirmware, 2, source.Length % intPacketSize);
                                    }
                                }

                                CsConst.mySends.AddBufToSndList(ArayFirmware, 0x15FF, CsConst.CurrentUpgradeSubnetID, CsConst.CurrentUpgradeDeviceID, (intPacketSize > 80), false, false, false);
                                UDPReceive.ClearQueueDataForUpgrade();

                                if (backgroundWorker1 != null && backgroundWorker1.IsBusy)
                                {
                                    backgroundWorker1.ReportProgress(UpgradeID * 100 / intMaxPacket);
                                }
                            }
                            else
                            {
                                CsConst.MyBlnFinish = true;
                            }

                            d1 = DateTime.Now;
                        }
                    }
                }
                #endregion
            }
            catch
            {
            }
        }
Пример #6
0
        private void btnModify1_Click(object sender, EventArgs e)
        {
            if (numSub.Value == 255)
            {
                return;
            }
            if (numDev.Value == 255)
            {
                return;
            }
            byte[] ArayTmp = new byte[2];

            Cursor.Current = Cursors.WaitCursor;

            ArayTmp[0] = (byte)numSub.Value;
            ArayTmp[1] = (byte)numDev.Value;
            bool isModify = false;

            if (CsConst.SpecailAddress.Contains(MyintDeviceType)) // 要不要加修改地址加密界面
            {
                if (HDLSysPF.SpecialModifyAddress(MyintDeviceType, 0, 255, 255, ArayTmp) == true)
                {
                    UDPReceive.ClearQueueData();
                    if (CsConst.mySends.AddBufToSndList(ArayTmp, 0xE5F7, 255, 255, false, false, true, false) == true)
                    {
                        System.Threading.Thread.Sleep(100);
                        for (int i = 0; i < UDPReceive.receiveQueue.Count; i++)
                        {
                            byte[] readData = UDPReceive.receiveQueue.ToArray()[i];
                            if (readData[21] == 0xE5 && readData[22] == 0xF8)
                            {
                                CsConst.MyTmpName = new List <string>();
                                CsConst.MyTmpName.Add(ArayTmp[0].ToString());
                                CsConst.MyTmpName.Add(ArayTmp[1].ToString());
                                DialogResult   = DialogResult.OK;
                                Cursor.Current = Cursors.Default;
                                isModify       = true;
                                this.Close();
                                break;
                            }
                        }
                    }
                    if (isModify)
                    {
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show(CsConst.mstrINIDefault.IniReadValue("Public", "99632", ""), ""
                                        , MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
                    }
                }
                else
                {
                    MessageBox.Show(CsConst.mstrINIDefault.IniReadValue("Public", "99632", ""), ""
                                    , MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
                }
            }
            else
            {
                UDPReceive.ClearQueueData();
                if (CsConst.mySends.AddBufToSndList(ArayTmp, 0xE5F7, 255, 255, false, false, true, false) == true)
                {
                    System.Threading.Thread.Sleep(100);
                    for (int i = 0; i < UDPReceive.receiveQueue.Count; i++)
                    {
                        byte[] readData = UDPReceive.receiveQueue.ToArray()[i];
                        if (readData[21] == 0xE5 && readData[22] == 0xF8)
                        {
                            CsConst.MyTmpName = new List <string>();
                            CsConst.MyTmpName.Add(ArayTmp[0].ToString());
                            CsConst.MyTmpName.Add(ArayTmp[1].ToString());
                            DialogResult   = DialogResult.OK;
                            Cursor.Current = Cursors.Default;
                            isModify       = true;
                            break;
                        }
                    }
                }
                if (isModify)
                {
                    this.Close();
                }
                else
                {
                    MessageBox.Show(CsConst.mstrINIDefault.IniReadValue("Public", "99632", ""), ""
                                    , MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
                }
            }

            Cursor.Current = Cursors.Default;
        }
Пример #7
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            try
            {
                #region
                Cursor.Current                 = Cursors.WaitCursor;
                CsConst.FastSearch             = true;
                CsConst.AddedDevicesIndexGroup = new List <int>();
                CsConst.mbytCurUsingSubNetID   = 255;
                CsConst.mbytCurUsingDevNetID   = 255;
                UDPReceive.ClearQueueData();
                if (CsConst.myOnlines == null)
                {
                    CsConst.myOnlines = new List <DevOnLine>();
                }
                DateTime d1, d2;
                int      intCMD = 0x000E;
                CsConst.mySends.AddBufToSndList(null, intCMD, 255, 255, false, false, false, false);
                d1 = DateTime.Now;
                d2 = DateTime.Now;

                if (UDPReceive.receiveQueue.Count > 0)
                {
                    int index = 1;
                    if (CsConst.myOnlines.Count > 0)
                    {
                        for (int i = 0; i < CsConst.myOnlines.Count; i++)
                        {
                            int intTmp1 = CsConst.myOnlines[i].intDIndex;
                            if (intTmp1 > index)
                            {
                                index = intTmp1;
                            }
                        }
                    }
                    for (int i = 0; i < UDPReceive.receiveQueue.Count; i++)
                    {
                        byte[] readData = UDPReceive.receiveQueue.ToArray()[i];
                        if (readData[21] == 0x00 && readData[22] == 0x0F && readData.Length >= 45)
                        {
                            DevOnLine temp       = new DevOnLine();
                            byte[]    arayRemark = new byte[20];

                            for (int intI = 0; intI < 20; intI++)
                            {
                                arayRemark[intI] = readData[25 + intI];
                            }
                            string strRemark = HDLPF.Byte2String(arayRemark);
                            temp.bytSub     = readData[17];
                            temp.bytDev     = readData[18];
                            temp.DevName    = temp.bytSub.ToString() + "-" + temp.bytDev.ToString() + "\\" + strRemark.ToString();
                            temp.DeviceType = readData[19] * 256 + readData[20];
                            temp.strVersion = "Unread";

                            if (CsConst.myOnlines.Count > 0)
                            {
                                bool isAdd = true;
                                foreach (DevOnLine tmp in CsConst.myOnlines)
                                {
                                    if (temp.DevName == tmp.DevName && temp.bytSub == tmp.bytSub &&
                                        temp.bytDev == tmp.bytDev && temp.DeviceType == tmp.DeviceType)
                                    {
                                        isAdd = false;
                                        break;
                                    }
                                }
                                if (isAdd)
                                {
                                    index          = index + 1;
                                    temp.intDIndex = index;
                                    CsConst.myOnlines.Add(temp);
                                    HDLSysPF.AddItsDefaultSettings(temp.DeviceType, temp.intDIndex, temp.DevName);
                                }
                            }
                            else
                            {
                                temp.intDIndex = 1;
                                CsConst.myOnlines.Add(temp);
                                HDLSysPF.AddItsDefaultSettings(temp.DeviceType, temp.intDIndex, temp.DevName);
                            }
                        }
                    }
                }
                Cursor.Current = Cursors.Default;

                dgvDevice.Rows.Clear();
                if (CsConst.myOnlines != null && CsConst.myOnlines.Count > 0)
                {
                    for (int i = 0; i < CsConst.myOnlines.Count; i++)
                    {
                        if (CsConst.minAllWirelessDeviceType.Contains(CsConst.myOnlines[i].DeviceType))
                        {
                            object[] obj = new object[] { dgvDevice.RowCount + 1, CsConst.myOnlines[i].bytSub.ToString(),
                                                          CsConst.myOnlines[i].bytDev.ToString(), CsConst.myOnlines[i].DevName.Split('\\')[1].ToString(),
                                                          CsConst.mstrINIDefault.IniReadValue("DeviceType" + CsConst.myOnlines[i].DeviceType.ToString(), "Description", ""),
                                                          CsConst.myOnlines[i].DeviceType.ToString(), CsConst.myOnlines[i].intDIndex.ToString(),
                                                          CsConst.mstrINIDefault.IniReadValue("DeviceType" + CsConst.myOnlines[i].DeviceType.ToString(), "Model", "") };
                            dgvDevice.Rows.Add(obj);
                        }
                    }
                }
                #endregion
            }
            catch
            {
            }
            CsConst.FastSearch = false;
        }
Пример #8
0
 void calculationWorker_DoWork(object sender, DoWorkEventArgs e)
 {
     try
     {
         MyBackGroup.ReportProgress(0, null);
         DateTime t1 = DateTime.Now;
         DateTime t2 = DateTime.Now;
         while (!CsConst.MyBlnFinish)
         {
             if (UDPReceive.receiveQueueForAudio.Count > 0)
             {
                 t1 = DateTime.Now;
                 byte[] arayTmp       = UDPReceive.receiveQueueForAudio.Dequeue();
                 int    FileDataIndex = arayTmp[0] * 256 * 256 * 256 + arayTmp[1] * 256 * 256 + arayTmp[2] * 256 + arayTmp[3];
                 if (arayTmp[0] == 0xFF && arayTmp[1] == 0xFF && arayTmp[2] == 0xFF && arayTmp[3] == 0xFF)
                 {
                     CsConst.MyBlnFinish = true;
                     break;
                 }
                 if ((FileDataIndex + 1024) <= SourceFile.Length)
                 {
                     byte[] arayData = new byte[1024 + 7];
                     arayData[0] = 0x04;
                     arayData[1] = 0x05;
                     arayData[2] = 2;
                     arayData[3] = arayTmp[0];
                     arayData[4] = arayTmp[1];
                     arayData[5] = arayTmp[2];
                     arayData[6] = arayTmp[3];
                     Array.Copy(SourceFile, FileDataIndex, arayData, 7, 1024);
                     CsConst.mySends.AddBufToSndList(arayData, 0x1364, SubNetID, DevID, true, false, false, false);
                     MyBackGroup.ReportProgress(FileDataIndex * 99 / SourceFile.Length);
                 }
                 else
                 {
                     byte[] arayData = new byte[SourceFile.Length - FileDataIndex + 7];
                     arayData[0] = Convert.ToByte((arayData.Length - 2) / 256);
                     arayData[1] = Convert.ToByte((arayData.Length - 2) % 256);
                     arayData[2] = 2;
                     arayData[3] = arayTmp[0];
                     arayData[4] = arayTmp[1];
                     arayData[5] = arayTmp[2];
                     arayData[6] = arayTmp[3];
                     Array.Copy(SourceFile, FileDataIndex, arayData, 7, SourceFile.Length - FileDataIndex);
                     CsConst.mySends.AddBufToSndList(arayData, 0x1364, SubNetID, DevID, true, false, false, false);
                 }
             }
             else
             {
                 t2 = DateTime.Now;
                 if (HDLSysPF.Compare(t2, t1) > 60000)
                 {
                     break;
                 }
             }
         }
         if (CsConst.MyBlnFinish)
         {
             MyBackGroup.ReportProgress(100, null);
             MessageBox.Show(CsConst.mstrINIDefault.IniReadValue("public", "99534", ""));
         }
     }
     catch
     {
     }
     UDPReceive.ClearQueueDataForAudio();
 }