Example #1
0
 private void GetDeviceList()
 {
     try
     {
         dgOnline.Rows.Clear();
         CsConst.myOnlines = new List <DevOnLine>();
         string strFileName = Application.StartupPath + @"\ini\List.txt";
         if (File.Exists(strFileName))
         {
             StreamReader sr = new StreamReader(strFileName, Encoding.Default);
             String       line;
             while ((line = sr.ReadLine()) != null)
             {
                 string str = line.ToString();
                 str = str.Trim();
                 string[] strList = str.Split(' ');
                 Byte[]   arayTmp = new Byte[strList.Length];
                 for (int i = 0; i < strList.Length; i++)
                 {
                     arayTmp[i] = Convert.ToByte(strList[i], 16);
                 }
                 object    obj  = HDLSysPF.BytesToStruct(arayTmp, typeof(DevOnLine));
                 DevOnLine temp = (DevOnLine)obj;
                 CsConst.myOnlines.Add(temp);
                 // HDLSysPF.AddItsDefaultSettings(DeviceType, intDIndex, DevName);
             }
             sr.Dispose();
         }
         if (CsConst.myOnlines != null && CsConst.myOnlines.Count() > 0)
         {
             UpdateDataGridViewOfOnlineDevice();
         }
         File.Delete(strFileName);
     }
     catch
     {
     }
 }
Example #2
0
        private void UpdateDataGridViewOfOnlineDevice()
        {
            dgOnline.Rows.Clear();
            dgOnline.BringToFront();
            #region
            if (CsConst.myOnlines == null)
            {
                return;
            }
            if (CsConst.myOnlines.Count == 0)
            {
                return;
            }

            int[,] arayTmp = new int[CsConst.myOnlines.Count, 3];
            for (int i = 0; i < CsConst.myOnlines.Count; i++)
            {
                arayTmp[i, 0] = CsConst.myOnlines[i].bytSub;
                arayTmp[i, 1] = CsConst.myOnlines[i].bytDev;
                arayTmp[i, 2] = Convert.ToInt32(i);
            }

            #region
            for (int i = 0; i < arayTmp.Length / 3; i++)
            {
                for (int j = 0; j < (arayTmp.Length / 3) - i - 1; j++)
                {
                    if ((arayTmp[j, 0] > arayTmp[j + 1, 0]) ||
                        ((arayTmp[j, 0] == arayTmp[j + 1, 0]) &&
                         (arayTmp[j, 1] > arayTmp[j + 1, 1])))
                    {
                        int Tmp0 = arayTmp[j, 0];
                        int Tmp1 = arayTmp[j, 1];
                        int Tmp2 = arayTmp[j, 2];
                        arayTmp[j, 0]     = arayTmp[j + 1, 0];
                        arayTmp[j, 1]     = arayTmp[j + 1, 1];
                        arayTmp[j, 2]     = arayTmp[j + 1, 2];
                        arayTmp[j + 1, 0] = Tmp0;
                        arayTmp[j + 1, 1] = Tmp1;
                        arayTmp[j + 1, 2] = Tmp2;
                    }
                }
            }
            #endregion

            for (int i = 0; i < CsConst.myOnlines.Count; i++)
            {
                DevOnLine tmp = CsConst.myOnlines[arayTmp[i, 2]];
                if (tmp.DevName == "")
                {
                    return;
                }
                Image oimg1 = HDL_Buspro_Setup_Tool.Properties.Resources.OK;

                String[] strTmp            = DeviceTypeList.GetDisplayInformationFromPublicModeGroup(tmp.DeviceType);
                String   deviceModel       = strTmp[0];
                String   deviceDescription = strTmp[1];

                if (tmp.strVersion == null)
                {
                    tmp.strVersion = "";
                }
                string strVersion = tmp.strVersion;
                if (strVersion == "")
                {
                    strVersion = "Unread";
                }
                object[] obj = { false,             oimg1,      dgOnline.RowCount + 1,    tmp.bytSub, tmp.bytDev, deviceModel, tmp.DevName.Split('\\')[1].ToString(),
                                 deviceDescription, strVersion, tmp.intDIndex.ToString(), "" };
                dgOnline.Rows.Add(obj);
            }
            #endregion
        }
