コード例 #1
0
        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.ReadResponsePacketData(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 = "";
            }
        }
コード例 #2
0
        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);
        }