コード例 #1
0
        internal static object ByteToObject(this byte[] payload, EpicsType epicsType)
        {
            switch (epicsType)
            {
            case EpicsType.String:
                return(ByteConverter.ToString(payload));

            case EpicsType.Short:
                return(ByteConverter.ToInt16(payload));

            case EpicsType.UShort:
                return(ByteConverter.ToUInt16(payload));

            case EpicsType.Float:
                return(ByteConverter.ToFloat(payload));

            case EpicsType.Byte:
                return(ByteConverter.ToByte(payload, 0));

            case EpicsType.Int:
                return(ByteConverter.ToInt32(payload));

            case EpicsType.Double:
                return(ByteConverter.ToDouble(payload));

            default:
                throw new Exception("Type " + epicsType.ToString() + " not yet supported");
            }
        }
コード例 #2
0
        internal static object ByteToObject(this byte[] payload, EpicsType epicsType, int datacount)
        {
            switch (epicsType)
            {
            /// -> basic types
            case EpicsType.String:
            {
                string[] arr = new string[datacount];
                for (int i = 0; i < datacount; i++)
                {
                    string tmp = ByteConverter.ToString(payload, i * 40);
                    arr[i] = tmp;
                    /*offset += tmp.Length + 1;*/
                }

                return(arr);
            }

            case EpicsType.Short:
            {
                short[] arr = new short[datacount];
                for (int i = 0; i < datacount; i++)
                {
                    arr[i] = ByteConverter.ToInt16(payload, i * 2);
                }

                return(arr);
            }

            case EpicsType.Float:
            {
                float[] arr = new float[datacount];
                for (int i = 0; i < datacount; i++)
                {
                    arr[i] = ByteConverter.ToFloat(payload, i * 4);
                }

                return(arr);
            }

            case EpicsType.Byte:
            {
                byte[] arr = new byte[datacount];
                for (int i = 0; i < datacount; i++)
                {
                    arr[i] = ByteConverter.ToByte(payload, i);
                }

                return(arr);
            }

            case EpicsType.Int:
            {
                int[] arr = new int[datacount];
                for (int i = 0; i < datacount; i++)
                {
                    arr[i] = ByteConverter.ToInt32(payload, i * 4);
                }

                return(arr);
            }

            case EpicsType.Double:
            {
                double[] arr = new double[datacount];
                for (int i = 0; i < datacount; i++)
                {
                    arr[i] = ByteConverter.ToDouble(payload, i * 8);
                }

                return(arr);
            }

            default:
                throw new Exception("Type " + epicsType.ToString() + " not yet supported");
            }
        }