コード例 #1
0
ファイル: VdfEnities.cs プロジェクト: twoflyliu/DcmAppTest
        private uint GetValue(List <byte> data, VdfByteOrder byteOrder, int startBit, int bitLen)
        {
            switch (byteOrder)
            {
            default:
            case VdfByteOrder.Intel:
                return(ValueUtils.GetValueIntel(data, startBit, bitLen));

            case VdfByteOrder.Motorola:
                return(ValueUtils.GetValueMotorola(data, startBit, bitLen));
            }
        }
コード例 #2
0
        // 对信号的值进行编码
        // 信号值从data中获取
        public static string Encode(List <byte> data, VdfSignal signal, bool withUnit = false)
        {
            if (signal.VdfValueDesc == null)
            {
                throw new VdfException("Signal Value Desc cannot be null");
            }

            string ret;

            // 使用两个编码接口,
            // 因为BCD编码使用传整形值是不能满足需求的,必须传递字节数组,并且需要直到,字节序
            try
            {
                uint value = 0;
                switch (signal.ByteOrder)
                {
                case VdfByteOrder.Intel:
                    value = ValueUtils.GetValueIntel(data, signal.StartBit, signal.BitLen);
                    break;

                case VdfByteOrder.Motorola:
                    value = ValueUtils.GetValueMotorola(data, signal.StartBit, signal.BitLen);
                    break;

                default:
                    throw new VdfException("Invalid Byte Order: " + signal.ByteOrder.ToString());
                }
                ret = signal.VdfValueDesc.Encode(value, withUnit);
            }
            catch (NotImplementedException)
            {
                ret = signal.VdfValueDesc.Encode(data, signal, withUnit);
            }

            return(ret);
        }