private void getDataGridViewList() { int Length = 0; if (Type == 1) { Length = oMHRCU.myRS2BUS.Count; } else if (Type == 2) { Length = oMHRCU.my4852BUS.Count; } for (int i = 0; i < Length; i++) { Rs232ToBus temp = null; if (Type == 1) { temp = oMHRCU.myRS2BUS[i]; } else if (Type == 2) { temp = oMHRCU.my4852BUS[i]; } string strEnable = CsConst.WholeTextsList[1775].sDisplayName; if (temp.rs232Param.enable == 1) { strEnable = CsConst.mstrINIDefault.IniReadValue("public", "00042", ""); } string strType = CsConst.WholeTextsList[1775].sDisplayName; string strCMD = ""; string strEnd = cbEndChar.Items[0].ToString(); if (temp.rs232Param.type == 0) { //strType = CsConst.mstrINIDefault.IniReadValue("public", "99838", ""); //int Count = temp.TmpRS232.RSCMD[temp.TmpRS232.RSCMD.Length - 1]; //if (Count > 33) Count = 33; //byte[] arayTmp = new byte[Count]; //Array.Copy(temp.TmpRS232.RSCMD, 0, arayTmp, 0, Count); //if (Count == 0) // strCMD = ""; //else // strCMD = HDLPF.Byte2String(arayTmp); //strCMD = HDLPF.Byte2String(arayTmp); //if (arayTmp.Length > 2 && arayTmp[arayTmp.Length - 1] == 0x0A && arayTmp[arayTmp.Length - 2] == 0x0D) strEnd = cbEndChar.Items[2].ToString(); //else if (arayTmp.Length > 1 && arayTmp[arayTmp.Length - 1] == 0x0D) strEnd = cbEndChar.Items[1].ToString(); } else if (temp.rs232Param.type == 1) { //strType = CsConst.mstrINIDefault.IniReadValue("public", "99839", ""); //int Count = temp.TmpRS232.RSCMD[temp.TmpRS232.RSCMD.Length - 1]; //if (Count > 33) Count = 33; //for (int j = 0; j < Count; j++) //{ // strCMD = strCMD + GlobalClass.AddLeftZero(temp.TmpRS232.RSCMD[j].ToString("X"), 2) + " "; //} } strCMD = strCMD.Trim(); object[] obj = new object[] { temp.ID.ToString(), temp.remark.ToString(), strEnable, strType, strCMD, strEnd }; dgvCommand.Rows.Add(obj); } }
private void btnSure_Click(object sender, EventArgs e) { try { oMHRCU.myRS2BUS = new List <Rs232ToBus>(); setAllControlVisible(false); if (Type == 1) { oMHRCU.myRS2BUS = new List <Rs232ToBus>(); } else if (Type == 2) { oMHRCU.my4852BUS = new List <Rs232ToBus>(); } Cursor.Current = Cursors.WaitCursor; dgvCommand.Rows.Clear(); btnSure.Enabled = false; byte[] arayTmp = new byte[1]; byte bytFrm = Convert.ToByte(Convert.ToInt32(txtFrm.Text)); byte bytTo = Convert.ToByte(txtTo.Text); int CMD1 = 0xE410; int CMD2 = 0xE418; if (Type == 1) { CMD1 = 0xE410; CMD2 = 0xE418; } else if (Type == 2) { CMD1 = 0xDA51; CMD2 = 0xDA59; } for (byte byt = bytFrm; byt <= bytTo; byt++) { Rs232ToBus temp = new Rs232ToBus(); temp.rs232Param = new Rs232Param(); arayTmp[0] = Convert.ToByte(byt); if (CsConst.mySends.AddBufToSndList(arayTmp, CMD1, SubNetID, DevID, false, true, true, CsConst.minAllWirelessDeviceType.Contains(MyintDeviceType)) == true) { temp.ID = Convert.ToByte(byt); temp.rs232Param.enable = CsConst.myRevBuf[27]; temp.rs232Param.type = CsConst.myRevBuf[28]; // temp.rs232Param.RSCMD = new byte[33 + 1]; // Array.Copy(CsConst.myRevBuf, 29, temp.TmpRS232.RSCMD, 0, temp.TmpRS232.RSCMD.Length); System.Threading.Thread.Sleep(1); } else { Cursor.Current = Cursors.Default; return; } if (CsConst.mySends.AddBufToSndList(arayTmp, CMD2, SubNetID, DevID, false, true, true, CsConst.minAllWirelessDeviceType.Contains(MyintDeviceType)) == true) { byte[] arayRemark = new byte[20]; for (int intI = 0; intI < 20; intI++) { arayRemark[intI] = CsConst.myRevBuf[27 + intI]; } temp.remark = HDLPF.Byte2String(arayRemark); System.Threading.Thread.Sleep(1); } else { Cursor.Current = Cursors.Default; return; } if (Type == 1) { oMHRCU.myRS2BUS.Add(temp); } else if (Type == 2) { oMHRCU.my4852BUS.Add(temp); } } } catch { } btnSure.Enabled = true; Cursor.Current = Cursors.Default; getDataGridViewList(); }