示例#1
0
        public override bool Receive(SerialPort serialPort)
        {
            if (!base.Receive(serialPort))
            {
                return(false);
            }
            if ((Length != 7) && (Length != 9))
            {
                return(false);
            }

            Parameter      = new DriveParameter();
            Parameter.Type = (DriveParameterType)_buffer[0];
            switch (Parameter.DataType)
            {
            case DriveParameterDataType.Byte:
            {
                byte value = _buffer[1];
                Parameter.Value = value;
            }
            break;

            case DriveParameterDataType.UInt16:
            {
                UInt16 value = BitConverter.ToUInt16(_buffer, 1);
                Parameter.Value = value;
            }
            break;

            case DriveParameterDataType.Int16:
            {
                Int16 value = BitConverter.ToInt16(_buffer, 1);
                Parameter.Value = value;
            }
            break;

            case DriveParameterDataType.UInt32:
            {
                UInt32 value = BitConverter.ToUInt32(_buffer, 1);
                Parameter.Value = value;
            }
            break;

            case DriveParameterDataType.Single:
            {
                Single value = BitConverter.ToSingle(_buffer, 1);
                Parameter.Value = value;
            }
            break;
            }
            return(true);
        }
示例#2
0
        public override bool Receive(SerialPort serialPort)
        {
            if (!base.Receive(serialPort))
                return false;
            if ((Length != 7) && (Length != 9))
                return false;

            Parameter = new DriveParameter();
            Parameter.Type = (DriveParameterType)_buffer[0];
            switch (Parameter.DataType)
            {
                case DriveParameterDataType.Byte:
                    {
                        byte value = _buffer[1];
                        Parameter.Value = value;
                    }
                    break;
                case DriveParameterDataType.UInt16:
                    {
                        UInt16 value = BitConverter.ToUInt16(_buffer, 1);
                        Parameter.Value = value;
                    }
                    break;
                case DriveParameterDataType.Int16:
                    {
                        Int16 value = BitConverter.ToInt16(_buffer, 1);
                        Parameter.Value = value;
                    }
                    break;
                case DriveParameterDataType.UInt32:
                    {
                        UInt32 value = BitConverter.ToUInt32(_buffer, 1);
                        Parameter.Value = value;
                    }
                    break;
                case DriveParameterDataType.Single:
                    {
                        Single value = BitConverter.ToSingle(_buffer, 1);
                        Parameter.Value = value;
                    }
                    break;
            }
            return true;
        }