Last active
June 25, 2020 10:16
-
-
Save OberdanBrito/278c202b21d92d850d29ab384978ccbc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
foreach (ManagementObject item in searcher.Get()) | |
{ | |
string Description = item["Description"]?.ToString(); | |
string Name = item["Name"]?.ToString(); | |
string SystemName = item["SystemName"]?.ToString(); | |
if (Description != null && Name.Contains("(COM")) | |
{ | |
if (Description.Contains("CH340") || Description.Contains("Arduino")) | |
{ | |
// Hardware encontrado. Armazenando as inforações | |
Console.WriteLine($"Encontrado o leitor RFID em {Name}"); | |
HardwareInfo LeitorRFIDInfo = new HardwareInfo | |
{ | |
PortName = Name.Substring(Name.IndexOf("(COM")).Replace("(", "").Replace(")", ""), | |
Description = Description, | |
SystemName = SystemName | |
}; | |
Console.WriteLine(LeitorRFIDInfo.ToString()); | |
_serialPort.PortName = LeitorRFIDInfo.PortName; | |
_serialPort.DataReceived += SerialPort_DataReceived; | |
_serialPort.ErrorReceived += SerialPort_ErrorReceived; | |
// Inicia processo de conexão serial | |
_serialPort.Open(); | |
Console.WriteLine($"Situação: {_serialPort.IsOpen}"); | |
return; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment