private void getPortList()
{
_SerialPorts.Clear();
a_SerialPorts = SerialPort.GetPortNames();
SerialPort testPort;
foreach (string port in a_SerialPorts) {
try {
testPort = new SerialPort(port);
testPort.Open();
_SerialPorts.Add(new SerialPortEntry
{
s_PortName = port,
s_Status = "ON"
});
testPort.Close();
}
catch (IOException e) {
_SerialPorts.Add(new SerialPortEntry
{
s_PortName = port,
s_Status = "OFF"
});
}
}
for (int i = 0; i < listView.Items.Count; i++) {
if (s_PrevSelectedSerialPort == ((SerialPortEntry)listView.Items[i]).s_PortName) {
listView.SelectedIndex = i;
break;
}
}
}