How to Find PNPDeviceID for Disk any Drive - c#

I use this code for get all drive in pc:
using System;
using System.IO;
class Info {
public static void Main() {
DriveInfo[] drives = DriveInfo.GetDrives();
foreach (DriveInfo drive in drives) {
Console.WriteLine(drive.Name);
}
}
}
Now, using the name of each drive, I want to find its PNPDeviceID.

Related

Controll Motor Driver HAT Waveshare with C#

I am very new in this. So if anyone can help will be great. I am trying to control Motor Driver HAT Waveshare with C# via i2c from my Raspberry pi 4b. I Install Iot.Device.MotorHat NuGet package and try this example but the result is Unexpected value of duty cycle (9766, 10280).
This is the i2c addres
This is my class
using Iot.Device.MotorHat;
using System.Collections.Generic;
using System.Device.I2c;
namespace projectV2
{
public class DCMotorController : BaseClass
{
public void StartMotor()
{
using (var motorHat = new MotorHat(200, 0x40))
{
var motor = motorHat.CreateDCMotor(1);
motor.Speed = 1;
}
}
public void StopMotor()
{
using (var motorHat = new MotorHat(200, 0x40))
{
var motor = motorHat.CreateDCMotor(1);
motor.Speed = 0;
}
}
}
}

Having trouble getting CPU temps using Open Hardware Monitor C#

As the title describes I am having trouble getting CPU temps using the openhardwaremonitor.dll reference. I think I am running the program as an admin, I select run as admin when starting visual studio because I do not have the option to add an application.manifest file. This is the code I am using;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenHardwareMonitor.Hardware;
namespace Get_CPU_Temp5
{
class Program
{
public class UpdateVisitor : IVisitor
{
public void VisitComputer(IComputer computer)
{
computer.Traverse(this);
}
public void VisitHardware(IHardware hardware)
{
hardware.Update();
foreach (IHardware subHardware in hardware.SubHardware) subHardware.Accept(this);
}
public void VisitSensor(ISensor sensor) { }
public void VisitParameter(IParameter parameter) { }
}
static void GetSystemInfo()
{
UpdateVisitor updateVisitor = new UpdateVisitor();
Computer computer = new Computer();
computer.Open();
computer.CPUEnabled = true;
computer.Accept(updateVisitor);
for (int i = 0; i < computer.Hardware.Length; i++)
{
if (computer.Hardware[i].HardwareType == HardwareType.CPU)
{
for (int j = 0; j < computer.Hardware[i].Sensors.Length; j++)
{
if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Temperature)
Console.WriteLine(computer.Hardware[i].Sensors[j].Name + ":" + computer.Hardware[i].Sensors[j].Value.ToString() + "\r");
}
}
}
computer.Close();
}
static void Main(string[] args)
{
while (true)
{
GetSystemInfo();
}
}
}
}
Error;
"System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Management, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.'"
This error is at computer.Open();
I am using visual studio 2019.
Any help will be greatly appreciated!
I just ran into this issue with trying to use openhardwaremonitor.dll with .Net core. The fix I found was to load system.management from Nuget. Apparently the system.management assemblies are not included in .net core like they are with .net Framework.

How do i load a folder in to a list box?

im trying to load a folder with .mp3 files into a listbox and be able to play them, this is the code i have tried and it loads the folder but doesent allow me to play the files
private void PopulateListBox(ListBox lsb, string Folder, string FileType)
{
DirectoryInfo dinfo = new DirectoryInfo(Folder);
FileInfo[] Files = dinfo.GetFiles(FileType);
foreach(FileInfo file in Files)
{
lsb.Items.Add(file.Name);
}
}
//Try this.
using System;
using WMPLib;
using System.IO;
namespace _myNamespace
{
public partial class Form1:Form
{
//to use 'WindowsMediaPlayer' you need to import WMPLib
//add a reference "Windows Media Player" from the COM section of vstudio reference manager.
WindowsMediaPlayer player;
//constructor
public Form1
{
InitializeComponent();
PopulateListBox("folder");
player = new WindowsMediaPlayer();
}
private void PopulateListBox(string folder)
{
string[] files = Directory.GetFiles(folder);
foreach(string file in files)
listbox1.Items.Add(file);
}
private void btnPlay_Click(object sender, EventArgs e)
{
string file = listbox1.SelectedItem as string;
if(!string.IsNullOrWhiteSpace(file))
{
player.URL = file;
player.controls.play();
}
}
}
}
private void PopulateListBox(ListBox lsb, string Folder, string FileType)
{
string[] files = Directory.GetFiles(Folder);
foreach(string file in Files)
{
lsb.Items.Add(file);
}
}