Example #3
0
        private void btnManual_Click(object sender, EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                byte[] ArayTmp  = new byte[0];
                byte   bytSubID = Convert.ToByte(txtMSub.Text);
                byte   bytDevID = Convert.ToByte(txtMDev.Text);

                if (CsConst.mySends.AddBufToSndList(ArayTmp, 0x000E, bytSubID, bytDevID, false, true, true, false) == true)
                {
                    int index = 1;
                    if (CsConst.myOnlines != null && CsConst.myOnlines.Count > 0)
                    {
                        for (int i = 0; i < CsConst.myOnlines.Count; i++)
                        {
                            int intTmp1 = CsConst.myOnlines[i].intDIndex;
                            if (intTmp1 > index)
                            {
                                index = intTmp1;
                            }
                        }
                    }
                    byte[] arayRemark = new byte[20];
                    Array.Copy(CsConst.myRevBuf, 25, arayRemark, 0, 20);
                    string    strRemark = HDLPF.Byte2String(arayRemark);
                    DevOnLine temp      = new DevOnLine();
                    temp.bytSub     = CsConst.myRevBuf[17];
                    temp.bytDev     = CsConst.myRevBuf[18];
                    temp.DevName    = temp.bytSub.ToString() + "-" + temp.bytDev.ToString() + "\\" + strRemark.ToString();
                    temp.DeviceType = CsConst.myRevBuf[19] * 256 + CsConst.myRevBuf[20];

                    Image oimg1 = HDL_Buspro_Setup_Tool.Properties.Resources.OK;

                    String[] strTmp            = DeviceTypeList.GetDisplayInformationFromPublicModeGroup(temp.DeviceType);
                    String   deviceModel       = strTmp[0];
                    String   deviceDescription = strTmp[1];

                    if (temp.strVersion == null)
                    {
                        temp.strVersion = "";
                    }
                    string strVersion = temp.strVersion;
                    if (strVersion == "")
                    {
                        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);
                            object[] obj = new object[] { false, oimg1, DGV.RowCount + 1, temp.bytSub, temp.bytDev, deviceModel, temp.DevName.Split('\\')[1].ToString(),
                                                          deviceDescription, strVersion, index, "" };
                            DGV.Rows.Add(obj);
                        }
                        else
                        {
                            bool isAddRow = true;
                            for (int i = 0; i < DGV.Rows.Count; i++)
                            {
                                if (DGV[9, i].Value.ToString() == index.ToString())
                                {
                                    isAddRow = false;
                                    break;
                                }
                            }
                            object[] obj;
                            if (isAddRow)
                            {
                                obj = new object[] { false, oimg1, DGV.RowCount + 1, temp.bytSub, temp.bytDev, deviceModel, temp.DevName.Split('\\')[1].ToString(),
                                                     deviceDescription, strVersion, index, "" };
                                DGV.Rows.Add(obj);
                            }
                            obj = new object[] { true, temp.bytSub, temp.bytDev, temp.DevName.Split('\\')[1].ToString(),
                                                 deviceModel, deviceDescription };
                            dgvResult.Rows.Add(obj);
                        }
                    }
                    else
                    {
                        temp.intDIndex = 1;
                        if (CsConst.myOnlines == null)
                        {
                            CsConst.myOnlines = new List <DevOnLine>();
                        }
                        CsConst.myOnlines.Add(temp);
                        HDLSysPF.AddItsDefaultSettings(temp.DeviceType, temp.intDIndex, temp.DevName);
                        object[] obj = new object[] { false, oimg1, DGV.RowCount + 1, temp.bytSub, temp.bytDev, deviceModel, temp.DevName.Split('\\')[1].ToString(),
                                                      deviceDescription, strVersion, index, "" };
                        DGV.Rows.Add(obj);
                        obj = new object[] { true, temp.bytSub, temp.bytDev, temp.DevName.Split('\\')[1].ToString(),
                                             deviceDescription, deviceModel };
                        dgvResult.Rows.Add(obj);
                    }
                    CsConst.myRevBuf = new byte[1200];
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            Cursor.Current = Cursors.Default;
        }
