→ 개발/C#

[C#] PC에서 사용할 수 있는 COM포트 목록 가져오기

벅스쭌 2014. 12. 30. 13:46
반응형

 

 운영체제

 Windows7 64-bit

 최초 작성일

 2014/12/30

 프로그램 및 버전

 VisualStudio2010

 마지막 수정 작성일

 -

 

[주의사항]

 -

 

1. 작업개요

 PC에서 사용할 수 있는 COM포트 목록을 List<string>으로 가져온다.

 

2. 작업내용

1) 다음 함수 작성

 소스 및 이미지

 

        public static List<string> GetConnectComDevice()
        {
            List<string> lstPorts = new List<string>();
            RegistryKey rkRoot = Registry.LocalMachine.OpenSubKey("HARDWARE");
            RegistryKey rkSubKey = rkRoot.OpenSubKey("DEVICEMAP\\SERIALCOMM");
 
            if (rkSubKey == null || rkSubKey.ValueCount == 0)
            {
                lstPorts.Add("none");
            }
            else
            {
                string[] tmpCom = rkSubKey.GetValueNames();
                for (int i = 0; i < rkSubKey.ValueCount; i++)
                {
                    lstPorts.Insert(0, (rkSubKey.GetValue(tmpCom[i]).ToString()));
                }
            }
            return lstPorts;
        }

 설명

 위 함수를 생성하여 호출하면 사용할 수 있는 COM PORT 리스트를 확인할 수 있다.

 

3. 작업결과

 -

 

[참고 사이트]

 www.happytomorrow.net

 위 사이트를 참고 하였습니다.

 

 

반응형