C# speech recogntion engine recognizes everything wrong

I have been trying to make a personal assistant in my free time, and so far i have made him speak, but now i am trying to speak to him. Whenever i do however, he fails massively. When i say "Hello my name is Alexander" he recognizes "in the name is unresolved bush" or something else that is just not correct. am i doing something wrong or is the built in C# recognition engine just broken?
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Speech.Recognition;
using System.Speech.Synthesis;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TTS_Test
{
class Jarvis
{
private static SpeechSynthesizer synthezier;
private static String name;
public Jarvis()
{
synthezier = new SpeechSynthesizer();
synthezier.SelectVoiceByHints(VoiceGender.Male, VoiceAge.Senior);
synthezier.Volume = 100;
synthezier.Rate = 0;
}
private bool isFirstTime()
{
if (File.Exists("config"))
{
return false;
}else{
return true;
}
}
private void firstTimeSetup()
{
say("Hello, My name is Jarvis. It seems that this is your first time here. Please take some time to configure the application.");
Config config = new Config();
config.ShowDialog();
say("Thank you! I should be up and running now.");
}
public void initiate()
{
if (isFirstTime())
{
firstTimeSetup();
}
setupUserData();
say("Hello " + name+". How may i help you today?");
recognize();
}
public void setupUserData()
{
StreamReader reader = new StreamReader("config");
name = reader.ReadLine();
reader.Close();
}
public void say(string output)
{
synthezier.Speak(output);
}
public void recognize()
{
SpeechRecognitionEngine sr = new SpeechRecognitionEngine(new System.Globalization.CultureInfo("en-GB"));
sr.LoadGrammar(new DictationGrammar());
sr.InitialSilenceTimeout = TimeSpan.FromSeconds(5);
sr.SetInputToDefaultAudioDevice();
RecognitionResult result = sr.Recognize();
MessageBox.Show(result.Text);
}
}
}
You should train your computer to better understand you by going to the Control Panel\All Control Panel Items\Speech Recognition

Can't figure out why I dont have access to a public function in a separate class

I am trying to call a public function inside a public class in my web application but for some reason the function is not accessible even though I can get to the class fine and the function is marked as public. When I call FileUploader, the only options I am given are equals and referanceequals. What stupid thing am I over looking? Please not that the class is in a secondary project called Classes in my app. I do not have problems accessing a difference class in the project that FileUploader is in.
using System;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Auth;
using Microsoft.WindowsAzure.Storage.Blob;
using Microsoft.WindowsAzure;
using System.IO;
using System.Configuration;
using FFInfo.Classes;
namespace FFInfo
{
public partial class FUTest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (fuFile.HasFile)
{
}
}
}
}
FileUploaders.cs
using FFInfo.DAL;
using FFInfo.DAL.Tables;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using System;
using System.Web;
namespace FFInfo.Classes
{
public class FileUploader
{
public Int64 UploadSiteImage(string ConnectionString, string ContainerName, string FilePath, HttpPostedFile UploadedFile)
{
CloudStorageAccount SiteImages = CloudStorageAccount.Parse(ConnectionString);
CloudBlobClient SiteImagesBlob = SiteImages.CreateCloudBlobClient();
CloudBlobContainer SiteImageContainer = SiteImagesBlob.GetContainerReference(ContainerName);
SiteImageContainer.CreateIfNotExists();
CloudBlockBlob Image = SiteImageContainer.GetBlockBlobReference(FilePath + UploadedFile.FileName);
using (UploadedFile.InputStream)
{
Image.UploadFromStream(UploadedFile.InputStream);
}
using (var db = new Compleate())
{
File NewFile = new File()
{
ContainerName = ContainerName,
FilePath = FilePath,
FileName = UploadedFile.FileName,
ContentType = UploadedFile.ContentType
};
db.Files.Add(NewFile);
db.SaveChanges();
return NewFile.FileID;
}
}
}
}
Did you perhaps mean for the UploadSiteImage method to be static?
Try (new FileUploader()). <-- will get intelisense here.
But, yeah, you probably want the method to be public static

Categories

Resources