Example #4
0
        void calculationWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                UDPReceive.receiveQueue.Clear();
                dgvResult.Rows.Clear();
                if (CsConst.myOnlines == null)
                {
                    CsConst.myOnlines = new List <DevOnLine>();
                }
                //CsConst.mySends.AddBufToSndList(null, 0x000E, 255, 255, false, false, false, false);
                lbCurrentSubValue.Text = txtASub.Text;
                if (txtASub.Text == "255" || (txtADev1.Text == "255" && txtADev2.Text == "255"))
                {
                    Process.Visible        = false;
                    lbCurrentDevValue.Text = "255";
                    CsConst.FastSearch     = true;
                    Byte RepeatSendTimes = 1;

                    Random      R1 = new Random();
                    Random      R2 = new Random();
                    List <Byte> SearchDeviceAddressesList = new List <byte>();
                    R1.Next();
                    Byte[] RandomWhenSearch = new Byte[2];
                    R1.NextBytes(RandomWhenSearch);

                    Byte[] DataSendBuffer = new Byte[2 + SearchDeviceAddressesList.Count];
                    RandomWhenSearch.CopyTo(DataSendBuffer, 0);
RepeatSearch:
                    if (SearchDeviceAddressesList != null && SearchDeviceAddressesList.Count > 0)
                    {
                        DataSendBuffer = new Byte[2 + SearchDeviceAddressesList.Count];
                        RandomWhenSearch.CopyTo(DataSendBuffer, 0);
                        SearchDeviceAddressesList.CopyTo(DataSendBuffer, 2);
                        SearchDeviceAddressesList = new List <byte>();
                    }
                    CsConst.mySends.AddBufToSndList(DataSendBuffer, 0x000E, 255, 255, false, false, false, false);
                    // 广播搜索方式汇集
                    #region
                    DateTime d1, d2;
                    d1 = DateTime.Now;
                    d2 = DateTime.Now;
                    while (UDPReceive.receiveQueue.Count > 0 || HDLSysPF.Compare(d2, d1) < 2000)
                    {
                        if (isStopSearch)
                        {
                            break;
                        }
                        d2 = DateTime.Now;
                        if (UDPReceive.receiveQueue.Count > 0)
                        {
                            byte[] readData = UDPReceive.receiveQueue.Dequeue();

                            if (readData[21] == 0x00 && readData[22] == 0x0F && readData.Length >= 45)
                            {
                                int index = 1;
                                while (CsConst.AddedDevicesIndexGroup.Contains(index))
                                {
                                    index++;
                                }

                                DevOnLine temp       = new DevOnLine();
                                byte[]    arayRemark = new byte[20];

                                HDLSysPF.CopyRemarkBufferFrmMyRevBuffer(readData, arayRemark, 25);
                                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";
                                temp.intDIndex  = index;

                                String[] strTmp            = DeviceTypeList.GetDisplayInformationFromPublicModeGroup(temp.DeviceType);
                                String   deviceDescription = strTmp[1];
                                String   strModel          = strTmp[0];

                                if (temp.strVersion == null)
                                {
                                    temp.strVersion = "";
                                }
                                string strVersion = temp.strVersion;
                                if (strVersion == "")
                                {
                                    strVersion = "Unread";
                                }

                                object[] obj1 = new object[] { true, temp.bytSub, temp.bytDev, temp.DevName.Split('\\')[1].ToString(),
                                                               deviceDescription, strModel, temp.DeviceType };
                                object[] obj2 = { false,             HDL_Buspro_Setup_Tool.Properties.Resources.OK, DGV.RowCount + 1,          temp.bytSub, temp.bytDev, strModel, temp.DevName.Split('\\')[1].ToString(),
                                                  deviceDescription, strVersion,                                    temp.intDIndex.ToString(), "",          temp.DeviceType };
                                Boolean  isAddDeviceToMain = true;
                                // 是不是增加到在线设备列表和主窗体
                                #region
                                if (CsConst.myOnlines.Count > 0)
                                {
                                    foreach (DevOnLine tmp in CsConst.myOnlines)
                                    {
                                        if (temp.DevName == tmp.DevName && temp.bytSub == tmp.bytSub && temp.bytDev == tmp.bytDev && temp.DeviceType == tmp.DeviceType)
                                        {
                                            isAddDeviceToMain = false;
                                            break;
                                        }
                                    }
                                }

                                if (isAddDeviceToMain)
                                {
                                    CsConst.myOnlines.Add(temp);
                                    HDLSysPF.AddItsDefaultSettings(temp.DeviceType, temp.intDIndex, temp.DevName);
                                    CsConst.AddedDevicesIndexGroup.Add(index);
                                    if (this.DGV.InvokeRequired)//等待异步
                                    {
                                        FlushClient2 fc = new FlushClient2(ThreadFunction2);
                                        this.DGV.Invoke(fc, new object[] { obj2 });
                                    }
                                    else
                                    {
                                        DGV.Rows.Add(obj2);
                                    }
                                }
                                #endregion
                                //添加到当前窗体
                                #region
                                isAddToList = true;
                                if (dgvResult.Rows.Count > 0)
                                {
                                    for (int i = 0; i < dgvResult.Rows.Count; i++)
                                    {
                                        if (temp.DevName == dgvResult[1, i].Value.ToString() + "-" + dgvResult[2, i].Value.ToString() +
                                            "\\" + dgvResult[3, i].Value.ToString())
                                        {
                                            isAddToList = false;
                                            break;
                                        }
                                    }
                                    if (isAddToList)
                                    {
                                        if (this.dgvResult.InvokeRequired)//等待异步
                                        {
                                            FlushClient1 fc = new FlushClient1(ThreadFunction1);
                                            this.dgvResult.Invoke(fc, new object[] { obj1 });
                                        }
                                        else
                                        {
                                            dgvResult.Rows.Add(obj1);
                                        }
                                    }
                                }
                                else
                                {
                                    if (this.dgvResult.InvokeRequired)//等待异步
                                    {
                                        FlushClient1 fc = new FlushClient1(ThreadFunction1);
                                        this.dgvResult.Invoke(fc, new object[] { obj1 });
                                    }
                                    else
                                    {
                                        dgvResult.Rows.Add(obj1);
                                    }
                                }
                                if (isAddToList)
                                {
                                    SearchDeviceAddressesList.Add(temp.bytSub);
                                    SearchDeviceAddressesList.Add(temp.bytDev);
                                }
                                #endregion
                            }
                        }
                    }
                    #endregion

                    RepeatSendTimes++;
                    if (RepeatSendTimes <= 4)
                    {
                        goto RepeatSearch;
                    }
                }
                else
                {
                    Process.Visible = true;
                    SubnetID        = Convert.ToByte(txtASub.Text);
                    DeviceID1       = Convert.ToByte(txtADev1.Text);
                    DeviceID2       = Convert.ToByte(txtADev2.Text);
                    int intTmp = 0;
                    for (byte byt = DeviceID1; byt <= DeviceID2; byt++)
                    {
                        if (isStopSearch)
                        {
                            break;
                        }
                        byte[] ArayTmp  = new byte[0];
                        byte   bytSubID = Convert.ToByte(SubnetID);
                        byte   bytDevID = Convert.ToByte(byt);
                        if (CsConst.mySends.AddBufToSndList(ArayTmp, 0x000E, bytSubID, bytDevID, false, false, true, false) == true)
                        {
                            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;
                                    }
                                }
                            }
                            byte[] arayRemark = new byte[20];
                            for (int intI = 0; intI < 20; intI++)
                            {
                                arayRemark[intI] = CsConst.myRevBuf[25 + intI];
                            }
                            string    strRemark = HDLPF.Byte2String(arayRemark);
                            DevOnLine temp      = new DevOnLine();
                            temp.bytSub     = CsConst.myRevBuf[17];
                            temp.bytDev     = CsConst.myRevBuf[18];
                            temp.DevName    = temp.bytSub.ToString() + "-" + temp.bytDev.ToString() + "\\" + strRemark.ToString();
                            temp.DeviceType = CsConst.myRevBuf[19] * 256 + CsConst.myRevBuf[20];
                            temp.strVersion = "Unread";

                            String[] strArayTmp        = DeviceTypeList.GetDisplayInformationFromPublicModeGroup(temp.DeviceType);
                            String   deviceDescription = strArayTmp[1];
                            String   strModel          = strArayTmp[0];

                            string strTmp = string.Format("{0,-3}{1,-1}{2,-3}{3,-1}{4,-20}", temp.bytSub.ToString(), "-", temp.bytDev.ToString(), "-",
                                                          strModel);
                            if (temp.strVersion == null)
                            {
                                temp.strVersion = "";
                            }
                            string strVersion = temp.strVersion;
                            if (strVersion == "")
                            {
                                strVersion = "Unread";
                            }
                            isAddDeviceToMain = true;
                            if (CsConst.myOnlines.Count > 0)
                            {
                                foreach (DevOnLine tmp in CsConst.myOnlines)
                                {
                                    if (temp.DevName == tmp.DevName && temp.bytSub == tmp.bytSub &&
                                        temp.bytDev == tmp.bytDev && temp.DeviceType == tmp.DeviceType)
                                    {
                                        isAddDeviceToMain = false;
                                        break;
                                    }
                                }
                                if (isAddDeviceToMain)
                                {
                                    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);
                            }
                            object[] obj1 = new object[] { true, temp.bytSub, temp.bytDev, temp.DevName.Split('\\')[1].ToString(),
                                                           deviceDescription, strModel };
                            object[] obj2 = new object[] { false, DGV.RowCount + 1, temp.DevName.Split('\\')[1].ToString(),
                                                           deviceDescription, strVersion, temp.bytSub, temp.bytDev, strModel,
                                                           index, "" };
                            if (DGV.InvokeRequired)//等待异步
                            {
                                FlushClient2 fc = new FlushClient2(ThreadFunction2);
                                this.DGV.Invoke(fc, new object[] { obj2 });
                            }
                            else
                            {
                                if (isAddDeviceToMain)
                                {
                                    DGV.Rows.Add(obj2);
                                }
                            }
                            isAddToList = true;
                            if (dgvResult.Rows.Count > 0)
                            {
                                for (int i = 0; i < dgvResult.Rows.Count; i++)
                                {
                                    if (temp.DevName == dgvResult[1, i].Value.ToString() + "-" + dgvResult[2, i].Value.ToString() +
                                        "\\" + dgvResult[3, i].Value.ToString())
                                    {
                                        isAddToList = false;
                                        break;
                                    }
                                }
                                if (isAddToList)
                                {
                                    if (this.dgvResult.InvokeRequired)//等待异步
                                    {
                                        FlushClient1 fc = new FlushClient1(ThreadFunction1);
                                        this.dgvResult.Invoke(fc, new object[] { obj1 });
                                    }
                                    else
                                    {
                                        dgvResult.Rows.Add(obj1);
                                    }
                                }
                            }
                            else
                            {
                                if (this.dgvResult.InvokeRequired)//等待异步
                                {
                                    FlushClient1 fc = new FlushClient1(ThreadFunction1);
                                    this.dgvResult.Invoke(fc, new object[] { obj1 });
                                }
                                else
                                {
                                    dgvResult.Rows.Add(obj1);
                                }
                            }
                            //CsConst.myRevBuf = new byte[1200];
                            //System.Threading.Thread.Sleep(10);
                        }

                        if (byt + 1 <= DeviceID2)
                        {
                            lbCurrentDevValue.Text = (byt + 1).ToString();
                        }

                        if (CsConst.calculationWorker != null && CsConst.calculationWorker.IsBusy)
                        {
                            if (intTmp * 100 / (DeviceID2 - DeviceID1) <= 100)
                            {
                                CsConst.calculationWorker.ReportProgress(intTmp * 100 / (DeviceID2 - DeviceID1));
                            }
                        }
                        intTmp++;
                    }
                }
            }
            catch
            {
            }
        }
