Пример #1
0
        public object[] GetArray(TypeCollection types)
        {
            UInt16 arrayTypeCrc = ValueNative.GetArrayType(m_nativeInstance);
            Type   arrayType    = types.FindTypeByCrc(arrayTypeCrc);

            if (arrayType == null || arrayType.ManagedType == null)
            {
                return(null);
            }

            int elementSize = ValueNative.GetArrayElementSize(m_nativeInstance);

            if (elementSize != Marshal.SizeOf(arrayType.ManagedType))
            {
                return(null);
            }

            int length = ValueNative.GetArrayLength(m_nativeInstance);

            object[] array = new object[length];

            IntPtr arrayData = ValueNative.GetArrayData(m_nativeInstance);

            for (int i = 0; i < length; i++)
            {
                array[i]   = Marshal.PtrToStructure(arrayData, arrayType.ManagedType);
                arrayData += elementSize;
            }

            return(array);
        }
Пример #2
0
 public Conct()
 {
     m_device         = new Device();
     m_controller     = m_device.Controller;
     m_typeCollection = new TypeCollection();
     m_devices        = new ObservableCollection <ConnectedDevice>();
 }
Пример #3
0
        public void SetArray(TypeCollection types, object[] array, System.Type managedType = null)
        {
            if (array == null)
            {
                throw new ArgumentNullException("array");
            }

            if (managedType == null && array.Length == 0)
            {
                throw new ArgumentNullException("managedType");
            }

            if (managedType == null)
            {
                managedType = array[0].GetType();
            }

            Type type = types.FindTypeByManagedType(managedType);

            if (type == null)
            {
                throw new Exception("Type not found for " + managedType.FullName);
            }

            int elementSize = Marshal.SizeOf(managedType);

            if (array.Length == 0)
            {
                ValueNative.SetArray(m_nativeInstance, IntPtr.Zero, elementSize, 0, type.Crc);
                return;
            }

            IntPtr arrayData = Marshal.AllocHGlobal(elementSize * array.Length);

            for (int i = 0; i < array.Length; i++)
            {
                if (array[i] == null)
                {
                    throw new ArgumentNullException("array[" + i.ToString() + "]");
                }

                if (array[i].GetType() != managedType)
                {
                    throw new Exception("Type '" + array[i].GetType().FullName + "' in array[" + i.ToString() + "] doesn't match given Type '" + managedType.FullName + "'");
                }

                Marshal.StructureToPtr(array[i], arrayData, false);
                arrayData += elementSize;
            }

            ValueNative.SetArray(m_nativeInstance, arrayData, elementSize, array.Length, type.Crc);
            Marshal.FreeHGlobal(arrayData);
        }
Пример #4
0
        public object GetStruct(TypeCollection types)
        {
            UInt16     structTypeCrc = ValueNative.GetStructType(m_nativeInstance);
            StructType structType    = types.FindStructByCrc(structTypeCrc);

            if (structType == null || structType.ManagedType == null)
            {
                return(null);
            }

            if (ValueNative.GetStructSize(m_nativeInstance) != Marshal.SizeOf(structType.ManagedType))
            {
                return(null);
            }

            IntPtr structData = ValueNative.GetStructData(m_nativeInstance);

            return(Marshal.PtrToStructure(structData, structType.ManagedType));
        }
Пример #5
0
        public void Dispose()
        {
            if (m_controller != null)
            {
                m_controller.Dispose();
                m_controller = null;
            }

            if (m_device != null)
            {
                m_device.Dispose();
                m_device = null;
            }

            if (m_typeCollection != null)
            {
                m_typeCollection.Dispose();
                m_typeCollection = null;
            }
        }
Пример #6
0
        public void SetStruct(TypeCollection types, object data)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            Type type = types.FindTypeByManagedType(data.GetType());

            if (type == null)
            {
                throw new Exception("Type not found for " + data.GetType().FullName);
            }

            int    structSize = Marshal.SizeOf(type.ManagedType);
            IntPtr structData = Marshal.AllocHGlobal(structSize);

            Marshal.StructureToPtr(data, structData, false);
            ValueNative.SetStruct(m_nativeInstance, structData, structSize, type.Crc);

            Marshal.FreeHGlobal(structData);
        }
Пример #7
0
 public StructType(IntPtr nativeInstance, TypeCollection collection)
     : base(nativeInstance)
 {
     m_collection = collection;
 }
Пример #8
0
 public InterfaceType(IntPtr nativeInstance, TypeCollection collection)
     : base(nativeInstance)
 {
     m_collection = collection;
 }