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 = ""; } }
private void buttonSave_Click(object sender, EventArgs e) { object[] deviceConfig = new object[4]; deviceConfig[0] = null; deviceConfig[1] = comboBoxDeviceAddress.SelectedValue; deviceConfig[2] = comboBoxCommand.Text; deviceConfig[3] = textBoxCommandDesc.Text; dbMgr.UpdateDevice(deviceConfig); int Id = dbMgr.GetDeviceId(comboBoxDeviceAddress.SelectedValue.ToString(), comboBoxCommand.Text); SaveDataBytes(Id); dbMgr.SaveConfig(); }
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++; } } } }
public ArrayList DecodeResponse(byte [] response) { //response. string deviceAddress = DecimalToBase((int)response[0], 16); ArrayList responseArray = new ArrayList(); ArrayList decodedArray = new ArrayList(); if (response.Length > 3) { responseArray.Add("Read"); responseArray.Add(deviceAddress); 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); responseArray.Add(command); command = "0x" + command; byte checkSum = CalculateCheckSome(response, response.Length - 2); // if (checkSum == response[response.Length - 2]) /// check the check sum and verify the recieved data { int id = dbMgr.GetDeviceId(deviceAddress, command); object[] responseData = dbMgr.ReadResponsePacketData(id); for (int i = 2; i < response.Length; i++) { responseArray.Add(DecimalToBase((int)response[i], 16)); } for (int i = 0; i < responseData.Length; i++) { string byteDataTag = ((object[])responseData[i])[4].ToString(); if (byteDataTag == ByteDataTag.EightBitSingle.ToString()) { int byteValue = (response[i] & 0x7f); // remove the 7 th bit decodedArray.Add(byteValue); } else if (byteDataTag == ByteDataTag.EightBitNibble.ToString() && (((object[])responseData[i + 1])[4].ToString()) == ByteDataTag.EightBitNibble.ToString()) { int databyte = response[i] & 0x0f; databyte = databyte << 4; int lsb = response[i + 1] & 0x0f; databyte = databyte | lsb; decodedArray.Add(databyte); i++; } } } UpdateDataRecieved(responseArray); } return(decodedArray); }