Example #5
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;
        }
Example #6
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            byte[] ArayTmp  = new byte[0];
            byte   bytSubID = Convert.ToByte(numSub.Value);
            byte   bytDevID = Convert.ToByte(numDev.Value);

            if (CsConst.mySends.AddBufToSndList(ArayTmp, 0x000E, bytSubID, bytDevID, false, true, true, false) == true)
            {
                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;
                        }
                    }
                }
                byte[] arayRemark = new byte[20];
                for (int intI = 0; intI < 20; intI++)
                {
                    arayRemark[intI] = CsConst.myRevBuf[25 + intI];
                }
                string    strRemark = HDLPF.Byte2String(arayRemark);
                DevOnLine temp      = new DevOnLine();
                temp.bytSub     = CsConst.myRevBuf[17];
                temp.bytDev     = CsConst.myRevBuf[18];
                temp.DevName    = temp.bytSub.ToString() + "-" + temp.bytDev.ToString() + "\\" + strRemark.ToString();
                temp.DeviceType = CsConst.myRevBuf[19] * 256 + CsConst.myRevBuf[20];
                string   strModel = CsConst.mstrINIDefault.IniReadValue("DeviceType" + temp.DeviceType.ToString(), "Model", "");
                object[] obj      = { dgvDevice.RowCount + 1,                                                   temp.bytSub.ToString(),     temp.bytDev.ToString(), strRemark,
                                      CsConst.mstrINIDefault.IniReadValue("DeviceType" + temp.DeviceType.ToString(), "Description",              ""),
                                      strModel,                                                                      temp.DeviceType.ToString(), index.ToString() };
                dgvDevice.Rows.Add(obj);
                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);
                }
                CsConst.myRevBuf = new byte[1200];
            }
            Cursor.Current = Cursors.Default;
        }