Ejemplo n.º 1
0
        internal static AdlStatus ADL_Adapter_AdapterInfo_Get(ADLAdapterInfo[] info)
        {
            int       elementSize = Marshal.SizeOf(typeof(ADLAdapterInfo));
            int       size        = info.Length * elementSize;
            IntPtr    ptr         = Marshal.AllocHGlobal(size);
            AdlStatus result      = _ADL_Adapter_AdapterInfo_Get(ptr, size);

            for (int i = 0; i < info.Length; i++)
            {
                info[i] = (ADLAdapterInfo)Marshal.PtrToStructure((IntPtr)((long)ptr + i * elementSize), typeof(ADLAdapterInfo));
            }
            Marshal.FreeHGlobal(ptr);

            // the ADLAdapterInfo.VendorID field reported by ADL is wrong on
            // Windows systems (parse error), so we fix this here
            for (int i = 0; i < info.Length; i++)
            {
                // try Windows UDID format
                Match m = Regex.Match(info[i].UDID, "PCI_VEN_([A-Fa-f0-9]{1,4})&.*");
                if (m.Success && m.Groups.Count == 2)
                {
                    info[i].VendorID = Convert.ToInt32(m.Groups[1].Value, 16);
                    continue;
                }
                // if above failed, try Unix UDID format
                m = Regex.Match(info[i].UDID, "[0-9]+:[0-9]+:([0-9]+):[0-9]+:[0-9]+");
                if (m.Success && m.Groups.Count == 2)
                {
                    info[i].VendorID = Convert.ToInt32(m.Groups[1].Value, 10);
                }
            }

            return(result);
        }
Ejemplo n.º 2
0
        internal static AdlStatus ADLMainControlCreate(out IntPtr context)
        {
            context = IntPtr.Zero;
            string path1 = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "atiadlxx.dll");
            string path2 = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "atiadlxy.dll");
            string path3 = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.SystemX86), "atiadlxx.dll");
            string path4 = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.SystemX86), "atiadlxy.dll");

            if (!File.Exists(path1) && !File.Exists(path2) && !File.Exists(path3) && !File.Exists(path4))
            {
                return(AdlStatus.ADL_ERR);
            }
            AdlStatus r       = AdlStatus.ADL_ERR;
            string    dllName = "atiadlxx.dll";

            try {
                CreateDelegates(dllName);
                if (ADL_Main_Control_Create != null)
                {
                    r = ADL_Main_Control_Create(Marshal.AllocHGlobal, 1);
                }
                else
                {
                    return(AdlStatus.ADL_ERR);
                }
            }
            catch (Exception e) {
                Logger.ErrorDebugLine(e);
                try {
                    dllName = "atiadlxy.dll";
                    CreateDelegates(dllName);
                    if (ADL_Main_Control_Create != null)
                    {
                        r = ADL_Main_Control_Create(Marshal.AllocHGlobal, 1);
                    }
                    else
                    {
                        return(AdlStatus.ADL_ERR);
                    }
                }
                catch (Exception ex) {
                    Logger.ErrorDebugLine(ex);
                    r = AdlStatus.ADL_ERR;
                }
            }
            if (r < AdlStatus.ADL_OK)
            {
                NTMinerConsole.DevError(() => $"{nameof(ADL_Main_Control_Create)} {r.ToString()} {dllName}");
            }
            ADL2MainControlCreate(out context);
            return(r);
        }