public List<Device> GetDevices() { MinerConfiguration minerConfiguration = new MinerConfiguration() { ExecutablePath = MinerPath.GetPathToInstalledMiner(), DisableGpu = xgminerConfiguration.DisableGpu, DisableUsbProbe = xgminerConfiguration.DisableUsbProbe, ScanArguments = xgminerConfiguration.ScanArguments }; Miner miner = new Miner(minerConfiguration); List<Device> detectedDevices = miner.ListDevices(true); if (xgminerConfiguration.StratumProxy) { detectedDevices.Add(new Device() { Kind = DeviceKind.PXY, Driver = "proxy", Name = "Stratum Proxy" }); } SortDevices(detectedDevices); return detectedDevices; }
static void Main(string[] args) { //examples of using MultiMiner.Xgminer.dll and MultiMiner.Xgminer.Api.dll //download and install the latest version of bfgminer const string executablePath = @"D:\bfgminer\"; const string executableName = "bfgminer.exe"; Console.WriteLine("Downloading and installing {0} from {1} to the directory {2}", executableName, Xgminer.Installer.GetMinerDownloadRoot(), executablePath); //download and install bfgminer from the official website Xgminer.Installer.InstallMiner(executablePath); try { //create an instance of Miner with the downloaded executable MinerConfiguration minerConfiguration = new MinerConfiguration() { ExecutablePath = Path.Combine(executablePath, executableName) }; Miner miner = new Miner(minerConfiguration); //use it to iterate through devices List<Device> deviceList = miner.ListDevices(); Console.WriteLine("Using {0} to list available mining devices", executableName); //output devices foreach (Device device in deviceList) Console.WriteLine("Device detected: {0}\t{1}\t{2}", device.Kind, device.Driver, device.Name); //start mining if there are devices if (deviceList.Count > 0) { Console.WriteLine("{0} device(s) detected, mining Bitcoin on Bitminter using all devices", deviceList.Count); //setup a pool MiningPool pool = new MiningPool() { Host = "mint.bitminter.com", Port = 3333, Username = "******", Password = "******" }; minerConfiguration.Pools.Add(pool); //specify algorithm minerConfiguration.Algorithm = CoinAlgorithm.SHA256; //disable GPU mining minerConfiguration.DisableGpu = true; //specify device indexes to use for (int i = 0; i < deviceList.Count; i++) minerConfiguration.DeviceDescriptors.Add(deviceList[i]); //enable RPC API minerConfiguration.ApiListen = true; minerConfiguration.ApiPort = 4028; Console.WriteLine("Launching {0}", executableName); //start mining miner = new Miner(minerConfiguration); System.Diagnostics.Process minerProcess = miner.Launch(); try { //get an API context Xgminer.Api.ApiContext apiContext = new Xgminer.Api.ApiContext(minerConfiguration.ApiPort); try { //mine for one minute, monitoring hashrate via the API for (int i = 0; i < 6; i++) { Thread.Sleep(1000 * 10); //sleep 10s //query the miner process via its RPC API for device information List<Xgminer.Api.Responses.DeviceInformationResponse> deviceInformation = apiContext.GetDeviceInformation(); //output device information foreach (Xgminer.Api.Responses.DeviceInformationResponse item in deviceInformation) Console.WriteLine("Hasrate for device {0}: {1} current, {2} average", item.Index, item.CurrentHashrate, item.AverageHashrate); } } finally { Console.WriteLine("Quitting mining via the RPC API"); //stop mining, try the API first apiContext.QuitMining(); } } finally { Console.WriteLine("Killing any remaining process"); //then kill the process try { minerProcess.Kill(); minerProcess.WaitForExit(); minerProcess.Close(); } catch (InvalidOperationException ex) { //already closed } } } else { Console.WriteLine("No devices capable of mining detected"); } } finally { Console.WriteLine("Cleaning up, deleting directory {0}", executablePath); Directory.Delete(executablePath, true); } Console.WriteLine("Press any key to exit"); Console.ReadKey(); }
private List<Device> GetDevices() { MinerConfiguration minerConfiguration = new MinerConfiguration(); minerConfiguration.MinerBackend = engineConfiguration.XgminerConfiguration.MinerBackend; minerConfiguration.ExecutablePath = MinerPath.GetPathToInstalledMiner(minerConfiguration.MinerBackend); minerConfiguration.ErupterDriver = engineConfiguration.XgminerConfiguration.ErupterDriver; minerConfiguration.DisableGpu = engineConfiguration.XgminerConfiguration.DisableGpu; Miner miner = new Miner(minerConfiguration); List<Device> detectedDevices = miner.ListDevices(); if ((engineConfiguration.XgminerConfiguration.MinerBackend == MinerBackend.Bfgminer) && engineConfiguration.XgminerConfiguration.StratumProxy) { Device proxyDevice = new Device(); proxyDevice.Kind = DeviceKind.PXY; proxyDevice.Driver = "proxy"; proxyDevice.Name = "Stratum Proxy"; proxyDevice.Identifier = "PXY"; proxyDevice.DeviceIndex = detectedDevices.Count; detectedDevices.Add(proxyDevice); } //sort GPUs first - the output of -d? changed with bfgminer 3.3.0 detectedDevices.Sort((d1, d2) => { int result = 0; result = d1.Kind.CompareTo(d2.Kind); if (result == 0) result = d1.DeviceIndex.CompareTo(d2.DeviceIndex); return result; }); return detectedDevices; }