private void comboBoxCommand_SelectedIndexChanged(object sender, EventArgs e) { if (comboBoxCommand.SelectedValue != null && dataBytes.Count > 0) { textBoxCommandDesc.Text = dbMgr.GetDeviceDescription(comboBoxDeviceAddress.SelectedValue.ToString(), comboBoxCommand.SelectedValue.ToString()); int Id = dbMgr.GetDeviceId(comboBoxDeviceAddress.SelectedValue.ToString(), comboBoxCommand.Text); object[] readByteData = dbMgr.ReadSendPacketData(Id); for (int i = 0; i < dataBytes.Count; i++) { ((CustomByteData)dataBytes[i]).DataTypeTag = DataType.Address.ToString(); ((CustomByteData)dataBytes[i]).TxtDataDescription = ""; ((CustomByteData)dataBytes[i]).DataTag = ByteDataTag.EightBitSingle.ToString(); } for (int i = 0; i < readByteData.Length; i++) { object[] tempObject = (object[])(readByteData[i]); ((CustomByteData)dataBytes[i]).DataTypeTag = (string)tempObject[1]; ((CustomByteData)dataBytes[i]).TxtDataDescription = (string)tempObject[3]; ((CustomByteData)dataBytes[i]).DataTag = (string)tempObject[4]; } } else { textBoxCommandDesc.Text = ""; } }
public ArrayList DecodeResponse2(byte[] response) { string deviceAddress = DecimalToBase((int)response[0], 16); ArrayList decodedArray = new ArrayList(); deviceAddress = "0x" + deviceAddress; switch (deviceAddress) { case "0x10": deviceAddress = DeviceAddresses.SmartBord.ToString(); break; case "0x13": deviceAddress = DeviceAddresses.BackPlane.ToString(); break; } string command = DecimalToBase((int)response[1], 16); command = "0x" + command; int id = dbMgr.GetDeviceId(deviceAddress, command); object[] responseData = dbMgr.ReadSendPacketData(id); for (int i = 0; i < responseData.Length; i++) { string byteDataTag = ((object[])responseData[i])[4].ToString(); string eightBitNibble = ByteDataTag.EightBitNibble.ToString(); if (byteDataTag == ByteDataTag.EightBitSingle.ToString()) { int byteValue = (response[i + 2] & 0x7f); // remove the 7 th bit decodedArray.Add(byteValue); } else if (byteDataTag == eightBitNibble && (((object[])responseData[i + 1])[4].ToString()) == eightBitNibble) { int databyte = response[i + 2] & 0x0f; databyte = databyte << 4; int lsb = response[i + 3] & 0x0f; databyte = databyte | lsb; decodedArray.Add(databyte); i++; } } return(decodedArray); }
public void RefreshAll(string deviceAddress, string command) { dbMgr = new DBManager(); Controls.Clear(); dataBytes = new ArrayList(); if (dbMgr.OpenConfig(configFilePath)) { int Id = dbMgr.GetDeviceId(deviceAddress, command); object[] sendPacketData = dbMgr.ReadSendPacketData(Id); for (int i = 0; i < sendPacketData.Length; i++) { string dataTagType = (((object[])sendPacketData[i])[4].ToString()); string dataTypeNibble = ByteDataTag.EightBitNibble.ToString(); if (dataTagType == ByteDataTag.EightBitSingle.ToString()) { UserInputData userInputData1 = new V25Emulator.UserInputData(); userInputData1.LabelName = (string)(((object [])sendPacketData[i])[1]); if (i > 0) { if (((object[])sendPacketData[i - 1])[4].ToString() == dataTypeNibble) { userInputData1.Location = new System.Drawing.Point(20, 10 + 30 * (i - 1)); } else { userInputData1.Location = new System.Drawing.Point(20, 10 + 30 * i); } } else { userInputData1.Location = new System.Drawing.Point(20, 10 + 30 * i); } userInputData1.Name = "userInputData1"; userInputData1.Size = new System.Drawing.Size(205, 34); userInputData1.TabIndex = 0; userInputData1.TextBoxData = ""; dataBytes.Add(userInputData1); Controls.Add(userInputData1); } else if (dataTagType == dataTypeNibble && (((object[])sendPacketData[i + 1])[4].ToString()) == dataTypeNibble) { UserInputData userInputData1 = new V25Emulator.UserInputData(); userInputData1.LabelName = (string)(((object[])sendPacketData[i])[1]); if (dataBytes.Count >= 1) { userInputData1.Location = new System.Drawing.Point(20, ((UserInputData)dataBytes[dataBytes.Count - 1]).Location.Y + 30); } else { userInputData1.Location = new System.Drawing.Point(20, 10 + 30 * i); } userInputData1.Name = "userInputData1"; userInputData1.Size = new System.Drawing.Size(205, 34); userInputData1.TabIndex = 0; userInputData1.TextBoxData = ""; dataBytes.Add(userInputData1); Controls.Add(userInputData1); i++; } } } }