示例#1
0
        public static object ByteArrayToStruct(byte[] bytes, DataTypes dataType)
        {
            int    size;
            IntPtr ptr;

            switch (dataType)
            {
            case DataTypes.Imu:
                var ImuStruct = new myohw_imu_data_t();
                size = Marshal.SizeOf(ImuStruct);

                ptr = Marshal.AllocHGlobal(size);
                Marshal.Copy(bytes, 0, ptr, size);
                ImuStruct = (myohw_imu_data_t)Marshal.PtrToStructure(ptr, ImuStruct.GetType());
                Marshal.FreeHGlobal(ptr);

                return(ImuStruct);

            case DataTypes.Emg:
                var EmgStruct = new myohw_emg_data_t();
                size = Marshal.SizeOf(EmgStruct);

                ptr = Marshal.AllocHGlobal(size);
                Marshal.Copy(bytes, 0, ptr, size);
                EmgStruct = (myohw_emg_data_t)Marshal.PtrToStructure(ptr, EmgStruct.GetType());
                Marshal.FreeHGlobal(ptr);

                return(EmgStruct);
            }
            return(null);
        }
示例#2
0
        public static myohw_emg_data_t ByteArrayToStruct(byte[] bytes)
        {
            myohw_emg_data_t _struct = new myohw_emg_data_t();
            int size = Marshal.SizeOf(_struct);

            IntPtr ptr = Marshal.AllocHGlobal(size);

            Marshal.Copy(bytes, 0, ptr, size);
            _struct = (myohw_emg_data_t)Marshal.PtrToStructure(ptr, _struct.GetType());
            Marshal.FreeHGlobal(ptr);

            return(_struct);
        }