Пример #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 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;
        }
Пример #3
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;
        }